@@ -359,22 +359,38 @@ export function client_component(analysis, options) {
359359 if ( dev ) push_args . push ( b . id ( analysis . name ) ) ;
360360
361361 let component_block = b . block ( [
362+ store_init ,
362363 ...store_setup ,
363364 ...legacy_reactive_declarations ,
364365 ...group_binding_declarations ,
365- ...state . instance_level_snippets ,
366- .../** @type {ESTree.Statement[] } */ ( instance . body ) ,
367- analysis . runes || ! analysis . needs_context
368- ? b . empty
369- : b . stmt ( b . call ( '$.init' , analysis . immutable ? b . true : undefined ) )
366+ ...state . instance_level_snippets
370367 ] ) ;
371368
369+ if ( analysis . instance . has_await ) {
370+ const body = b . block ( [
371+ .../** @type {ESTree.Statement[] } */ ( instance . body ) ,
372+ b . if ( b . call ( '$.aborted' ) , b . return ( ) ) ,
373+ .../** @type {ESTree.Statement[] } */ ( template . body )
374+ ] ) ;
375+
376+ component_block . body . push ( b . stmt ( b . call ( `$.async_body` , b . arrow ( [ ] , body , true ) ) ) ) ;
377+ } else {
378+ component_block . body . push (
379+ .../** @type {ESTree.Statement[] } */ ( instance . body ) ,
380+ .../** @type {ESTree.Statement[] } */ ( template . body )
381+ ) ;
382+ }
383+
372384 if ( analysis . needs_mutation_validation ) {
373385 component_block . body . unshift (
374386 b . var ( '$$ownership_validator' , b . call ( '$.create_ownership_validator' , b . id ( '$$props' ) ) )
375387 ) ;
376388 }
377389
390+ if ( ! analysis . runes && analysis . needs_context ) {
391+ component_block . body . push ( b . stmt ( b . call ( '$.init' , analysis . immutable ? b . true : undefined ) ) ) ;
392+ }
393+
378394 const should_inject_context =
379395 dev ||
380396 analysis . needs_context ||
@@ -389,52 +405,6 @@ export function client_component(analysis, options) {
389405 analysis . uses_slots ||
390406 analysis . slot_names . size > 0 ;
391407
392- if ( analysis . instance . has_await ) {
393- const params = [ b . id ( '$$anchor' ) ] ;
394- if ( should_inject_props ) {
395- params . push ( b . id ( '$$props' ) ) ;
396- }
397- if ( store_setup . length > 0 ) {
398- params . push ( b . id ( '$$stores' ) ) ;
399- }
400- const body = b . function_declaration (
401- b . id ( '$$body' ) ,
402- params ,
403- b . block ( [
404- b . var ( '$$unsuspend' , b . call ( '$.suspend' ) ) ,
405- b . var ( '$$active' , b . id ( '$.active_effect' ) ) ,
406- b . try_catch (
407- b . block ( [
408- ...component_block . body ,
409- b . if ( b . call ( '$.aborted' ) , b . return ( ) ) ,
410- .../** @type {ESTree.Statement[] } */ ( template . body )
411- ] ) ,
412- b . block ( [
413- b . if (
414- b . unary ( '!' , b . call ( '$.aborted' , b . id ( '$$active' ) ) ) ,
415- b . stmt ( b . call ( '$.invoke_error_boundary' , b . id ( '$$error' ) , b . id ( '$$active' ) ) )
416- )
417- ] )
418- ) ,
419- b . stmt ( b . call ( '$$unsuspend' ) )
420- ] ) ,
421- true
422- ) ;
423-
424- state . hoisted . push ( body ) ;
425-
426- component_block = b . block ( [
427- b . var ( 'fragment' , b . call ( '$.comment' ) ) ,
428- b . var ( 'node' , b . call ( '$.first_child' , b . id ( 'fragment' ) ) ) ,
429- store_init ,
430- b . stmt ( b . call ( body . id , b . id ( 'node' ) , ...params . slice ( 1 ) ) ) ,
431- b . stmt ( b . call ( '$.append' , b . id ( '$$anchor' ) , b . id ( 'fragment' ) ) )
432- ] ) ;
433- } else {
434- component_block . body . unshift ( store_init ) ;
435- component_block . body . push ( .../** @type {ESTree.Statement[] } */ ( template . body ) ) ;
436- }
437-
438408 // trick esrap into including comments
439409 component_block . loc = instance . loc ;
440410
0 commit comments