chore(animations): make sure host-prop animation deprecation is correctly emitted

Closes #10581
This commit is contained in:
Matias Niemelä 2016-08-08 17:08:53 -07:00 committed by Alex Rickabaugh
parent b2b47177cd
commit 0b08dd8674
3 changed files with 26 additions and 8 deletions

View File

@ -441,8 +441,8 @@ export class CompileDirectiveMetadata implements CompileMetadataWithIdentifier {
hostProperties[matches[1]] = value; hostProperties[matches[1]] = value;
} else if (isPresent(matches[2])) { } else if (isPresent(matches[2])) {
hostListeners[matches[2]] = value; hostListeners[matches[2]] = value;
} else if (isPresent(matches[3])) { } else if (isPresent(matches[3])) { // DEPRECATED: remove this if statement post RC5
hostProperties[matches[3]] = value; hostProperties['@' + matches[3]] = value;
} }
}); });
} }

View File

@ -540,7 +540,7 @@ class TemplateParseVisitor implements html.Visitor {
} else if (isPresent(bindParts[7])) { // match: animate-name } else if (isPresent(bindParts[7])) { // match: animate-name
if (attrName[0] == '@' && isPresent(attrValue) && attrValue.length > 0) { if (attrName[0] == '@' && isPresent(attrValue) && attrValue.length > 0) {
this._reportError( this._reportError(
`Assigning animation triggers via @prop="exp" attributes with an expression is deprecated. Use [@prop]="exp" instead!`, `Assigning animation triggers via @prop="exp" attributes with an expression is deprecated. Use property bindings (e.g. [@prop]="exp") instead!`,
attr.sourceSpan, ParseErrorLevel.WARNING); attr.sourceSpan, ParseErrorLevel.WARNING);
} }
this._parseAnimation( this._parseAnimation(
@ -809,9 +809,13 @@ class TemplateParseVisitor implements html.Visitor {
boundPropertyName = partValue.substr(1); boundPropertyName = partValue.substr(1);
bindingType = PropertyBindingType.Animation; bindingType = PropertyBindingType.Animation;
securityContext = SecurityContext.NONE; securityContext = SecurityContext.NONE;
this._reportError( // DEPRECATED: remove this if statement post RC5
`Assigning animation triggers within host data as attributes such as "@prop": "exp" is deprecated. Use "[@prop]": "exp" instead!`, if (boundPropertyName[0] == '@') {
sourceSpan, ParseErrorLevel.WARNING); this._reportError(
`Assigning animation triggers within host data as attributes such as "@prop": "exp" is deprecated. Use host bindings (e.g. "[@prop]": "exp") instead!`,
sourceSpan, ParseErrorLevel.WARNING);
boundPropertyName = boundPropertyName.substr(1);
}
} else { } else {
boundPropertyName = this._schemaRegistry.getMappedPropName(partValue); boundPropertyName = this._schemaRegistry.getMappedPropName(partValue);
securityContext = this._schemaRegistry.securityContext(elementName, boundPropertyName); securityContext = this._schemaRegistry.securityContext(elementName, boundPropertyName);

View File

@ -291,6 +291,7 @@ Can't bind to 'invalidProp' since it isn't a known property of 'my-component'.
]); ]);
}); });
// DEPRECATED: remove this spec post RC5
it('should parse bound properties via @ and not report them as attributes and also report a deprecation warning', it('should parse bound properties via @ and not report them as attributes and also report a deprecation warning',
() => { () => {
expect(humanizeTplAst(parse('<div @something="value2">', []))).toEqual([ expect(humanizeTplAst(parse('<div @something="value2">', []))).toEqual([
@ -302,10 +303,11 @@ Can't bind to 'invalidProp' since it isn't a known property of 'my-component'.
expect(console.warnings).toEqual([[ expect(console.warnings).toEqual([[
'Template parse warnings:', 'Template parse warnings:',
`Assigning animation triggers via @prop="exp" attributes with an expression is deprecated. Use [@prop]="exp" instead! ("<div [ERROR ->]@something="value2">"): TestComp@0:5` `Assigning animation triggers via @prop="exp" attributes with an expression is deprecated. Use property bindings (e.g. [@prop]="exp") instead! ("<div [ERROR ->]@something="value2">"): TestComp@0:5`
].join('\n')]); ].join('\n')]);
}); });
// DEPRECATED: remove this spec post RC5
it('should issue a warning when host attributes contain a non property-bound animation trigger', it('should issue a warning when host attributes contain a non property-bound animation trigger',
() => { () => {
var dirA = CompileDirectiveMetadata.create({ var dirA = CompileDirectiveMetadata.create({
@ -318,10 +320,22 @@ Can't bind to 'invalidProp' since it isn't a known property of 'my-component'.
expect(console.warnings).toEqual([[ expect(console.warnings).toEqual([[
'Template parse warnings:', 'Template parse warnings:',
`Assigning animation triggers within host data as attributes such as "@prop": "exp" is deprecated. Use "[@prop]": "exp" instead! ("[ERROR ->]<div></div>"): TestComp@0:0, Directive DirA` `Assigning animation triggers within host data as attributes such as "@prop": "exp" is deprecated. Use host bindings (e.g. "[@prop]": "exp") instead! ("[ERROR ->]<div></div>"): TestComp@0:0, Directive DirA`
].join('\n')]); ].join('\n')]);
}); });
it('should not issue a warning when host attributes contain a valid property-bound animation trigger',
() => {
var dirA = CompileDirectiveMetadata.create({
selector: 'div',
type: new CompileTypeMetadata({moduleUrl: someModuleUrl, name: 'DirA'}),
host: {'[@prop]': 'expr'}
});
humanizeTplAst(parse('<div></div>', [dirA]));
expect(console.warnings.length).toEqual(0);
});
it('should not issue a warning when an animation property is bound without an expression', it('should not issue a warning when an animation property is bound without an expression',
() => { () => {
humanizeTplAst(parse('<div @something>', [])); humanizeTplAst(parse('<div @something>', []));