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
This commit is contained in:
Wesley Cho 2015-12-20 09:56:00 -05:00 committed by Misko Hevery
parent 62dd3ceb64
commit 53628e19ac
2 changed files with 16 additions and 2 deletions

View File

@ -414,7 +414,9 @@ class TemplateParseVisitor implements HtmlAstVisitor {
templateBindingsSource = attr.value; templateBindingsSource = attr.value;
} else if (attr.name.startsWith(TEMPLATE_ATTR_PREFIX)) { } else if (attr.name.startsWith(TEMPLATE_ATTR_PREFIX)) {
var key = attr.name.substring(TEMPLATE_ATTR_PREFIX.length); // remove the star 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)) { if (isPresent(templateBindingsSource)) {
var bindings = this._parseTemplateBindings(templateBindingsSource, attr.sourceSpan); var bindings = this._parseTemplateBindings(templateBindingsSource, attr.sourceSpan);

View File

@ -460,7 +460,7 @@ export function main() {
it('should support optional directive properties', () => { it('should support optional directive properties', () => {
var dirA = CompileDirectiveMetadata.create({ var dirA = CompileDirectiveMetadata.create({
selector: 'div', selector: 'div',
type: new CompileTypeMetadata({moduleUrl: someModuleUrl, name: 'DirA'}), type: new CompileTypeMetadata({moduleUrl: someModuleUrl, name: 'Dir'}),
inputs: ['a'] inputs: ['a']
}); });
expect(humanizeTplAst(parse('<div></div>', [dirA]))) expect(humanizeTplAst(parse('<div></div>', [dirA])))
@ -1009,6 +1009,18 @@ There is no directive with "exportAs" set to "dirA" ("<div [ERROR ->]#a="dirA"><
[ElementAst, 'div'] [ElementAst, 'div']
]); ]);
}); });
it('should work with *... and :', () => {
var dirA = CompileDirectiveMetadata.create(
{selector: '[a]', type: new CompileTypeMetadata({name: 'DirA'}), inputs: ['a', 'b']});
expect(humanizeTplAst(parse('<div *a="b: foo">', [dirA])))
.toEqual([
[EmbeddedTemplateAst],
[DirectiveAst, dirA],
[BoundDirectivePropertyAst, 'a', 'b'],
[ElementAst, 'div']
]);
});
}); });
}); });