Skip to content

Commit f178788

Browse files
committed
clarify
1 parent 558c39a commit f178788

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,12 @@ function serialize_inline_component(node, component_name, context) {
763763
/** @type {import('estree').Identifier | import('estree').MemberExpression | null} */
764764
let bind_this = null;
765765

766+
/**
767+
* If this component has a slot property, it is a named slot within another component. In this case
768+
* the slot scope applies to the component itself, too, and not just its children.
769+
*/
770+
let slot_scope_applies_to_itself = false;
771+
766772
/**
767773
* @param {import('estree').Property} prop
768774
*/
@@ -775,8 +781,6 @@ function serialize_inline_component(node, component_name, context) {
775781
props_and_spreads.push(props);
776782
}
777783
}
778-
779-
let is_named_parent_slot = false;
780784
for (const attribute of node.attributes) {
781785
if (attribute.type === 'LetDirective') {
782786
lets.push(/** @type {import('estree').ExpressionStatement} */ (context.visit(attribute)));
@@ -811,7 +815,7 @@ function serialize_inline_component(node, component_name, context) {
811815
}
812816

813817
if (attribute.name === 'slot') {
814-
is_named_parent_slot = true;
818+
slot_scope_applies_to_itself = true;
815819
}
816820

817821
const [, value] = serialize_attribute_value(attribute.value, context);
@@ -866,9 +870,7 @@ function serialize_inline_component(node, component_name, context) {
866870
}
867871
}
868872

869-
if (is_named_parent_slot) {
870-
// This component is filling a named slot in its parent component, so get the relevant
871-
// attributes from the parent slot.
873+
if (slot_scope_applies_to_itself) {
872874
context.state.init.push(...lets);
873875
}
874876

@@ -927,7 +929,7 @@ function serialize_inline_component(node, component_name, context) {
927929

928930
const slot_fn = b.arrow(
929931
[b.id('$$anchor'), b.id('$$slotProps')],
930-
b.block([...(slot_name === 'default' && !is_named_parent_slot ? lets : []), ...body])
932+
b.block([...(slot_name === 'default' && !slot_scope_applies_to_itself ? lets : []), ...body])
931933
);
932934

933935
if (slot_name === 'default') {

packages/svelte/src/compiler/phases/3-transform/server/transform-server.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,12 @@ function serialize_inline_component(node, component_name, context) {
813813
/** @type {Record<string, import('#compiler').TemplateNode[]>} */
814814
const children = {};
815815

816+
/**
817+
* If this component has a slot property, it is a named slot within another component. In this case
818+
* the slot scope applies to the component itself, too, and not just its children.
819+
*/
820+
let slot_scope_applies_to_itself = false;
821+
816822
/**
817823
* @param {import('estree').Property} prop
818824
*/
@@ -825,8 +831,6 @@ function serialize_inline_component(node, component_name, context) {
825831
props_and_spreads.push(props);
826832
}
827833
}
828-
829-
let is_named_parent_slot = false;
830834
for (const attribute of node.attributes) {
831835
if (attribute.type === 'LetDirective') {
832836
lets.push(/** @type {import('estree').ExpressionStatement} */ (context.visit(attribute)));
@@ -840,7 +844,7 @@ function serialize_inline_component(node, component_name, context) {
840844
}
841845

842846
if (attribute.name === 'slot') {
843-
is_named_parent_slot = true;
847+
slot_scope_applies_to_itself = true;
844848
}
845849

846850
const value = serialize_attribute_value(attribute.value, context, false, true);
@@ -865,9 +869,7 @@ function serialize_inline_component(node, component_name, context) {
865869
}
866870
}
867871

868-
if (is_named_parent_slot) {
869-
// This component is filling a named slot in its parent component, so get the relevant
870-
// attributes from the parent slot.
872+
if (slot_scope_applies_to_itself) {
871873
context.state.init.push(...lets);
872874
}
873875

@@ -916,7 +918,7 @@ function serialize_inline_component(node, component_name, context) {
916918

917919
const slot_fn = b.arrow(
918920
[b.id('$$payload'), b.id('$$slotProps')],
919-
b.block([...(slot_name === 'default' && !is_named_parent_slot ? lets : []), ...body])
921+
b.block([...(slot_name === 'default' && !slot_scope_applies_to_itself ? lets : []), ...body])
920922
);
921923

922924
if (slot_name === 'default') {

0 commit comments

Comments
 (0)