Skip to content

Commit 1e811df

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

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 }'],
253+
[html.Comment, '', 2, '<!--'],
254+
[html.Text, '} y', 2, '} y'],
255+
[html.Element, 'div', 1, '<div></div>', '<div>', '</div>'],
256+
]);
257+
expect(errors).toEqual([]);
258+
});
242259
});
243260

244261
describe('attributes', () => {
@@ -288,6 +305,16 @@ import {humanizeDom, humanizeDomSourceSpans, humanizeLineColumn, humanizeNodes}
288305
[html.Attribute, ':xlink:href', 'Port'],
289306
]);
290307
});
308+
309+
it('should support a prematurely terminated interpolation in attribute', () => {
310+
const {errors, rootNodes} = parser.parse('<div p="{{ abc"><span></span>', 'TestComp');
311+
expect(humanizeNodes(rootNodes, true)).toEqual([
312+
[html.Element, 'div', 0, '<div p="{{ abc">', '<div p="{{ abc">', null],
313+
[html.Attribute, 'p', '{{ abc', 'p="{{ abc"'],
314+
[html.Element, 'span', 1, '<span></span>', '<span>', '</span>'],
315+
]);
316+
expect(humanizeErrors(errors)).toEqual([]);
317+
});
291318
});
292319

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

0 commit comments

Comments
 (0)