test(compiler): add a test for parsing multiline expressions in attributes (#42062)

This tests a scenario that was failing in an internal project.

PR Close #42062
This commit is contained in:
Pete Bacon Darwin 2021-07-21 15:58:48 +01:00 committed by atscott
parent 28b0c45fde
commit fe12651580
2 changed files with 48 additions and 0 deletions

View File

@ -274,6 +274,33 @@ import {humanizeDom, humanizeDomSourceSpans, humanizeLineColumn, humanizeNodes}
]); ]);
}); });
it('should parse attributes containing unquoted interpolation', () => {
expect(humanizeDom(parser.parse('<div foo={{message}}></div>', 'TestComp'))).toEqual([
[html.Element, 'div', 0],
[html.Attribute, 'foo', '{{message}}', [''], ['{{', 'message', '}}'], ['']]
]);
});
it('should parse bound inputs with expressions containing newlines', () => {
expect(humanizeDom(parser.parse(
`<app-component
[attr]="[
{text: 'some text',url:'//www.google.com'},
{text:'other text',url:'//www.google.com'}]"></app-component>`,
'TestComp')))
.toEqual([
[html.Element, 'app-component', 0],
[
html.Attribute, '[attr]', `[
{text: 'some text',url:'//www.google.com'},
{text:'other text',url:'//www.google.com'}]`,
[`[
{text: 'some text',url:'//www.google.com'},
{text:'other text',url:'//www.google.com'}]`]
],
]);
});
it('should parse attributes containing encoded entities', () => { it('should parse attributes containing encoded entities', () => {
expect(humanizeDom(parser.parse('<div foo="&amp;"></div>', 'TestComp'))).toEqual([ expect(humanizeDom(parser.parse('<div foo="&amp;"></div>', 'TestComp'))).toEqual([
[html.Element, 'div', 0], [html.Element, 'div', 0],

View File

@ -407,6 +407,27 @@ import {ParseLocation, ParseSourceFile, ParseSourceSpan} from '../../src/parse_u
]); ]);
}); });
it('should parse bound inputs with expressions containing newlines', () => {
expect(tokenizeAndHumanizeParts(`<app-component
[attr]="[
{text: 'some text',url:'//www.google.com'},
{text:'other text',url:'//www.google.com'}]">`))
.toEqual([
[TokenType.TAG_OPEN_START, '', 'app-component'],
[TokenType.ATTR_NAME, '', '[attr]'],
[TokenType.ATTR_QUOTE, '"'],
[
TokenType.ATTR_VALUE_TEXT,
'[\n' +
' {text: \'some text\',url:\'//www.google.com\'},\n' +
' {text:\'other text\',url:\'//www.google.com\'}]'
],
[TokenType.ATTR_QUOTE, '"'],
[TokenType.TAG_OPEN_END],
[TokenType.EOF],
]);
});
it('should parse attributes with empty quoted value', () => { it('should parse attributes with empty quoted value', () => {
expect(tokenizeAndHumanizeParts('<t a="">')).toEqual([ expect(tokenizeAndHumanizeParts('<t a="">')).toEqual([
[TokenType.TAG_OPEN_START, '', 't'], [TokenType.TAG_OPEN_START, '', 't'],