Skip to content

Commit e5e1b0d

Browse files
committed
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
1 parent d77bb46 commit e5e1b0d

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

packages/animations/browser/src/dsl/animation_ast_builder.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export class AnimationAstBuilderVisitor implements AnimationDslVisitor {
9696
if (def.type == AnimationMetadataType.State) {
9797
const stateDef = def as AnimationStateMetadata;
9898
const name = stateDef.name;
99-
name.split(/\s*,\s*/).forEach(n => {
99+
name.toString().split(/\s*,\s*/).forEach(n => {
100100
stateDef.name = n;
101101
states.push(this.visitState(stateDef, context));
102102
});

packages/animations/browser/test/dsl/animation_trigger_spec.ts

+11
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,17 @@ import {makeTrigger} from '../shared';
203203
]);
204204
});
205205

206+
it('should treat numeric values (disguised as strings) as proper state values', () => {
207+
const result = makeTrigger('name', [
208+
state(1 as any as string, style({opacity: 0})),
209+
state(0 as any as string, style({opacity: 0})), transition('* => *', animate(1000))
210+
]);
211+
212+
expect(() => {
213+
const trans = buildTransition(result, element, false, true) !;
214+
}).not.toThrow();
215+
});
216+
206217
describe('aliases', () => {
207218
it('should alias the :enter transition as void => *', () => {
208219
const result = makeTrigger('name', [transition(':enter', animate(3333))]);

0 commit comments

Comments
 (0)