@@ -92,7 +92,7 @@ export class Compiler {
9292 // Used for bootstrapping.
9393 compileInHost ( componentTypeOrBinding :any ) :Promise < ProtoViewRef > {
9494 var componentBinding = this . _bindDirective ( componentTypeOrBinding ) ;
95- this . _assertTypeIsComponent ( componentBinding ) ;
95+ Compiler . _assertTypeIsComponent ( componentBinding ) ;
9696
9797 var directiveMetadata = componentBinding . metadata ;
9898 return this . _render . compileHost ( directiveMetadata ) . then ( ( hostRenderPv ) => {
@@ -104,7 +104,7 @@ export class Compiler {
104104
105105 compile ( component : Type ) :Promise < ProtoViewRef > {
106106 var componentBinding = this . _bindDirective ( component ) ;
107- this . _assertTypeIsComponent ( componentBinding ) ;
107+ Compiler . _assertTypeIsComponent ( componentBinding ) ;
108108 var protoView = this . _compile ( componentBinding ) ;
109109 var pvPromise = PromiseWrapper . isPromise ( protoView ) ? protoView : PromiseWrapper . resolve ( protoView ) ;
110110 return pvPromise . then ( ( appProtoView ) => {
@@ -134,13 +134,21 @@ export class Compiler {
134134 if ( isBlank ( template ) ) {
135135 return null ;
136136 }
137- var directives = ListWrapper . map (
138- this . _flattenDirectives ( template ) ,
139- ( directive ) => this . _bindDirective ( directive )
140- ) ;
141- var renderTemplate = this . _buildRenderTemplate ( component , template , directives ) ;
137+
138+ var directives = this . _flattenDirectives ( template ) ;
139+
140+ for ( var i = 0 ; i < directives . length ; i ++ ) {
141+ if ( ! Compiler . _isValidDirective ( directives [ i ] ) ) {
142+ throw new BaseException (
143+ `Unexpected directive value '${ stringify ( directives [ i ] ) } ' on the View of component '${ stringify ( component ) } '` ) ;
144+ }
145+ }
146+
147+ var boundDirectives = ListWrapper . map ( directives , ( directive ) => this . _bindDirective ( directive ) ) ;
148+
149+ var renderTemplate = this . _buildRenderTemplate ( component , template , boundDirectives ) ;
142150 pvPromise = this . _render . compile ( renderTemplate ) . then ( ( renderPv ) => {
143- return this . _compileNestedProtoViews ( componentBinding , renderPv , directives ) ;
151+ return this . _compileNestedProtoViews ( componentBinding , renderPv , boundDirectives ) ;
144152 } ) ;
145153
146154 MapWrapper . set ( this . _compiling , component , pvPromise ) ;
@@ -227,7 +235,7 @@ export class Compiler {
227235 return directives ;
228236 }
229237
230- _flattenList ( tree :List < any > , out :List < Type > ) :void {
238+ _flattenList ( tree :List < any > , out :List < any > /*< Type|Binding>*/ ) :void {
231239 for ( var i = 0 ; i < tree . length ; i ++ ) {
232240 var item = tree [ i ] ;
233241 if ( ListWrapper . isList ( item ) ) {
@@ -238,7 +246,11 @@ export class Compiler {
238246 }
239247 }
240248
241- _assertTypeIsComponent ( directiveBinding :DirectiveBinding ) :void {
249+ static _isValidDirective ( value : any ) : boolean {
250+ return isPresent ( value ) && ( value instanceof Type || value instanceof Binding ) ;
251+ }
252+
253+ static _assertTypeIsComponent ( directiveBinding :DirectiveBinding ) :void {
242254 if ( directiveBinding . metadata . type !== renderApi . DirectiveMetadata . COMPONENT_TYPE ) {
243255 throw new BaseException ( `Could not load '${ stringify ( directiveBinding . key . token ) } ' because it is not a component.` ) ;
244256 }
0 commit comments