From e5e1b0da33a7fa509f9420b38ac248f7a0ab7caa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matias=20Niemel=C3=A4?= Date: Wed, 21 Mar 2018 19:58:37 -0700 Subject: [PATCH] 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 --- .../browser/src/dsl/animation_ast_builder.ts | 2 +- .../browser/test/dsl/animation_trigger_spec.ts | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/animations/browser/src/dsl/animation_ast_builder.ts b/packages/animations/browser/src/dsl/animation_ast_builder.ts index 4884072fc3..841bfd378b 100644 --- a/packages/animations/browser/src/dsl/animation_ast_builder.ts +++ b/packages/animations/browser/src/dsl/animation_ast_builder.ts @@ -96,7 +96,7 @@ export class AnimationAstBuilderVisitor implements AnimationDslVisitor { if (def.type == AnimationMetadataType.State) { const stateDef = def as AnimationStateMetadata; const name = stateDef.name; - name.split(/\s*,\s*/).forEach(n => { + name.toString().split(/\s*,\s*/).forEach(n => { stateDef.name = n; states.push(this.visitState(stateDef, context)); }); diff --git a/packages/animations/browser/test/dsl/animation_trigger_spec.ts b/packages/animations/browser/test/dsl/animation_trigger_spec.ts index c541c09292..b88f450b72 100644 --- a/packages/animations/browser/test/dsl/animation_trigger_spec.ts +++ b/packages/animations/browser/test/dsl/animation_trigger_spec.ts @@ -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', () => { it('should alias the :enter transition as void => *', () => { const result = makeTrigger('name', [transition(':enter', animate(3333))]);