@@ -209,7 +209,8 @@ export function client_component(analysis, options) {
209209
210210 /** @type {ESTree.Statement[] } */
211211 const store_setup = [ ] ;
212-
212+ /** @type {ESTree.Statement } */
213+ let store_init = b . empty ;
213214 /** @type {ESTree.VariableDeclaration[] } */
214215 const legacy_reactive_declarations = [ ] ;
215216
@@ -227,8 +228,9 @@ export function client_component(analysis, options) {
227228 if ( binding . kind === 'store_sub' ) {
228229 if ( store_setup . length === 0 ) {
229230 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' )
232234 ) ;
233235 }
234236
@@ -379,9 +381,16 @@ export function client_component(analysis, options) {
379381 analysis . slot_names . size > 0 ;
380382
381383 if ( analysis . instance . has_await ) {
384+ const params = [ b . id ( '$$anchor' ) ] ;
385+ if ( should_inject_props ) {
386+ params . push ( b . id ( '$$props' ) ) ;
387+ }
388+ if ( store_setup . length > 0 ) {
389+ params . push ( b . id ( '$$stores' ) ) ;
390+ }
382391 const body = b . function_declaration (
383392 b . id ( '$$body' ) ,
384- should_inject_props ? [ b . id ( '$$anchor' ) , b . id ( '$$props' ) ] : [ b . id ( '$$anchor' ) ] ,
393+ params ,
385394 b . block ( [
386395 b . var ( '$$unsuspend' , b . call ( '$.suspend' ) ) ,
387396 ...component_block . body ,
@@ -397,10 +406,12 @@ export function client_component(analysis, options) {
397406 component_block = b . block ( [
398407 b . var ( 'fragment' , b . call ( '$.comment' ) ) ,
399408 b . var ( 'node' , b . call ( '$.first_child' , b . id ( 'fragment' ) ) ) ,
400- b . stmt ( b . call ( body . id , b . id ( 'node' ) , should_inject_props && b . id ( '$$props' ) ) ) ,
409+ store_init ,
410+ b . stmt ( b . call ( body . id , b . id ( 'node' ) , ...params . slice ( 1 ) ) ) ,
401411 b . stmt ( b . call ( '$.append' , b . id ( '$$anchor' ) , b . id ( 'fragment' ) ) )
402412 ] ) ;
403413 } else {
414+ component_block . body . unshift ( store_init ) ;
404415 component_block . body . push ( .../** @type {ESTree.Statement[] } */ ( template . body ) ) ;
405416 }
406417
0 commit comments