Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test(compiler): check that the parser supports prematurely terminated…
… interpolations

Such interpolations turned up during internal testing at Google, so this
commit adds a test to prevent regressions.
  • Loading branch information
petebacondarwin committed Jul 31, 2021
commit 0384fa4e533d9f7d0c1357267e4862f795d35b0f
27 changes: 27 additions & 0 deletions packages/compiler/test/ml_parser/html_parser_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,23 @@ import {humanizeDom, humanizeDomSourceSpans, humanizeLineColumn, humanizeNodes}
]);
expect(parsed.errors).toEqual([]);
});

it('should treat prematurely terminated interpolation as text', () => {
const {errors, rootNodes} =
parser.parse('<div><span>x {{ expr }<!---->} y</span><div></div></div>', 'TestComp');
expect(humanizeNodes(rootNodes, true)).toEqual([
[
html.Element, 'div', 0, '<div><span>x {{ expr }<!---->} y</span><div></div></div>',
'<div>', '</div>'
],
[html.Element, 'span', 1, '<span>x {{ expr }<!---->} y</span>', '<span>', '</span>'],
[html.Text, 'x {{ expr }', 2, ['x '], ['{{', ' expr }'], [''], 'x {{ expr }'],
[html.Comment, '', 2, '<!--'],
[html.Text, '} y', 2, ['} y'], '} y'],
[html.Element, 'div', 1, '<div></div>', '<div>', '</div>'],
]);
expect(errors).toEqual([]);
});
});

describe('attributes', () => {
Expand Down Expand Up @@ -318,6 +335,16 @@ import {humanizeDom, humanizeDomSourceSpans, humanizeLineColumn, humanizeNodes}
[html.Attribute, ':xlink:href', 'Port', ['Port']],
]);
});

it('should support a prematurely terminated interpolation in attribute', () => {
const {errors, rootNodes} = parser.parse('<div p="{{ abc"><span></span>', 'TestComp');
expect(humanizeNodes(rootNodes, true)).toEqual([
[html.Element, 'div', 0, '<div p="{{ abc">', '<div p="{{ abc">', null],
[html.Attribute, 'p', '{{ abc', [''], ['{{', ' abc'], [''], 'p="{{ abc"'],
[html.Element, 'span', 1, '<span></span>', '<span>', '</span>'],
]);
expect(humanizeErrors(errors)).toEqual([]);
});
});

describe('comments', () => {
Expand Down