Skip to content

Commit 11ebe21

Browse files
petebacondarwinatscott
authored andcommitted
test(compiler): check that the parser supports prematurely terminated interpolations (#42062)
Such interpolations turned up during internal testing at Google, so this commit adds a test to prevent regressions. PR Close #42062
1 parent 9b3d4f5 commit 11ebe21

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

‎packages/compiler/test/ml_parser/html_parser_spec.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,23 @@ import {humanizeDom, humanizeDomSourceSpans, humanizeLineColumn, humanizeNodes}
239239
]);
240240
expect(parsed.errors).toEqual([]);
241241
});
242+
243+
it('should treat prematurely terminated interpolation as text', () => {
244+
const {errors, rootNodes} =
245+
parser.parse('<div><span>x {{ expr }<!---->} y</span><div></div></div>', 'TestComp');
246+
expect(humanizeNodes(rootNodes, true)).toEqual([
247+
[
248+
html.Element, 'div', 0, '<div><span>x {{ expr }<!---->} y</span><div></div></div>',
249+
'<div>', '</div>'
250+
],
251+
[html.Element, 'span', 1, '<span>x {{ expr }<!---->} y</span>', '<span>', '</span>'],
252+
[html.Text, 'x {{ expr }', 2, ['x '], ['{{', ' expr }'], [''], 'x {{ expr }'],
253+
[html.Comment, '', 2, '<!--'],
254+
[html.Text, '} y', 2, ['} y'], '} y'],
255+
[html.Element, 'div', 1, '<div></div>', '<div>', '</div>'],
256+
]);
257+
expect(errors).toEqual([]);
258+
});
242259
});
243260

244261
describe('attributes', () => {
@@ -318,6 +335,16 @@ import {humanizeDom, humanizeDomSourceSpans, humanizeLineColumn, humanizeNodes}
318335
[html.Attribute, ':xlink:href', 'Port', ['Port']],
319336
]);
320337
});
338+
339+
it('should support a prematurely terminated interpolation in attribute', () => {
340+
const {errors, rootNodes} = parser.parse('<div p="{{ abc"><span></span>', 'TestComp');
341+
expect(humanizeNodes(rootNodes, true)).toEqual([
342+
[html.Element, 'div', 0, '<div p="{{ abc">', '<div p="{{ abc">', null],
343+
[html.Attribute, 'p', '{{ abc', [''], ['{{', ' abc'], [''], 'p="{{ abc"'],
344+
[html.Element, 'span', 1, '<span></span>', '<span>', '</span>'],
345+
]);
346+
expect(humanizeErrors(errors)).toEqual([]);
347+
});
321348
});
322349

323350
describe('comments', () => {

0 commit comments

Comments
 (0)