@@ -33,7 +33,7 @@ export class ViewCompileResult {
3333@CompilerInjectable ( )
3434export class ViewCompiler {
3535 constructor (
36- private _genConfigNext : CompilerConfig , private _schemaRegistryNext : ElementSchemaRegistry ) { }
36+ private _genConfigNext : CompilerConfig , private _schemaRegistry : ElementSchemaRegistry ) { }
3737
3838 compileComponent (
3939 component : CompileDirectiveMetadata , template : TemplateAst [ ] , styles : o . Expression ,
@@ -288,24 +288,23 @@ class ViewBuilder implements TemplateAstVisitor, LocalResolver, BuiltinConverter
288288 elName = null ;
289289 }
290290
291- const { flags, usedEvents, queryMatchesExpr, hostBindings, hostEvents} =
291+ const { flags, usedEvents, queryMatchesExpr, hostBindings : dirHostBindings , hostEvents} =
292292 this . _visitElementOrTemplate ( nodeIndex , ast ) ;
293293
294294 let inputDefs : o . Expression [ ] = [ ] ;
295295 let outputDefs : o . Expression [ ] = [ ] ;
296296 if ( elName ) {
297- ast . inputs . forEach (
298- ( inputAst ) => hostBindings . push ( { context : COMP_VAR , value : inputAst . value } ) ) ;
297+ const hostBindings = ast . inputs
298+ . map ( ( inputAst ) => ( {
299+ context : COMP_VAR as o . Expression ,
300+ value : inputAst . value ,
301+ bindingDef : elementBindingDef ( inputAst , null ) ,
302+ } ) )
303+ . concat ( dirHostBindings ) ;
299304 if ( hostBindings . length ) {
300305 this . _addUpdateExpressions ( nodeIndex , hostBindings , this . updateRendererExpressions ) ;
306+ inputDefs = hostBindings . map ( entry => entry . bindingDef ) ;
301307 }
302- // Note: inputDefs have to be in the same order as hostBindings:
303- // - first the entries from the directives, then the ones from the element.
304- ast . directives . forEach (
305- ( dirAst , dirIndex ) =>
306- inputDefs . push ( ...elementBindingDefs ( dirAst . hostProperties , dirAst ) ) ) ;
307- inputDefs . push ( ...elementBindingDefs ( ast . inputs , null ) ) ;
308-
309308 outputDefs = usedEvents . map (
310309 ( [ target , eventName ] ) => o . literalArr ( [ o . literal ( target ) , o . literal ( eventName ) ] ) ) ;
311310 }
@@ -355,7 +354,7 @@ class ViewBuilder implements TemplateAstVisitor, LocalResolver, BuiltinConverter
355354 flags : NodeFlags ,
356355 usedEvents : [ string , string ] [ ] ,
357356 queryMatchesExpr : o . Expression ,
358- hostBindings : { value : AST , context : o . Expression } [ ] ,
357+ hostBindings : { value : AST , context : o . Expression , bindingDef : o . Expression } [ ] ,
359358 hostEvents : { context : o . Expression , eventAst : BoundEventAst , dirAst : DirectiveAst } [ ] ,
360359 } {
361360 let flags = NodeFlags . None ;
@@ -373,7 +372,7 @@ class ViewBuilder implements TemplateAstVisitor, LocalResolver, BuiltinConverter
373372 usedEvents . set ( elementEventFullName ( target , name ) , [ target , name ] ) ;
374373 } ) ;
375374 } ) ;
376- const hostBindings : { value : AST , context : o . Expression } [ ] = [ ] ;
375+ const hostBindings : { value : AST , context : o . Expression , bindingDef : o . Expression } [ ] = [ ] ;
377376 const hostEvents : { context : o . Expression , eventAst : BoundEventAst , dirAst : DirectiveAst } [ ] = [ ] ;
378377 const componentFactoryResolverProvider = createComponentFactoryResolver ( ast . directives ) ;
379378 if ( componentFactoryResolverProvider ) {
@@ -443,7 +442,7 @@ class ViewBuilder implements TemplateAstVisitor, LocalResolver, BuiltinConverter
443442 providerAst : ProviderAst , dirAst : DirectiveAst , directiveIndex : number ,
444443 elementNodeIndex : number , refs : ReferenceAst [ ] , queryMatches : QueryMatch [ ] ,
445444 usedEvents : Map < string , any > , queryIds : StaticAndDynamicQueryIds ) : {
446- hostBindings : { value : AST , context : o . Expression } [ ] ,
445+ hostBindings : { value : AST , context : o . Expression , bindingDef : o . Expression } [ ] ,
447446 hostEvents : { context : o . Expression , eventAst : BoundEventAst , dirAst : DirectiveAst } [ ]
448447 } {
449448 const nodeIndex = this . nodeDefs . length ;
@@ -513,14 +512,16 @@ class ViewBuilder implements TemplateAstVisitor, LocalResolver, BuiltinConverter
513512 const dirContextExpr = o . importExpr ( createIdentifier ( Identifiers . nodeValue ) ) . callFn ( [
514513 VIEW_VAR , o . literal ( nodeIndex )
515514 ] ) ;
516- const hostBindings = dirAst . hostProperties . map ( ( hostBindingAst ) => {
517- return {
518- value : ( < ASTWithSource > hostBindingAst . value ) . ast ,
519- context : dirContextExpr ,
520- } ;
521- } ) ;
522- const hostEvents = dirAst . hostEvents . map (
523- ( hostEventAst ) => { return { context : dirContextExpr , eventAst : hostEventAst , dirAst} ; } ) ;
515+ const hostBindings =
516+ dirAst . hostProperties . map ( ( hostBindingAst ) => ( {
517+ value : ( < ASTWithSource > hostBindingAst . value ) . ast ,
518+ context : dirContextExpr ,
519+ bindingDef : elementBindingDef ( hostBindingAst , dirAst ) ,
520+ } ) ) ;
521+ const hostEvents = dirAst . hostEvents . map ( ( hostEventAst ) => ( {
522+ context : dirContextExpr ,
523+ eventAst : hostEventAst , dirAst,
524+ } ) ) ;
524525
525526
526527 // directiveDef(
@@ -906,36 +907,32 @@ function lifecycleHookToNodeFlag(lifecycleHook: LifecycleHooks): NodeFlags {
906907 return nodeFlag ;
907908}
908909
909- function elementBindingDefs (
910- inputAsts : BoundElementPropertyAst [ ] , dirAst : DirectiveAst ) : o . Expression [ ] {
911- return inputAsts . map ( ( inputAst ) => {
912- switch ( inputAst . type ) {
913- case PropertyBindingType . Attribute :
914- return o . literalArr ( [
915- o . literal ( BindingType . ElementAttribute ) , o . literal ( inputAst . name ) ,
916- o . literal ( inputAst . securityContext )
917- ] ) ;
918- case PropertyBindingType . Property :
919- return o . literalArr ( [
920- o . literal ( BindingType . ElementProperty ) , o . literal ( inputAst . name ) ,
921- o . literal ( inputAst . securityContext )
922- ] ) ;
923- case PropertyBindingType . Animation :
924- const bindingType = dirAst && dirAst . directive . isComponent ?
925- BindingType . ComponentHostProperty :
926- BindingType . ElementProperty ;
927- return o . literalArr ( [
928- o . literal ( bindingType ) , o . literal ( '@' + inputAst . name ) ,
929- o . literal ( inputAst . securityContext )
930- ] ) ;
931- case PropertyBindingType . Class :
932- return o . literalArr ( [ o . literal ( BindingType . ElementClass ) , o . literal ( inputAst . name ) ] ) ;
933- case PropertyBindingType . Style :
934- return o . literalArr ( [
935- o . literal ( BindingType . ElementStyle ) , o . literal ( inputAst . name ) , o . literal ( inputAst . unit )
936- ] ) ;
937- }
938- } ) ;
910+ function elementBindingDef ( inputAst : BoundElementPropertyAst , dirAst : DirectiveAst ) : o . Expression {
911+ switch ( inputAst . type ) {
912+ case PropertyBindingType . Attribute :
913+ return o . literalArr ( [
914+ o . literal ( BindingType . ElementAttribute ) , o . literal ( inputAst . name ) ,
915+ o . literal ( inputAst . securityContext )
916+ ] ) ;
917+ case PropertyBindingType . Property :
918+ return o . literalArr ( [
919+ o . literal ( BindingType . ElementProperty ) , o . literal ( inputAst . name ) ,
920+ o . literal ( inputAst . securityContext )
921+ ] ) ;
922+ case PropertyBindingType . Animation :
923+ const bindingType = dirAst && dirAst . directive . isComponent ?
924+ BindingType . ComponentHostProperty :
925+ BindingType . ElementProperty ;
926+ return o . literalArr ( [
927+ o . literal ( bindingType ) , o . literal ( '@' + inputAst . name ) , o . literal ( inputAst . securityContext )
928+ ] ) ;
929+ case PropertyBindingType . Class :
930+ return o . literalArr ( [ o . literal ( BindingType . ElementClass ) , o . literal ( inputAst . name ) ] ) ;
931+ case PropertyBindingType . Style :
932+ return o . literalArr ( [
933+ o . literal ( BindingType . ElementStyle ) , o . literal ( inputAst . name ) , o . literal ( inputAst . unit )
934+ ] ) ;
935+ }
939936}
940937
941938
0 commit comments