fix(animations): treat numeric state name values as strings (#22923)

This patch ensures that if a numeric state name value in an animation
is detected then it will not throw an error. Normally this wouldn't
occur, but some JS optimizers may convert a quoted numeric value
(like "1" to 1) in some cases to save space. This patch makes sure
that Angular doesn't throw an error when this occurs.

PR Close #22923
This commit is contained in:
Matias Niemelä 2018-03-21 19:58:37 -07:00
parent d77bb460b0
commit e5e1b0da33
2 changed files with 12 additions and 1 deletions

View File

@ -96,7 +96,7 @@ export class AnimationAstBuilderVisitor implements AnimationDslVisitor {
if (def.type == AnimationMetadataType.State) { if (def.type == AnimationMetadataType.State) {
const stateDef = def as AnimationStateMetadata; const stateDef = def as AnimationStateMetadata;
const name = stateDef.name; const name = stateDef.name;
name.split(/\s*,\s*/).forEach(n => { name.toString().split(/\s*,\s*/).forEach(n => {
stateDef.name = n; stateDef.name = n;
states.push(this.visitState(stateDef, context)); states.push(this.visitState(stateDef, context));
}); });

View File

@ -203,6 +203,17 @@ import {makeTrigger} from '../shared';
]); ]);
}); });
it('should treat numeric values (disguised as strings) as proper state values', () => {
const result = makeTrigger('name', [
state(1 as any as string, style({opacity: 0})),
state(0 as any as string, style({opacity: 0})), transition('* => *', animate(1000))
]);
expect(() => {
const trans = buildTransition(result, element, false, true) !;
}).not.toThrow();
});
describe('aliases', () => { describe('aliases', () => {
it('should alias the :enter transition as void => *', () => { it('should alias the :enter transition as void => *', () => {
const result = makeTrigger('name', [transition(':enter', animate(3333))]); const result = makeTrigger('name', [transition(':enter', animate(3333))]);