@@ -209,7 +209,8 @@ export function client_component(analysis, options) {
209
209
210
210
/** @type {ESTree.Statement[] } */
211
211
const store_setup = [ ] ;
212
-
212
+ /** @type {ESTree.Statement } */
213
+ let store_init = b . empty ;
213
214
/** @type {ESTree.VariableDeclaration[] } */
214
215
const legacy_reactive_declarations = [ ] ;
215
216
@@ -227,8 +228,9 @@ export function client_component(analysis, options) {
227
228
if ( binding . kind === 'store_sub' ) {
228
229
if ( store_setup . length === 0 ) {
229
230
needs_store_cleanup = true ;
230
- store_setup . push (
231
- b . const ( b . array_pattern ( [ b . id ( '$$stores' ) , b . id ( '$$cleanup' ) ] ) , b . call ( '$.setup_stores' ) )
231
+ store_init = b . const (
232
+ b . array_pattern ( [ b . id ( '$$stores' ) , b . id ( '$$cleanup' ) ] ) ,
233
+ b . call ( '$.setup_stores' )
232
234
) ;
233
235
}
234
236
@@ -385,9 +387,16 @@ export function client_component(analysis, options) {
385
387
analysis . slot_names . size > 0 ;
386
388
387
389
if ( analysis . instance . has_await ) {
390
+ const params = [ b . id ( '$$anchor' ) ] ;
391
+ if ( should_inject_props ) {
392
+ params . push ( b . id ( '$$props' ) ) ;
393
+ }
394
+ if ( store_setup . length > 0 ) {
395
+ params . push ( b . id ( '$$stores' ) ) ;
396
+ }
388
397
const body = b . function_declaration (
389
398
b . id ( '$$body' ) ,
390
- should_inject_props ? [ b . id ( '$$anchor' ) , b . id ( '$$props' ) ] : [ b . id ( '$$anchor' ) ] ,
399
+ params ,
391
400
b . block ( [
392
401
b . var ( '$$unsuspend' , b . call ( '$.suspend' ) ) ,
393
402
...component_block . body ,
@@ -403,10 +412,12 @@ export function client_component(analysis, options) {
403
412
component_block = b . block ( [
404
413
b . var ( 'fragment' , b . call ( '$.comment' ) ) ,
405
414
b . var ( 'node' , b . call ( '$.first_child' , b . id ( 'fragment' ) ) ) ,
406
- b . stmt ( b . call ( body . id , b . id ( 'node' ) , should_inject_props && b . id ( '$$props' ) ) ) ,
415
+ store_init ,
416
+ b . stmt ( b . call ( body . id , b . id ( 'node' ) , ...params . slice ( 1 ) ) ) ,
407
417
b . stmt ( b . call ( '$.append' , b . id ( '$$anchor' ) , b . id ( 'fragment' ) ) )
408
418
] ) ;
409
419
} else {
420
+ component_block . body . unshift ( store_init ) ;
410
421
component_block . body . push ( .../** @type {ESTree.Statement[] } */ ( template . body ) ) ;
411
422
}
412
423
0 commit comments