|
|
|
@ -749,7 +749,7 @@ function serialize_inline_component(node, component_name, context) {
|
|
|
|
|
const props_and_spreads = [];
|
|
|
|
|
|
|
|
|
|
/** @type {import('estree').ExpressionStatement[]} */
|
|
|
|
|
const default_lets = [];
|
|
|
|
|
const lets = [];
|
|
|
|
|
|
|
|
|
|
/** @type {Record<string, import('#compiler').TemplateNode[]>} */
|
|
|
|
|
const children = {};
|
|
|
|
@ -763,6 +763,12 @@ function serialize_inline_component(node, component_name, context) {
|
|
|
|
|
/** @type {import('estree').Identifier | import('estree').MemberExpression | null} */
|
|
|
|
|
let bind_this = null;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
let slot_scope_applies_to_itself = false;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param {import('estree').Property} prop
|
|
|
|
|
*/
|
|
|
|
@ -775,12 +781,9 @@ function serialize_inline_component(node, component_name, context) {
|
|
|
|
|
props_and_spreads.push(props);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const attribute of node.attributes) {
|
|
|
|
|
if (attribute.type === 'LetDirective') {
|
|
|
|
|
default_lets.push(
|
|
|
|
|
/** @type {import('estree').ExpressionStatement} */ (context.visit(attribute))
|
|
|
|
|
);
|
|
|
|
|
lets.push(/** @type {import('estree').ExpressionStatement} */ (context.visit(attribute)));
|
|
|
|
|
} else if (attribute.type === 'OnDirective') {
|
|
|
|
|
events[attribute.name] ||= [];
|
|
|
|
|
let handler = serialize_event_handler(attribute, context);
|
|
|
|
@ -811,6 +814,10 @@ function serialize_inline_component(node, component_name, context) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (attribute.name === 'slot') {
|
|
|
|
|
slot_scope_applies_to_itself = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const [, value] = serialize_attribute_value(attribute.value, context);
|
|
|
|
|
|
|
|
|
|
if (attribute.metadata.dynamic) {
|
|
|
|
@ -863,6 +870,10 @@ function serialize_inline_component(node, component_name, context) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (slot_scope_applies_to_itself) {
|
|
|
|
|
context.state.init.push(...lets);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Object.keys(events).length > 0) {
|
|
|
|
|
const events_expression = b.object(
|
|
|
|
|
Object.keys(events).map((name) =>
|
|
|
|
@ -918,7 +929,7 @@ function serialize_inline_component(node, component_name, context) {
|
|
|
|
|
|
|
|
|
|
const slot_fn = b.arrow(
|
|
|
|
|
[b.id('$$anchor'), b.id('$$slotProps')],
|
|
|
|
|
b.block([...(slot_name === 'default' ? default_lets : []), ...body])
|
|
|
|
|
b.block([...(slot_name === 'default' && !slot_scope_applies_to_itself ? lets : []), ...body])
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (slot_name === 'default') {
|
|
|
|
|