Skip to content

Commit

Permalink
test(compiler): add a test for parsing multiline expressions in attri…
Browse files Browse the repository at this point in the history
…butes (angular#42062)

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

PR Close angular#42062
  • Loading branch information
petebacondarwin authored and atscott committed Aug 2, 2021
1 parent 28b0c45 commit fe12651
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
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 @@ -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', () => {
expect(humanizeDom(parser.parse('<div foo="&amp;"></div>', 'TestComp'))).toEqual([
[html.Element, 'div', 0],
Expand Down
21 changes: 21 additions & 0 deletions packages/compiler/test/ml_parser/lexer_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
expect(tokenizeAndHumanizeParts('<t a="">')).toEqual([
[TokenType.TAG_OPEN_START, '', 't'],
Expand Down

0 comments on commit fe12651

Please sign in to comment.