From 53628e19ac902a73b47cfe617ca3ed3bd3d7cc9e Mon Sep 17 00:00:00 2001 From: Wesley Cho Date: Sun, 20 Dec 2015 09:56:00 -0500 Subject: [PATCH] fix(compiler): add ability to parse : in * directives - Add ability to parse bindings properly when `:` is present when using a directive with the `*` prefix Closes #6038 --- modules/@angular/compiler/src/template_parser.ts | 4 +++- .../@angular/compiler/test/template_parser_spec.ts | 14 +++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/modules/@angular/compiler/src/template_parser.ts b/modules/@angular/compiler/src/template_parser.ts index ca2817e8d5..92663ae8b6 100644 --- a/modules/@angular/compiler/src/template_parser.ts +++ b/modules/@angular/compiler/src/template_parser.ts @@ -414,7 +414,9 @@ class TemplateParseVisitor implements HtmlAstVisitor { templateBindingsSource = attr.value; } else if (attr.name.startsWith(TEMPLATE_ATTR_PREFIX)) { var key = attr.name.substring(TEMPLATE_ATTR_PREFIX.length); // remove the star - templateBindingsSource = (attr.value.length == 0) ? key : key + ' ' + attr.value; + templateBindingsSource = (attr.value.length == 0) ? + key : + key + ' ' + StringWrapper.replaceAll(attr.value, /:/g, ' '); } if (isPresent(templateBindingsSource)) { var bindings = this._parseTemplateBindings(templateBindingsSource, attr.sourceSpan); diff --git a/modules/@angular/compiler/test/template_parser_spec.ts b/modules/@angular/compiler/test/template_parser_spec.ts index b0d5144b61..ee993a3e62 100644 --- a/modules/@angular/compiler/test/template_parser_spec.ts +++ b/modules/@angular/compiler/test/template_parser_spec.ts @@ -460,7 +460,7 @@ export function main() { it('should support optional directive properties', () => { var dirA = CompileDirectiveMetadata.create({ selector: 'div', - type: new CompileTypeMetadata({moduleUrl: someModuleUrl, name: 'DirA'}), + type: new CompileTypeMetadata({moduleUrl: someModuleUrl, name: 'Dir'}), inputs: ['a'] }); expect(humanizeTplAst(parse('
', [dirA]))) @@ -1009,6 +1009,18 @@ There is no directive with "exportAs" set to "dirA" ("
]#a="dirA">< [ElementAst, 'div'] ]); }); + + it('should work with *... and :', () => { + var dirA = CompileDirectiveMetadata.create( + {selector: '[a]', type: new CompileTypeMetadata({name: 'DirA'}), inputs: ['a', 'b']}); + expect(humanizeTplAst(parse('
', [dirA]))) + .toEqual([ + [EmbeddedTemplateAst], + [DirectiveAst, dirA], + [BoundDirectivePropertyAst, 'a', 'b'], + [ElementAst, 'div'] + ]); + }); }); });