@@ -54,7 +54,7 @@ describe('host bindings', () => {
54
54
allocHostVars ( 1 ) ;
55
55
}
56
56
if ( rf & RenderFlags . Update ) {
57
- elementProperty ( elementIndex , 'id' , bind ( ctx . id ) ) ;
57
+ elementProperty ( elementIndex , 'id' , bind ( ctx . id ) , null , true ) ;
58
58
}
59
59
}
60
60
} ) ;
@@ -75,7 +75,7 @@ describe('host bindings', () => {
75
75
allocHostVars ( 1 ) ;
76
76
}
77
77
if ( rf & RenderFlags . Update ) {
78
- elementProperty ( elIndex , 'id' , bind ( ctx . id ) ) ;
78
+ elementProperty ( elIndex , 'id' , bind ( ctx . id ) , null , true ) ;
79
79
}
80
80
} ,
81
81
template : ( rf : RenderFlags , ctx : HostBindingComp ) => { }
@@ -84,7 +84,7 @@ describe('host bindings', () => {
84
84
85
85
it ( 'should support host bindings in directives' , ( ) => {
86
86
let directiveInstance : Directive | undefined ;
87
-
87
+ const elementIndices : number [ ] = [ ] ;
88
88
class Directive {
89
89
// @HostBinding ('className')
90
90
klass = 'foo' ;
@@ -94,11 +94,12 @@ describe('host bindings', () => {
94
94
selectors : [ [ '' , 'dir' , '' ] ] ,
95
95
factory : ( ) => directiveInstance = new Directive ,
96
96
hostBindings : ( rf : RenderFlags , ctx : any , elementIndex : number ) => {
97
+ elementIndices . push ( elementIndex ) ;
97
98
if ( rf & RenderFlags . Create ) {
98
99
allocHostVars ( 1 ) ;
99
100
}
100
101
if ( rf & RenderFlags . Update ) {
101
- elementProperty ( elementIndex , 'className' , bind ( ctx . klass ) ) ;
102
+ elementProperty ( elementIndex , 'className' , bind ( ctx . klass ) , null , true ) ;
102
103
}
103
104
}
104
105
} ) ;
@@ -112,15 +113,46 @@ describe('host bindings', () => {
112
113
directiveInstance ! . klass = 'bar' ;
113
114
fixture . update ( ) ;
114
115
expect ( fixture . html ) . toEqual ( '<span class="bar"></span>' ) ;
116
+
117
+ // verify that we always call `hostBindings` function with the same element index
118
+ expect ( elementIndices . every ( id => id === elementIndices [ 0 ] ) ) . toBeTruthy ( ) ;
115
119
} ) ;
116
120
117
121
it ( 'should support host bindings on root component' , ( ) => {
122
+ const elementIndices : number [ ] = [ ] ;
123
+
124
+ class HostBindingComp {
125
+ // @HostBinding ()
126
+ id = 'my-id' ;
127
+
128
+ static ngComponentDef = defineComponent ( {
129
+ type : HostBindingComp ,
130
+ selectors : [ [ 'host-binding-comp' ] ] ,
131
+ factory : ( ) => new HostBindingComp ( ) ,
132
+ consts : 0 ,
133
+ vars : 0 ,
134
+ hostBindings : ( rf : RenderFlags , ctx : HostBindingComp , elIndex : number ) => {
135
+ elementIndices . push ( elIndex ) ;
136
+ if ( rf & RenderFlags . Create ) {
137
+ allocHostVars ( 1 ) ;
138
+ }
139
+ if ( rf & RenderFlags . Update ) {
140
+ elementProperty ( elIndex , 'id' , bind ( ctx . id ) , null , true ) ;
141
+ }
142
+ } ,
143
+ template : ( rf : RenderFlags , ctx : HostBindingComp ) => { }
144
+ } ) ;
145
+ }
146
+
118
147
const fixture = new ComponentFixture ( HostBindingComp ) ;
119
148
expect ( fixture . hostElement . id ) . toBe ( 'my-id' ) ;
120
149
121
150
fixture . component . id = 'other-id' ;
122
151
fixture . update ( ) ;
123
152
expect ( fixture . hostElement . id ) . toBe ( 'other-id' ) ;
153
+
154
+ // verify that we always call `hostBindings` function with the same element index
155
+ expect ( elementIndices . every ( id => id === elementIndices [ 0 ] ) ) . toBeTruthy ( ) ;
124
156
} ) ;
125
157
126
158
it ( 'should support host bindings on nodes with providers' , ( ) => {
@@ -150,7 +182,7 @@ describe('host bindings', () => {
150
182
allocHostVars ( 1 ) ;
151
183
}
152
184
if ( rf & RenderFlags . Update ) {
153
- elementProperty ( elIndex , 'id' , bind ( ctx . id ) ) ;
185
+ elementProperty ( elIndex , 'id' , bind ( ctx . id ) , null , true ) ;
154
186
}
155
187
} ,
156
188
template : ( rf : RenderFlags , ctx : CompWithProviders ) => { } ,
@@ -186,7 +218,7 @@ describe('host bindings', () => {
186
218
allocHostVars ( 1 ) ;
187
219
}
188
220
if ( rf & RenderFlags . Update ) {
189
- elementProperty ( elIndex , 'title' , bind ( ctx . title ) ) ;
221
+ elementProperty ( elIndex , 'title' , bind ( ctx . title ) , null , true ) ;
190
222
}
191
223
} ,
192
224
template : ( rf : RenderFlags , ctx : HostTitleComp ) => { }
@@ -239,7 +271,7 @@ describe('host bindings', () => {
239
271
allocHostVars ( 1 ) ;
240
272
}
241
273
if ( rf & RenderFlags . Update ) {
242
- elementProperty ( elIndex , 'id' , bind ( ctx . id ) ) ;
274
+ elementProperty ( elIndex , 'id' , bind ( ctx . id ) , null , true ) ;
243
275
}
244
276
} ,
245
277
template : ( rf : RenderFlags , ctx : HostBindingComp ) => { }
@@ -329,7 +361,7 @@ describe('host bindings', () => {
329
361
allocHostVars ( 1 ) ;
330
362
}
331
363
if ( rf & RenderFlags . Update ) {
332
- elementProperty ( elIndex , 'title' , bind ( ctx . value ) ) ;
364
+ elementProperty ( elIndex , 'title' , bind ( ctx . value ) , null , true ) ;
333
365
}
334
366
} ,
335
367
inputs : { inputValue : 'inputValue' }
@@ -562,10 +594,11 @@ describe('host bindings', () => {
562
594
allocHostVars ( 8 ) ;
563
595
}
564
596
if ( rf & RenderFlags . Update ) {
565
- elementProperty ( elIndex , 'id' , bind ( pureFunction1 ( 3 , ff , ctx . id ) ) ) ;
566
- elementProperty ( elIndex , 'dir' , bind ( ctx . dir ) ) ;
597
+ elementProperty ( elIndex , 'id' , bind ( pureFunction1 ( 3 , ff , ctx . id ) ) , null , true ) ;
598
+ elementProperty ( elIndex , 'dir' , bind ( ctx . dir ) , null , true ) ;
567
599
elementProperty (
568
- elIndex , 'title' , bind ( pureFunction2 ( 5 , ff2 , ctx . title , ctx . otherTitle ) ) ) ;
600
+ elIndex , 'title' , bind ( pureFunction2 ( 5 , ff2 , ctx . title , ctx . otherTitle ) ) , null ,
601
+ true ) ;
569
602
}
570
603
} ,
571
604
template : ( rf : RenderFlags , ctx : HostBindingComp ) => { }
@@ -640,7 +673,7 @@ describe('host bindings', () => {
640
673
allocHostVars ( 3 ) ;
641
674
}
642
675
if ( rf & RenderFlags . Update ) {
643
- elementProperty ( elIndex , 'id' , bind ( pureFunction1 ( 1 , ff , ctx . id ) ) ) ;
676
+ elementProperty ( elIndex , 'id' , bind ( pureFunction1 ( 1 , ff , ctx . id ) ) , null , true ) ;
644
677
}
645
678
} ,
646
679
template : ( rf : RenderFlags , ctx : HostBindingComp ) => { }
@@ -671,7 +704,7 @@ describe('host bindings', () => {
671
704
allocHostVars ( 3 ) ;
672
705
}
673
706
if ( rf & RenderFlags . Update ) {
674
- elementProperty ( elIndex , 'title' , bind ( pureFunction1 ( 1 , ff1 , ctx . title ) ) ) ;
707
+ elementProperty ( elIndex , 'title' , bind ( pureFunction1 ( 1 , ff1 , ctx . title ) ) , null , true ) ;
675
708
}
676
709
}
677
710
} ) ;
@@ -728,7 +761,7 @@ describe('host bindings', () => {
728
761
allocHostVars ( 3 ) ;
729
762
}
730
763
if ( rf & RenderFlags . Update ) {
731
- elementProperty ( elIndex , 'title' , bind ( pureFunction1 ( 1 , ff1 , ctx . title ) ) ) ;
764
+ elementProperty ( elIndex , 'title' , bind ( pureFunction1 ( 1 , ff1 , ctx . title ) ) , null , true ) ;
732
765
}
733
766
}
734
767
} ) ;
@@ -799,10 +832,12 @@ describe('host bindings', () => {
799
832
}
800
833
if ( rf & RenderFlags . Update ) {
801
834
elementProperty (
802
- elIndex , 'id' , bind ( ctx . condition ? pureFunction1 ( 2 , ff , ctx . id ) : 'green' ) ) ;
835
+ elIndex , 'id' , bind ( ctx . condition ? pureFunction1 ( 2 , ff , ctx . id ) : 'green' ) , null ,
836
+ true ) ;
803
837
elementProperty (
804
838
elIndex , 'title' ,
805
- bind ( ctx . otherCondition ? pureFunction1 ( 4 , ff1 , ctx . title ) : 'other title' ) ) ;
839
+ bind ( ctx . otherCondition ? pureFunction1 ( 4 , ff1 , ctx . title ) : 'other title' ) , null ,
840
+ true ) ;
806
841
}
807
842
} ,
808
843
template : ( rf : RenderFlags , ctx : HostBindingComp ) => { }
@@ -859,7 +894,7 @@ describe('host bindings', () => {
859
894
allocHostVars ( 1 ) ;
860
895
}
861
896
if ( rf & RenderFlags . Update ) {
862
- elementProperty ( elementIndex , 'id' , bind ( ctx . id ) ) ;
897
+ elementProperty ( elementIndex , 'id' , bind ( ctx . id ) , null , true ) ;
863
898
}
864
899
} ,
865
900
factory : ( ) => superDir = new SuperDirective ( ) ,
@@ -877,7 +912,7 @@ describe('host bindings', () => {
877
912
allocHostVars ( 1 ) ;
878
913
}
879
914
if ( rf & RenderFlags . Update ) {
880
- elementProperty ( elementIndex , 'title' , bind ( ctx . title ) ) ;
915
+ elementProperty ( elementIndex , 'title' , bind ( ctx . title ) , null , true ) ;
881
916
}
882
917
} ,
883
918
factory : ( ) => subDir = new SubDirective ( ) ,
@@ -965,7 +1000,7 @@ describe('host bindings', () => {
965
1000
allocHostVars ( 1 ) ;
966
1001
}
967
1002
if ( rf & RenderFlags . Update ) {
968
- elementProperty ( elIndex , 'id' , bind ( ctx . foos . length ) ) ;
1003
+ elementProperty ( elIndex , 'id' , bind ( ctx . foos . length ) , null , true ) ;
969
1004
}
970
1005
} ,
971
1006
contentQueries : ( dirIndex ) => { registerContentQuery ( query ( null , [ 'foo' ] ) , dirIndex ) ; } ,
@@ -1024,7 +1059,7 @@ describe('host bindings', () => {
1024
1059
allocHostVars ( 1 ) ;
1025
1060
}
1026
1061
if ( rf & RenderFlags . Update ) {
1027
- elementProperty ( elIndex , 'id' , bind ( ctx . myValue ) ) ;
1062
+ elementProperty ( elIndex , 'id' , bind ( ctx . myValue ) , null , true ) ;
1028
1063
}
1029
1064
} ,
1030
1065
template : ( rf : RenderFlags , cmp : HostBindingWithContentHooks ) => { }
0 commit comments