@@ -28,9 +28,6 @@ const STYLE_PREFIX = 'style';
2828
2929const ANIMATE_PROP_PREFIX = 'animate-' ;
3030
31- /**
32- * Type of a parsed property
33- */
3431export enum BoundPropertyType {
3532 DEFAULT ,
3633 LITERAL_ATTR ,
@@ -55,49 +52,48 @@ export class BoundProperty {
5552 */
5653export class BindingParser {
5754 pipesByName : Map < string , CompilePipeMetadata > = new Map ( ) ;
58- errors : ParseError [ ] = [ ] ;
5955
6056 constructor (
6157 private _exprParser : Parser , private _interpolationConfig : InterpolationConfig ,
62- protected _schemaRegistry : ElementSchemaRegistry , protected _schemas : SchemaMetadata [ ] ,
63- pipes : CompilePipeMetadata [ ] ) {
58+ private _schemaRegistry : ElementSchemaRegistry , private _schemas : SchemaMetadata [ ] ,
59+ pipes : CompilePipeMetadata [ ] , private _targetErrors : ParseError [ ] ) {
6460 pipes . forEach ( pipe => this . pipesByName . set ( pipe . name , pipe ) ) ;
6561 }
6662
6763 createDirectiveHostPropertyAsts (
68- elementName : string , hostProps : { [ key : string ] : string } , sourceSpan : ParseSourceSpan ,
69- targetPropertyAsts : BoundElementPropertyAst [ ] ) {
64+ elementName : string , hostProps : { [ key : string ] : string } ,
65+ sourceSpan : ParseSourceSpan ) : BoundElementPropertyAst [ ] {
7066 if ( hostProps ) {
7167 const boundProps : BoundProperty [ ] = [ ] ;
7268 Object . keys ( hostProps ) . forEach ( propName => {
7369 const expression = hostProps [ propName ] ;
7470 if ( typeof expression === 'string' ) {
7571 this . parsePropertyBinding ( propName , expression , true , sourceSpan , [ ] , boundProps ) ;
7672 } else {
77- this . reportError (
73+ this . _reportError (
7874 `Value of the host property binding "${ propName } " needs to be a string representing an expression but got "${ expression } " (${ typeof expression } )` ,
7975 sourceSpan ) ;
8076 }
8177 } ) ;
82- boundProps . forEach (
83- ( prop ) => { targetPropertyAsts . push ( this . createElementPropertyAst ( elementName , prop ) ) ; } ) ;
78+ return boundProps . map ( ( prop ) => this . createElementPropertyAst ( elementName , prop ) ) ;
8479 }
8580 }
8681
87- createDirectiveHostEventAsts (
88- hostListeners : { [ key : string ] : string } , sourceSpan : ParseSourceSpan ,
89- targetEventAsts : BoundEventAst [ ] ) {
82+ createDirectiveHostEventAsts ( hostListeners : { [ key : string ] : string } , sourceSpan : ParseSourceSpan ) :
83+ BoundEventAst [ ] {
9084 if ( hostListeners ) {
85+ const targetEventAsts : BoundEventAst [ ] = [ ] ;
9186 Object . keys ( hostListeners ) . forEach ( propName => {
9287 const expression = hostListeners [ propName ] ;
9388 if ( typeof expression === 'string' ) {
9489 this . parseEvent ( propName , expression , sourceSpan , [ ] , targetEventAsts ) ;
9590 } else {
96- this . reportError (
91+ this . _reportError (
9792 `Value of the host listener "${ propName } " needs to be a string representing an expression but got "${ expression } " (${ typeof expression } )` ,
9893 sourceSpan ) ;
9994 }
10095 } ) ;
96+ return targetEventAsts ;
10197 }
10298 }
10399
@@ -115,7 +111,7 @@ export class BindingParser {
115111 }
116112 return ast ;
117113 } catch ( e ) {
118- this . reportError ( `${ e } ` , sourceSpan ) ;
114+ this . _reportError ( `${ e } ` , sourceSpan ) ;
119115 return this . _exprParser . wrapLiteralPrimitive ( 'ERROR' , sourceInfo ) ;
120116 }
121117 }
@@ -150,10 +146,10 @@ export class BindingParser {
150146 }
151147 } ) ;
152148 bindingsResult . warnings . forEach (
153- ( warning ) => { this . reportError ( warning , sourceSpan , ParseErrorLevel . WARNING ) ; } ) ;
149+ ( warning ) => { this . _reportError ( warning , sourceSpan , ParseErrorLevel . WARNING ) ; } ) ;
154150 return bindingsResult . templateBindings ;
155151 } catch ( e ) {
156- this . reportError ( `${ e } ` , sourceSpan ) ;
152+ this . _reportError ( `${ e } ` , sourceSpan ) ;
157153 return [ ] ;
158154 }
159155 }
@@ -163,8 +159,8 @@ export class BindingParser {
163159 targetProps : BoundProperty [ ] ) {
164160 if ( _isAnimationLabel ( name ) ) {
165161 name = name . substring ( 1 ) ;
166- if ( isPresent ( value ) && value . length > 0 ) {
167- this . reportError (
162+ if ( value ) {
163+ this . _reportError (
168164 `Assigning animation triggers via @prop="exp" attributes with an expression is invalid.` +
169165 ` Use property bindings (e.g. [@prop]="exp") or use an attribute without a value (e.g. @prop) instead.` ,
170166 sourceSpan , ParseErrorLevel . FATAL ) ;
@@ -239,7 +235,7 @@ export class BindingParser {
239235 this . _checkPipes ( ast , sourceSpan ) ;
240236 return ast ;
241237 } catch ( e ) {
242- this . reportError ( `${ e } ` , sourceSpan ) ;
238+ this . _reportError ( `${ e } ` , sourceSpan ) ;
243239 return this . _exprParser . wrapLiteralPrimitive ( 'ERROR' , sourceInfo ) ;
244240 }
245241 }
@@ -271,7 +267,7 @@ export class BindingParser {
271267 `\n1. If '${ elementName } ' is an Angular component and it has '${ boundPropertyName } ' input, then verify that it is part of this module.` +
272268 `\n2. If '${ elementName } ' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schemas' of this component to suppress this message.\n` ;
273269 }
274- this . reportError ( errorMsg , boundProp . sourceSpan ) ;
270+ this . _reportError ( errorMsg , boundProp . sourceSpan ) ;
275271 }
276272 } else {
277273 if ( parts [ 0 ] == ATTRIBUTE_PREFIX ) {
@@ -299,7 +295,7 @@ export class BindingParser {
299295 bindingType = PropertyBindingType . Style ;
300296 securityContext = SecurityContext . STYLE ;
301297 } else {
302- this . reportError ( `Invalid property name '${ boundProp . name } '` , boundProp . sourceSpan ) ;
298+ this . _reportError ( `Invalid property name '${ boundProp . name } '` , boundProp . sourceSpan ) ;
303299 bindingType = null ;
304300 securityContext = null ;
305301 }
@@ -336,13 +332,13 @@ export class BindingParser {
336332 break ;
337333
338334 default :
339- this . reportError (
335+ this . _reportError (
340336 `The provided animation output phase value "${ phase } " for "@${ eventName } " is not supported (use start or done)` ,
341337 sourceSpan ) ;
342338 break ;
343339 }
344340 } else {
345- this . reportError (
341+ this . _reportError (
346342 `The animation trigger output event (@${ eventName } ) is missing its phase value name (start or done are currently supported)` ,
347343 sourceSpan ) ;
348344 }
@@ -369,26 +365,26 @@ export class BindingParser {
369365 this . _reportExpressionParserErrors ( ast . errors , sourceSpan ) ;
370366 }
371367 if ( ! ast || ast . ast instanceof EmptyExpr ) {
372- this . reportError ( `Empty expressions are not allowed` , sourceSpan ) ;
368+ this . _reportError ( `Empty expressions are not allowed` , sourceSpan ) ;
373369 return this . _exprParser . wrapLiteralPrimitive ( 'ERROR' , sourceInfo ) ;
374370 }
375371 this . _checkPipes ( ast , sourceSpan ) ;
376372 return ast ;
377373 } catch ( e ) {
378- this . reportError ( `${ e } ` , sourceSpan ) ;
374+ this . _reportError ( `${ e } ` , sourceSpan ) ;
379375 return this . _exprParser . wrapLiteralPrimitive ( 'ERROR' , sourceInfo ) ;
380376 }
381377 }
382378
383- reportError (
379+ private _reportError (
384380 message : string , sourceSpan : ParseSourceSpan ,
385381 level : ParseErrorLevel = ParseErrorLevel . FATAL ) {
386- this . errors . push ( new ParseError ( sourceSpan , message , level ) ) ;
382+ this . _targetErrors . push ( new ParseError ( sourceSpan , message , level ) ) ;
387383 }
388384
389385 private _reportExpressionParserErrors ( errors : ParserError [ ] , sourceSpan : ParseSourceSpan ) {
390386 for ( const error of errors ) {
391- this . reportError ( error . message , sourceSpan ) ;
387+ this . _reportError ( error . message , sourceSpan ) ;
392388 }
393389 }
394390
@@ -398,7 +394,7 @@ export class BindingParser {
398394 ast . visit ( collector ) ;
399395 collector . pipes . forEach ( ( pipeName ) => {
400396 if ( ! this . pipesByName . has ( pipeName ) ) {
401- this . reportError ( `The pipe '${ pipeName } ' could not be found` , sourceSpan ) ;
397+ this . _reportError ( `The pipe '${ pipeName } ' could not be found` , sourceSpan ) ;
402398 }
403399 } ) ;
404400 }
@@ -415,13 +411,13 @@ export class BindingParser {
415411 const report = isAttr ? this . _schemaRegistry . validateAttribute ( propName ) :
416412 this . _schemaRegistry . validateProperty ( propName ) ;
417413 if ( report . error ) {
418- this . reportError ( report . msg , sourceSpan , ParseErrorLevel . FATAL ) ;
414+ this . _reportError ( report . msg , sourceSpan , ParseErrorLevel . FATAL ) ;
419415 }
420416 }
421417}
422418
423419export class PipeCollector extends RecursiveAstVisitor {
424- pipes : Set < string > = new Set < string > ( ) ;
420+ pipes = new Set < string > ( ) ;
425421 visitPipe ( ast : BindingPipe , context : any ) : any {
426422 this . pipes . add ( ast . name ) ;
427423 ast . exp . visit ( this ) ;
0 commit comments