@ -359,16 +359,31 @@ export function client_component(analysis, options) {
if ( dev ) push _args . push ( b . id ( analysis . name ) ) ;
let component _block = b . block ( [
store _init ,
... store _setup ,
... legacy _reactive _declarations ,
... group _binding _declarations ,
... state . instance _level _snippets ,
... /** @type {ESTree.Statement[]} */ ( instance . body ) ,
analysis . runes || ! analysis . needs _context
? b . empty
: b . stmt ( b . call ( '$.init' , analysis . immutable ? b . true : undefined ) )
... state . instance _level _snippets
] ) ;
if ( analysis . instance . has _await ) {
const body = b . block ( [
... /** @type {ESTree.Statement[]} */ ( instance . body ) ,
b . if ( b . call ( '$.aborted' ) , b . return ( ) ) ,
... /** @type {ESTree.Statement[]} */ ( template . body )
] ) ;
component _block . body . push ( b . stmt ( b . call ( ` $ .async_body ` , b . arrow ( [ ] , body , true ) ) ) ) ;
} else {
component _block . body . push ( ... /** @type {ESTree.Statement[]} */ ( instance . body ) ) ;
if ( ! analysis . runes && analysis . needs _context ) {
component _block . body . push ( b . stmt ( b . call ( '$.init' , analysis . immutable ? b . true : undefined ) ) ) ;
}
component _block . body . push ( ... /** @type {ESTree.Statement[]} */ ( template . body ) ) ;
}
if ( analysis . needs _mutation _validation ) {
component _block . body . unshift (
b . var ( '$$ownership_validator' , b . call ( '$.create_ownership_validator' , b . id ( '$$props' ) ) )
@ -389,41 +404,6 @@ export function client_component(analysis, options) {
analysis . uses _slots ||
analysis . slot _names . size > 0 ;
if ( analysis . instance . has _await ) {
const params = [ b . id ( '$$anchor' ) ] ;
if ( should _inject _props ) {
params . push ( b . id ( '$$props' ) ) ;
}
if ( store _setup . length > 0 ) {
params . push ( b . id ( '$$stores' ) ) ;
}
const body = b . function _declaration (
b . id ( '$$body' ) ,
params ,
b . block ( [
b . var ( '$$unsuspend' , b . call ( '$.suspend' ) ) ,
... component _block . body ,
b . if ( b . call ( '$.aborted' ) , b . return ( ) ) ,
... /** @type {ESTree.Statement[]} */ ( template . body ) ,
b . stmt ( b . call ( '$$unsuspend' ) )
] ) ,
true
) ;
state . hoisted . push ( body ) ;
component _block = b . block ( [
b . var ( 'fragment' , b . call ( '$.comment' ) ) ,
b . var ( 'node' , b . call ( '$.first_child' , b . id ( 'fragment' ) ) ) ,
store _init ,
b . stmt ( b . call ( body . id , b . id ( 'node' ) , ... params . slice ( 1 ) ) ) ,
b . stmt ( b . call ( '$.append' , b . id ( '$$anchor' ) , b . id ( 'fragment' ) ) )
] ) ;
} else {
component _block . body . unshift ( store _init ) ;
component _block . body . push ( ... /** @type {ESTree.Statement[]} */ ( template . body ) ) ;
}
// trick esrap into including comments
component _block . loc = instance . loc ;