Skip to content

Commit

Permalink
fix(compiler): do not match directives to variable names
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
yjbanov committed Oct 21, 2015
1 parent 91f71d2 commit 711dbf4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 19 deletions.
6 changes: 2 additions & 4 deletions modules/angular2/src/core/compiler/template_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
19 changes: 4 additions & 15 deletions modules/angular2/test/core/compiler/template_parser_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('<div #a="b">', [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',
Expand Down Expand Up @@ -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('<div #a="dirA"></div>', [dirA])))
expect(humanizeTemplateAsts(parse('<div a #a="dirA"></div>', [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]']
]);
Expand All @@ -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('<div #a></div>', [dirA])))
expect(humanizeTemplateAsts(parse('<div a #a></div>', [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=]']
Expand Down

0 comments on commit 711dbf4

Please sign in to comment.