X Tutup
Skip to content

Commit 711dbf4

Browse files
committed
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).
1 parent 91f71d2 commit 711dbf4

File tree

2 files changed

+6
-19
lines changed

2 files changed

+6
-19
lines changed

modules/angular2/src/core/compiler/template_parser.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,7 @@ class TemplateParseVisitor implements HtmlAstVisitor {
295295
} else if (isPresent(
296296
bindParts[2])) { // match: var-name / var-name="iden" / #name / #name="iden"
297297
var identifier = bindParts[5];
298-
this._parseVariable(identifier, attrValue, attr.sourceInfo, targetMatchableAttrs,
299-
targetVars);
298+
this._parseVariable(identifier, attrValue, attr.sourceInfo, targetVars);
300299

301300
} else if (isPresent(bindParts[3])) { // match: on-event
302301
this._parseEvent(bindParts[5], attrValue, attr.sourceInfo, targetMatchableAttrs,
@@ -338,9 +337,8 @@ class TemplateParseVisitor implements HtmlAstVisitor {
338337
}
339338

340339
private _parseVariable(identifier: string, value: string, sourceInfo: any,
341-
targetMatchableAttrs: string[][], targetVars: VariableAst[]) {
340+
targetVars: VariableAst[]) {
342341
targetVars.push(new VariableAst(dashCaseToCamelCase(identifier), value, sourceInfo));
343-
targetMatchableAttrs.push([identifier, value]);
344342
}
345343

346344
private _parseProperty(name: string, expression: string, sourceInfo: any,

modules/angular2/test/core/compiler/template_parser_spec.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -379,19 +379,6 @@ export function main() {
379379
]);
380380
});
381381

382-
it('should locate directives in variable bindings', () => {
383-
var dirA = CompileDirectiveMetadata.create(
384-
{selector: '[a=b]', exportAs: 'b', type: new CompileTypeMetadata({name: 'DirA'})});
385-
var dirB = CompileDirectiveMetadata.create(
386-
{selector: '[b]', type: new CompileTypeMetadata({name: 'DirB'})});
387-
expect(humanizeTemplateAsts(parse('<div #a="b">', [dirA, dirB])))
388-
.toEqual([
389-
[ElementAst, 'div', 'TestComp > div:nth-child(0)'],
390-
[DirectiveAst, dirA, 'TestComp > div:nth-child(0)'],
391-
[VariableAst, 'a', 'b', 'TestComp > div:nth-child(0)[#a=b]']
392-
]);
393-
});
394-
395382
it('should parse directive host properties', () => {
396383
var dirA = CompileDirectiveMetadata.create({
397384
selector: 'div',
@@ -537,9 +524,10 @@ export function main() {
537524
it('should assign variables to directives via exportAs', () => {
538525
var dirA = CompileDirectiveMetadata.create(
539526
{selector: '[a]', type: new CompileTypeMetadata({name: 'DirA'}), exportAs: 'dirA'});
540-
expect(humanizeTemplateAsts(parse('<div #a="dirA"></div>', [dirA])))
527+
expect(humanizeTemplateAsts(parse('<div a #a="dirA"></div>', [dirA])))
541528
.toEqual([
542529
[ElementAst, 'div', 'TestComp > div:nth-child(0)'],
530+
[AttrAst, 'a', '', 'TestComp > div:nth-child(0)[a=]'],
543531
[DirectiveAst, dirA, 'TestComp > div:nth-child(0)'],
544532
[VariableAst, 'a', 'dirA', 'TestComp > div:nth-child(0)[#a=dirA]']
545533
]);
@@ -566,9 +554,10 @@ There is no directive with "exportAs" set to "dirA" at TestComp > div:nth-child(
566554
type: new CompileTypeMetadata({name: 'DirA'}),
567555
exportAs: 'dirA', template: new CompileTemplateMetadata({ngContentSelectors: []})
568556
});
569-
expect(humanizeTemplateAsts(parse('<div #a></div>', [dirA])))
557+
expect(humanizeTemplateAsts(parse('<div a #a></div>', [dirA])))
570558
.toEqual([
571559
[ElementAst, 'div', 'TestComp > div:nth-child(0)'],
560+
[AttrAst, 'a', '', 'TestComp > div:nth-child(0)[a=]'],
572561
[VariableAst, 'a', '', 'TestComp > div:nth-child(0)[#a=]'],
573562
[DirectiveAst, dirA, 'TestComp > div:nth-child(0)'],
574563
[VariableAst, 'a', '', 'TestComp > div:nth-child(0)[#a=]']

0 commit comments

Comments
 (0)
X Tutup