@@ -29,6 +29,7 @@ export function build_set_attributes(
29
29
state
30
30
) {
31
31
let has_state = false ;
32
+ let is_async = false ;
32
33
33
34
/** @type {ObjectExpression['properties'] } */
34
35
const values = [ ] ;
@@ -63,6 +64,8 @@ export function build_set_attributes(
63
64
}
64
65
values . push ( b . spread ( value ) ) ;
65
66
}
67
+
68
+ is_async ||= attribute . metadata . expression . is_async ;
66
69
}
67
70
68
71
const call = b . call (
@@ -80,6 +83,7 @@ export function build_set_attributes(
80
83
context . state . init . push ( b . let ( attributes_id ) ) ;
81
84
const update = b . stmt ( b . assignment ( '=' , attributes_id , call ) ) ;
82
85
context . state . update . push ( update ) ;
86
+ context . state . metadata . update_is_async ||= is_async ;
83
87
return true ;
84
88
}
85
89
@@ -104,7 +108,7 @@ export function build_style_directives(
104
108
const state = context . state ;
105
109
106
110
for ( const directive of style_directives ) {
107
- const { has_state, has_call } = directive . metadata . expression ;
111
+ const { has_state, has_call, is_async } = directive . metadata . expression ;
108
112
109
113
let value =
110
114
directive . value === true
@@ -129,10 +133,14 @@ export function build_style_directives(
129
133
) ;
130
134
131
135
if ( ! is_attributes_reactive && has_call ) {
132
- state . init . push ( build_update ( update ) ) ;
136
+ state . init . push ( build_update ( update , is_async ) ) ;
133
137
} else if ( is_attributes_reactive || has_state || has_call ) {
134
138
state . update . push ( update ) ;
139
+ state . metadata . update_is_async ||= is_async ;
135
140
} else {
141
+ if ( is_async ) {
142
+ throw new Error ( 'TODO top-level await' ) ;
143
+ }
136
144
state . init . push ( update ) ;
137
145
}
138
146
}
@@ -154,7 +162,7 @@ export function build_class_directives(
154
162
) {
155
163
const state = context . state ;
156
164
for ( const directive of class_directives ) {
157
- const { has_state, has_call } = directive . metadata . expression ;
165
+ const { has_state, has_call, is_async } = directive . metadata . expression ;
158
166
let value = /** @type {Expression } */ ( context . visit ( directive . expression ) ) ;
159
167
160
168
if ( has_call ) {
@@ -167,10 +175,14 @@ export function build_class_directives(
167
175
const update = b . stmt ( b . call ( '$.toggle_class' , element_id , b . literal ( directive . name ) , value ) ) ;
168
176
169
177
if ( ! is_attributes_reactive && has_call ) {
170
- state . init . push ( build_update ( update ) ) ;
178
+ state . init . push ( build_update ( update , is_async ) ) ;
171
179
} else if ( is_attributes_reactive || has_state || has_call ) {
172
180
state . update . push ( update ) ;
181
+ state . metadata . update_is_async ||= is_async ;
173
182
} else {
183
+ if ( is_async ) {
184
+ throw new Error ( 'TODO top-level await' ) ;
185
+ }
174
186
state . init . push ( update ) ;
175
187
}
176
188
}
0 commit comments