@@ -63,32 +63,48 @@ function get_attribute_name(element, attribute, context) {
63
63
* @param {boolean } is_attributes_reactive
64
64
*/
65
65
function serialize_style_directives ( style_directives , element_id , context , is_attributes_reactive ) {
66
- if ( style_directives . length > 0 ) {
67
- const values = style_directives . map ( ( directive ) => {
68
- let value =
69
- directive . value === true
70
- ? serialize_get_binding ( { name : directive . name , type : 'Identifier' } , context . state )
71
- : serialize_attribute_value ( directive . value , context ) [ 1 ] ;
72
- return b . stmt (
73
- b . call (
74
- '$.style' ,
75
- element_id ,
76
- b . literal ( directive . name ) ,
77
- value ,
78
- /** @type {import('estree').Expression } */ (
79
- directive . modifiers . includes ( 'important' ) ? b . true : undefined
80
- )
66
+ const state = context . state ;
67
+
68
+ for ( const directive of style_directives ) {
69
+ let value =
70
+ directive . value === true
71
+ ? serialize_get_binding ( { name : directive . name , type : 'Identifier' } , context . state )
72
+ : serialize_attribute_value ( directive . value , context ) [ 1 ] ;
73
+ const grouped = b . stmt (
74
+ b . call (
75
+ '$.style' ,
76
+ element_id ,
77
+ b . literal ( directive . name ) ,
78
+ value ,
79
+ /** @type {import('estree').Expression } */ (
80
+ directive . modifiers . includes ( 'important' ) ? b . true : undefined
81
+ )
82
+ )
83
+ ) ;
84
+ const singular = b . stmt (
85
+ b . call (
86
+ '$.style_effect' ,
87
+ element_id ,
88
+ b . literal ( directive . name ) ,
89
+ b . arrow ( [ ] , value ) ,
90
+ /** @type {import('estree').Expression } */ (
91
+ directive . modifiers . includes ( 'important' ) ? b . true : undefined
81
92
)
93
+ )
94
+ ) ;
95
+
96
+ const contains_call_expression =
97
+ Array . isArray ( directive . value ) &&
98
+ directive . value . some (
99
+ ( v ) => v . type === 'ExpressionTag' && v . metadata . contains_call_expression
82
100
) ;
83
- } ) ;
84
101
85
- if (
86
- is_attributes_reactive ||
87
- style_directives . some ( ( directive ) => directive . metadata . dynamic )
88
- ) {
89
- context . state . update . push ( ...values . map ( ( v ) => ( { grouped : v } ) ) ) ;
102
+ if ( ! is_attributes_reactive && contains_call_expression ) {
103
+ state . update_effects . push ( singular ) ;
104
+ } else if ( is_attributes_reactive || directive . metadata . dynamic || contains_call_expression ) {
105
+ state . update . push ( { grouped, singular } ) ;
90
106
} else {
91
- context . state . init . push ( ... values ) ;
107
+ state . init . push ( grouped ) ;
92
108
}
93
109
}
94
110
}
@@ -123,21 +139,21 @@ function parse_directive_name(name) {
123
139
* @param {boolean } is_attributes_reactive
124
140
*/
125
141
function serialize_class_directives ( class_directives , element_id , context , is_attributes_reactive ) {
126
- if ( class_directives . length > 0 ) {
127
- const values = class_directives . map ( ( directive ) => {
128
- const value = /** @type {import('estree').Expression } */ (
129
- context . visit ( directive . expression )
130
- ) ;
131
- return b . stmt ( b . call ( '$.class_toggle' , element_id , b . literal ( directive . name ) , value ) ) ;
132
- } ) ;
142
+ const state = context . state ;
143
+ for ( const directive of class_directives ) {
144
+ const value = /** @type {import('estree').Expression } */ ( context . visit ( directive . expression ) ) ;
145
+ const grouped = b . stmt ( b . call ( '$.class_toggle' , element_id , b . literal ( directive . name ) , value ) ) ;
146
+ const singular = b . stmt (
147
+ b . call ( '$.class_toggle_effect' , element_id , b . literal ( directive . name ) , b . arrow ( [ ] , value ) )
148
+ ) ;
149
+ const contains_call_expression = directive . expression . type === 'CallExpression' ;
133
150
134
- if (
135
- is_attributes_reactive ||
136
- class_directives . some ( ( directive ) => directive . metadata . dynamic )
137
- ) {
138
- context . state . update . push ( ...values . map ( ( v ) => ( { grouped : v } ) ) ) ;
151
+ if ( ! is_attributes_reactive && contains_call_expression ) {
152
+ state . update_effects . push ( singular ) ;
153
+ } else if ( is_attributes_reactive || directive . metadata . dynamic || contains_call_expression ) {
154
+ state . update . push ( { grouped, singular } ) ;
139
155
} else {
140
- context . state . init . push ( ... values ) ;
156
+ state . init . push ( grouped ) ;
141
157
}
142
158
}
143
159
}
@@ -295,7 +311,9 @@ function serialize_element_spread_attributes(attributes, context, element, eleme
295
311
values . push ( /** @type {import('estree').Expression } */ ( context . visit ( attribute ) ) ) ;
296
312
}
297
313
298
- is_reactive ||= attribute . metadata . dynamic ;
314
+ is_reactive ||=
315
+ attribute . metadata . dynamic ||
316
+ ( attribute . type === 'SpreadAttribute' && attribute . metadata . contains_call_expression ) ;
299
317
}
300
318
301
319
const lowercase_attributes =
0 commit comments