77 */
88import { AnimateTimings , AnimationAnimateChildMetadata , AnimationAnimateMetadata , AnimationAnimateRefMetadata , AnimationGroupMetadata , AnimationKeyframesSequenceMetadata , AnimationMetadata , AnimationMetadataType , AnimationOptions , AnimationQueryMetadata , AnimationQueryOptions , AnimationReferenceMetadata , AnimationSequenceMetadata , AnimationStaggerMetadata , AnimationStateMetadata , AnimationStyleMetadata , AnimationTransitionMetadata , AnimationTriggerMetadata , AUTO_STYLE , style , ɵStyleDataMap } from '@angular/animations' ;
99
10+ import { invalidDefinition , invalidKeyframes , invalidOffset , invalidParallelAnimation , invalidProperty , invalidStagger , invalidState , invalidStyleValue , invalidTrigger , keyframeOffsetsOutOfOrder , keyframesMissingOffsets } from '../error_helpers' ;
1011import { AnimationDriver } from '../render/animation_driver' ;
1112import { getOrSetDefaultValue } from '../render/shared' ;
1213import { convertToMap , copyObj , extractStyleParams , iteratorToArray , NG_ANIMATING_SELECTOR , NG_TRIGGER_SELECTOR , normalizeAnimationEntry , resolveTiming , SUBSTITUTION_EXPR_START , validateStyleParams , visitDslNode } from '../util' ;
@@ -56,7 +57,7 @@ const SELF_TOKEN_REGEX = new RegExp(`\s*${SELF_TOKEN}\s*,?`, 'g');
5657 */
5758export function buildAnimationAst (
5859 driver : AnimationDriver , metadata : AnimationMetadata | AnimationMetadata [ ] ,
59- errors : string [ ] ) : Ast < AnimationMetadataType > {
60+ errors : Error [ ] ) : Ast < AnimationMetadataType > {
6061 return new AnimationAstBuilderVisitor ( driver ) . build ( metadata , errors ) ;
6162}
6263
@@ -65,7 +66,7 @@ const ROOT_SELECTOR = '';
6566export class AnimationAstBuilderVisitor implements AnimationDslVisitor {
6667 constructor ( private _driver : AnimationDriver ) { }
6768
68- build ( metadata : AnimationMetadata | AnimationMetadata [ ] , errors : string [ ] ) :
69+ build ( metadata : AnimationMetadata | AnimationMetadata [ ] , errors : Error [ ] ) :
6970 Ast < AnimationMetadataType > {
7071 const context = new AnimationAstBuilderContext ( errors ) ;
7172 this . _resetContextStyleTimingState ( context ) ;
@@ -87,8 +88,7 @@ export class AnimationAstBuilderVisitor implements AnimationDslVisitor {
8788 const states : StateAst [ ] = [ ] ;
8889 const transitions : TransitionAst [ ] = [ ] ;
8990 if ( metadata . name . charAt ( 0 ) == '@' ) {
90- context . errors . push (
91- 'animation triggers cannot be prefixed with an `@` sign (e.g. trigger(\'@foo\', [...]))' ) ;
91+ context . errors . push ( invalidTrigger ( ) ) ;
9292 }
9393
9494 metadata . definitions . forEach ( def => {
@@ -107,8 +107,7 @@ export class AnimationAstBuilderVisitor implements AnimationDslVisitor {
107107 depCount += transition . depCount ;
108108 transitions . push ( transition ) ;
109109 } else {
110- context . errors . push (
111- 'only state() and transition() definitions can sit inside of a trigger()' ) ;
110+ context . errors . push ( invalidDefinition ( ) ) ;
112111 }
113112 } ) ;
114113
@@ -142,10 +141,7 @@ export class AnimationAstBuilderVisitor implements AnimationDslVisitor {
142141 } ) ;
143142 if ( missingSubs . size ) {
144143 const missingSubsArr = iteratorToArray ( missingSubs . values ( ) ) ;
145- context . errors . push ( `state("${
146- metadata
147- . name } ", ...) must define default values for all the following style substitutions: ${
148- missingSubsArr . join ( ', ' ) } `) ;
144+ context . errors . push ( invalidState ( metadata . name , missingSubsArr ) ) ;
149145 }
150146 }
151147
@@ -252,7 +248,7 @@ export class AnimationAstBuilderVisitor implements AnimationDslVisitor {
252248 if ( styleTuple === AUTO_STYLE ) {
253249 styles . push ( styleTuple ) ;
254250 } else {
255- context . errors . push ( `The provided style string value ${ styleTuple } is not allowed.` ) ;
251+ context . errors . push ( invalidStyleValue ( styleTuple ) ) ;
256252 }
257253 } else {
258254 styles . push ( convertToMap ( styleTuple ) ) ;
@@ -301,8 +297,7 @@ export class AnimationAstBuilderVisitor implements AnimationDslVisitor {
301297
302298 tuple . forEach ( ( value , prop ) => {
303299 if ( ! this . _driver . validateStyleProperty ( prop ) ) {
304- context . errors . push ( `The provided animation property "${
305- prop } " is not a supported CSS property for animations`) ;
300+ context . errors . push ( invalidProperty ( prop ) ) ;
306301 return ;
307302 }
308303
@@ -314,11 +309,8 @@ export class AnimationAstBuilderVisitor implements AnimationDslVisitor {
314309 if ( collectedEntry ) {
315310 if ( startTime != endTime && startTime >= collectedEntry . startTime &&
316311 endTime <= collectedEntry . endTime ) {
317- context . errors . push ( `The CSS property "${ prop } " that exists between the times of "${
318- collectedEntry . startTime } ms" and "${
319- collectedEntry
320- . endTime } ms" is also being animated in a parallel animation between the times of "${
321- startTime } ms" and "${ endTime } ms"`) ;
312+ context . errors . push ( invalidParallelAnimation (
313+ prop , collectedEntry . startTime , collectedEntry . endTime , startTime , endTime ) ) ;
322314 updateCollectedStyle = false ;
323315 }
324316
@@ -343,7 +335,7 @@ export class AnimationAstBuilderVisitor implements AnimationDslVisitor {
343335 KeyframesAst {
344336 const ast : KeyframesAst = { type : AnimationMetadataType . Keyframes , styles : [ ] , options : null } ;
345337 if ( ! context . currentAnimateTimings ) {
346- context . errors . push ( `keyframes() must be placed inside of a call to animate()` ) ;
338+ context . errors . push ( invalidKeyframes ( ) ) ;
347339 return ast ;
348340 }
349341
@@ -372,17 +364,17 @@ export class AnimationAstBuilderVisitor implements AnimationDslVisitor {
372364 } ) ;
373365
374366 if ( keyframesOutOfRange ) {
375- context . errors . push ( `Please ensure that all keyframe offsets are between 0 and 1` ) ;
367+ context . errors . push ( invalidOffset ( ) ) ;
376368 }
377369
378370 if ( offsetsOutOfOrder ) {
379- context . errors . push ( `Please ensure that all keyframe offsets are in order` ) ;
371+ context . errors . push ( keyframeOffsetsOutOfOrder ( ) ) ;
380372 }
381373
382374 const length = metadata . steps . length ;
383375 let generatedOffset = 0 ;
384376 if ( totalKeyframesWithOffsets > 0 && totalKeyframesWithOffsets < length ) {
385- context . errors . push ( `Not all style() steps within the declared keyframes() contain offsets` ) ;
377+ context . errors . push ( keyframesMissingOffsets ( ) ) ;
386378 } else if ( totalKeyframesWithOffsets == 0 ) {
387379 generatedOffset = MAX_KEYFRAME_OFFSET / ( length - 1 ) ;
388380 }
@@ -462,7 +454,7 @@ export class AnimationAstBuilderVisitor implements AnimationDslVisitor {
462454 visitStagger ( metadata : AnimationStaggerMetadata , context : AnimationAstBuilderContext ) :
463455 StaggerAst {
464456 if ( ! context . currentQuery ) {
465- context . errors . push ( `stagger() can only be used inside of query()` ) ;
457+ context . errors . push ( invalidStagger ( ) ) ;
466458 }
467459 const timings = metadata . timings === 'full' ?
468460 { duration : 0 , delay : 0 , easing : 'full' } :
@@ -511,7 +503,7 @@ export class AnimationAstBuilderContext {
511503 public currentTime : number = 0 ;
512504 public collectedStyles = new Map < string , Map < string , StyleTimeTuple > > ( ) ;
513505 public options : AnimationOptions | null = null ;
514- constructor ( public errors : string [ ] ) { }
506+ constructor ( public errors : Error [ ] ) { }
515507}
516508
517509type OffsetStyles = string | ɵStyleDataMap ;
@@ -537,7 +529,7 @@ function consumeOffset(styles: OffsetStyles|Array<OffsetStyles>): number|null {
537529 return offset ;
538530}
539531
540- function constructTimingAst ( value : string | number | AnimateTimings , errors : string [ ] ) {
532+ function constructTimingAst ( value : string | number | AnimateTimings , errors : Error [ ] ) {
541533 let timings : AnimateTimings | null = null ;
542534 if ( value . hasOwnProperty ( 'duration' ) ) {
543535 timings = value as AnimateTimings ;
0 commit comments