@ -52,6 +52,15 @@ export function build_component(node, component_name, context) {
/** @type {ExpressionStatement[]} */
/** @type {ExpressionStatement[]} */
const binding _initializers = [ ] ;
const binding _initializers = [ ] ;
const is _component _dynamic =
node . type === 'SvelteComponent' || ( node . type === 'Component' && node . metadata . dynamic ) ;
// The variable name used for the component inside $.component()
const intermediate _name =
node . type === 'Component' && node . metadata . dynamic
? context . state . scope . generate ( node . name )
: '$$component' ;
/ * *
/ * *
* If this component has a slot property , it is a named slot within another component . In this case
* If this component has a slot property , it is a named slot within another component . In this case
* the slot scope applies to the component itself , too , and not just its children .
* the slot scope applies to the component itself , too , and not just its children .
@ -199,7 +208,7 @@ export function build_component(node, component_name, context) {
b . call (
b . call (
'$$ownership_validator.binding' ,
'$$ownership_validator.binding' ,
b . literal ( binding . node . name ) ,
b . literal ( binding . node . name ) ,
b . id ( component_name ) ,
b . id ( is_component _dynamic ? intermediate _name : component_name ) ,
b . thunk ( expression )
b . thunk ( expression )
)
)
)
)
@ -414,8 +423,8 @@ export function build_component(node, component_name, context) {
// TODO We can remove this ternary once we remove legacy mode, since in runes mode dynamic components
// TODO We can remove this ternary once we remove legacy mode, since in runes mode dynamic components
// will be handled separately through the `$.component` function, and then the component name will
// will be handled separately through the `$.component` function, and then the component name will
// always be referenced through just the identifier here.
// always be referenced through just the identifier here.
node. type === 'SvelteComponent' || ( node . type === 'Component' && node . metadata . dynamic )
is_component _dynamic
? component _name
? intermediate _name
: /** @type {Expression} */ ( context . visit ( b . member _id ( component _name ) ) ) ,
: /** @type {Expression} */ ( context . visit ( b . member _id ( component _name ) ) ) ,
node _id ,
node _id ,
props _expression
props _expression
@ -432,7 +441,7 @@ export function build_component(node, component_name, context) {
const statements = [ ... snippet _declarations ] ;
const statements = [ ... snippet _declarations ] ;
if ( node. type === 'SvelteComponent' || ( node . type === 'Component' && node . metadata . dynamic ) ) {
if ( is_component _dynamic ) {
const prev = fn ;
const prev = fn ;
fn = ( node _id ) => {
fn = ( node _id ) => {
@ -441,11 +450,11 @@ export function build_component(node, component_name, context) {
node _id ,
node _id ,
b . thunk (
b . thunk (
/** @type {Expression} */ (
/** @type {Expression} */ (
context . visit ( node . type === 'Component' ? b . member _id ( node. name) : node . expression )
context . visit ( node . type === 'Component' ? b . member _id ( component_ name) : node . expression )
)
)
) ,
) ,
b . arrow (
b . arrow (
[ b . id ( '$$anchor' ) , b . id ( component _name ) ] ,
[ b . id ( '$$anchor' ) , b . id ( intermediate _name ) ] ,
b . block ( [ ... binding _initializers , b . stmt ( prev ( b . id ( '$$anchor' ) ) ) ] )
b . block ( [ ... binding _initializers , b . stmt ( prev ( b . id ( '$$anchor' ) ) ) ] )
)
)
) ;
) ;