From 15795d09cf55272932222b840e7f17bd6172436d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matias=20Niemel=C3=A4?= Date: Fri, 10 Nov 2017 09:46:18 +0200 Subject: [PATCH] fix(animations): validate against trigger() names that use @ symbols (#20326) PR Close #20326 --- .../animations/browser/src/dsl/animation_ast_builder.ts | 5 +++++ packages/animations/browser/test/dsl/animation_spec.ts | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/packages/animations/browser/src/dsl/animation_ast_builder.ts b/packages/animations/browser/src/dsl/animation_ast_builder.ts index 958232d88c..c6ecbef22f 100644 --- a/packages/animations/browser/src/dsl/animation_ast_builder.ts +++ b/packages/animations/browser/src/dsl/animation_ast_builder.ts @@ -90,6 +90,11 @@ export class AnimationAstBuilderVisitor implements AnimationDslVisitor { let depCount = context.depCount = 0; const states: StateAst[] = []; const transitions: TransitionAst[] = []; + if (metadata.name.charAt(0) == '@') { + context.errors.push( + 'animation triggers cannot be prefixed with an `@` sign (e.g. trigger(\'@foo\', [...]))'); + } + metadata.definitions.forEach(def => { this._resetContextStyleTimingState(context); if (def.type == AnimationMetadataType.State) { diff --git a/packages/animations/browser/test/dsl/animation_spec.ts b/packages/animations/browser/test/dsl/animation_spec.ts index 77a4f16569..f5e3fd28b8 100644 --- a/packages/animations/browser/test/dsl/animation_spec.ts +++ b/packages/animations/browser/test/dsl/animation_spec.ts @@ -119,6 +119,14 @@ export function main() { expect(() => validateAndThrowAnimationSequence(steps)).not.toThrow(); }); + it('should not allow triggers to be defined with a prefixed `@` symbol', () => { + const steps = trigger('@foo', []); + + expect(() => validateAndThrowAnimationSequence(steps)) + .toThrowError( + /animation triggers cannot be prefixed with an `@` sign \(e\.g\. trigger\('@foo', \[...\]\)\)/); + }); + it('should throw an error if an animation time is invalid', () => { const steps = [animate('500xs', style({opacity: 1}))];