Skip to content

Commit 4791832

Browse files
authored
fix: migrate $$slots.default correctly (#13238)
Mentioned in sveltejs/kit#12519 (comment)
1 parent 04df7b0 commit 4791832

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

packages/svelte/src/compiler/migrate/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,9 @@ function handle_identifier(node, state, path) {
927927
} else if (node.name === '$$slots' && state.analysis.uses_slots) {
928928
if (parent?.type === 'MemberExpression') {
929929
state.str.update(/** @type {number} */ (node.start), parent.property.start, '');
930+
if (parent.property.name === 'default') {
931+
state.str.update(parent.property.start, parent.property.end, 'children');
932+
}
930933
}
931934
// else passed as identifier, we don't know what to do here, so let it error
932935
}

packages/svelte/tests/migrate/samples/slots/input.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@
99
<slot name="bar" />
1010
{/if}
1111

12+
{#if $$slots.default}foo{/if}
13+
1214
<slot name="dashed-name" />

packages/svelte/tests/migrate/samples/slots/output.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@
1919
{@render bar?.()}
2020
{/if}
2121

22+
{#if children}foo{/if}
23+
2224
{@render dashed_name?.()}

0 commit comments

Comments
 (0)