Skip to content

Commit 05e1adb

Browse files
petebacondarwinthePunderWoman
authored andcommitted
test(compiler): add a test for parsing multiline expressions in attributes (#43132)
This tests a scenario that was failing in an internal project. PR Close #43132
1 parent 4cbeee7 commit 05e1adb

2 files changed

Lines changed: 48 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
@@ -274,6 +274,33 @@ import {humanizeDom, humanizeDomSourceSpans, humanizeLineColumn, humanizeNodes}
274274
]);
275275
});
276276

277+
it('should parse attributes containing unquoted interpolation', () => {
278+
expect(humanizeDom(parser.parse('<div foo={{message}}></div>', 'TestComp'))).toEqual([
279+
[html.Element, 'div', 0],
280+
[html.Attribute, 'foo', '{{message}}', [''], ['{{', 'message', '}}'], ['']]
281+
]);
282+
});
283+
284+
it('should parse bound inputs with expressions containing newlines', () => {
285+
expect(humanizeDom(parser.parse(
286+
`<app-component
287+
[attr]="[
288+
{text: 'some text',url:'//www.google.com'},
289+
{text:'other text',url:'//www.google.com'}]"></app-component>`,
290+
'TestComp')))
291+
.toEqual([
292+
[html.Element, 'app-component', 0],
293+
[
294+
html.Attribute, '[attr]', `[
295+
{text: 'some text',url:'//www.google.com'},
296+
{text:'other text',url:'//www.google.com'}]`,
297+
[`[
298+
{text: 'some text',url:'//www.google.com'},
299+
{text:'other text',url:'//www.google.com'}]`]
300+
],
301+
]);
302+
});
303+
277304
it('should parse attributes containing encoded entities', () => {
278305
expect(humanizeDom(parser.parse('<div foo="&amp;"></div>', 'TestComp'))).toEqual([
279306
[html.Element, 'div', 0],

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,27 @@ import {ParseLocation, ParseSourceFile, ParseSourceSpan} from '../../src/parse_u
407407
]);
408408
});
409409

410+
it('should parse bound inputs with expressions containing newlines', () => {
411+
expect(tokenizeAndHumanizeParts(`<app-component
412+
[attr]="[
413+
{text: 'some text',url:'//www.google.com'},
414+
{text:'other text',url:'//www.google.com'}]">`))
415+
.toEqual([
416+
[TokenType.TAG_OPEN_START, '', 'app-component'],
417+
[TokenType.ATTR_NAME, '', '[attr]'],
418+
[TokenType.ATTR_QUOTE, '"'],
419+
[
420+
TokenType.ATTR_VALUE_TEXT,
421+
'[\n' +
422+
' {text: \'some text\',url:\'//www.google.com\'},\n' +
423+
' {text:\'other text\',url:\'//www.google.com\'}]'
424+
],
425+
[TokenType.ATTR_QUOTE, '"'],
426+
[TokenType.TAG_OPEN_END],
427+
[TokenType.EOF],
428+
]);
429+
});
430+
410431
it('should parse attributes with empty quoted value', () => {
411432
expect(tokenizeAndHumanizeParts('<t a="">')).toEqual([
412433
[TokenType.TAG_OPEN_START, '', 't'],

0 commit comments

Comments
 (0)