Skip to content

Commit

Permalink
fix(compiler): Fix parsing attributes with dot in the name
Browse files Browse the repository at this point in the history
Previously there was a bug when compiler was trying to parse
some complicated element attributes i.e.
element <div [attr.someProp.propSuffix]="var"></div>
turns into <div someProp="varValue"></div>

We fixed such behavior and now ensure that whole attribute
name is being parsed into html i.e.
element <div [attr.someProp.propSuffix]="var"></div>
result this html <div someProp.propSuffix="varValue"></div>
  • Loading branch information
n0th1ng-else committed Nov 5, 2019
1 parent 25aaff2 commit a74b239
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/compiler/src/template_parser/binding_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ export class BindingParser {
// Check for special cases (prefix style, attr, class)
if (parts.length > 1) {
if (parts[0] == ATTRIBUTE_PREFIX) {
boundPropertyName = parts[1];
boundPropertyName = parts.slice(1).join(PROPERTY_PARTS_SEPARATOR);
if (!skipValidation) {
this._validatePropertyOrAttributeName(boundPropertyName, boundProp.sourceSpan, true);
}
Expand Down
10 changes: 10 additions & 0 deletions packages/compiler/test/template_parser/template_parser_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,16 @@ class ArrayConsole implements Console {
]);
});

it('should parse mixed case bound attributes with dot in the attribute name', () => {
expect(humanizeTplAst(parse('<div [attr.someAttr.someAttrSuffix]="v">', []))).toEqual([
[ElementAst, 'div'],
[
BoundElementPropertyAst, PropertyBindingType.Attribute, 'someAttr.someAttrSuffix',
'v', null
]
]);
});

it('should parse and dash case bound classes', () => {
expect(humanizeTplAst(parse('<div [class.some-class]="v">', []))).toEqual([
[ElementAst, 'div'],
Expand Down

0 comments on commit a74b239

Please sign in to comment.