From 711dbf49753b838eb9ff729bd57b0b93f0e75ea8 Mon Sep 17 00:00:00 2001 From: Yegor Jbanov Date: Tue, 20 Oct 2015 16:25:01 -0700 Subject: [PATCH] fix(compiler): do not match directives to variable names BREAKING CHANGES: - you can no longer use a #foo or a var-foo to apply directive [foo], although it didn't work properly anyway. This commit is fixing breakage caused by the switch to pre-compiler (exact SHA unknown). --- .../src/core/compiler/template_parser.ts | 6 ++---- .../core/compiler/template_parser_spec.ts | 19 ++++--------------- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/modules/angular2/src/core/compiler/template_parser.ts b/modules/angular2/src/core/compiler/template_parser.ts index 4817ac6202..7847b457d3 100644 --- a/modules/angular2/src/core/compiler/template_parser.ts +++ b/modules/angular2/src/core/compiler/template_parser.ts @@ -295,8 +295,7 @@ class TemplateParseVisitor implements HtmlAstVisitor { } else if (isPresent( bindParts[2])) { // match: var-name / var-name="iden" / #name / #name="iden" var identifier = bindParts[5]; - this._parseVariable(identifier, attrValue, attr.sourceInfo, targetMatchableAttrs, - targetVars); + this._parseVariable(identifier, attrValue, attr.sourceInfo, targetVars); } else if (isPresent(bindParts[3])) { // match: on-event this._parseEvent(bindParts[5], attrValue, attr.sourceInfo, targetMatchableAttrs, @@ -338,9 +337,8 @@ class TemplateParseVisitor implements HtmlAstVisitor { } private _parseVariable(identifier: string, value: string, sourceInfo: any, - targetMatchableAttrs: string[][], targetVars: VariableAst[]) { + targetVars: VariableAst[]) { targetVars.push(new VariableAst(dashCaseToCamelCase(identifier), value, sourceInfo)); - targetMatchableAttrs.push([identifier, value]); } private _parseProperty(name: string, expression: string, sourceInfo: any, diff --git a/modules/angular2/test/core/compiler/template_parser_spec.ts b/modules/angular2/test/core/compiler/template_parser_spec.ts index bae38463be..50ed6dfea4 100644 --- a/modules/angular2/test/core/compiler/template_parser_spec.ts +++ b/modules/angular2/test/core/compiler/template_parser_spec.ts @@ -379,19 +379,6 @@ export function main() { ]); }); - it('should locate directives in variable bindings', () => { - var dirA = CompileDirectiveMetadata.create( - {selector: '[a=b]', exportAs: 'b', type: new CompileTypeMetadata({name: 'DirA'})}); - var dirB = CompileDirectiveMetadata.create( - {selector: '[b]', type: new CompileTypeMetadata({name: 'DirB'})}); - expect(humanizeTemplateAsts(parse('
', [dirA, dirB]))) - .toEqual([ - [ElementAst, 'div', 'TestComp > div:nth-child(0)'], - [DirectiveAst, dirA, 'TestComp > div:nth-child(0)'], - [VariableAst, 'a', 'b', 'TestComp > div:nth-child(0)[#a=b]'] - ]); - }); - it('should parse directive host properties', () => { var dirA = CompileDirectiveMetadata.create({ selector: 'div', @@ -537,9 +524,10 @@ export function main() { it('should assign variables to directives via exportAs', () => { var dirA = CompileDirectiveMetadata.create( {selector: '[a]', type: new CompileTypeMetadata({name: 'DirA'}), exportAs: 'dirA'}); - expect(humanizeTemplateAsts(parse('
', [dirA]))) + expect(humanizeTemplateAsts(parse('
', [dirA]))) .toEqual([ [ElementAst, 'div', 'TestComp > div:nth-child(0)'], + [AttrAst, 'a', '', 'TestComp > div:nth-child(0)[a=]'], [DirectiveAst, dirA, 'TestComp > div:nth-child(0)'], [VariableAst, 'a', 'dirA', 'TestComp > div:nth-child(0)[#a=dirA]'] ]); @@ -566,9 +554,10 @@ There is no directive with "exportAs" set to "dirA" at TestComp > div:nth-child( type: new CompileTypeMetadata({name: 'DirA'}), exportAs: 'dirA', template: new CompileTemplateMetadata({ngContentSelectors: []}) }); - expect(humanizeTemplateAsts(parse('
', [dirA]))) + expect(humanizeTemplateAsts(parse('
', [dirA]))) .toEqual([ [ElementAst, 'div', 'TestComp > div:nth-child(0)'], + [AttrAst, 'a', '', 'TestComp > div:nth-child(0)[a=]'], [VariableAst, 'a', '', 'TestComp > div:nth-child(0)[#a=]'], [DirectiveAst, dirA, 'TestComp > div:nth-child(0)'], [VariableAst, 'a', '', 'TestComp > div:nth-child(0)[#a=]']