Skip to content

Commit c52e982

Browse files
committed
fix: migrate default slots to children snippet
1 parent ef205d9 commit c52e982

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

.changeset/five-dingos-push.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: migrate default slots to children snippet

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,6 +1152,10 @@ function migrate_slot_usage(node, path, state) {
11521152
is_text_attribute(attribute)
11531153
) {
11541154
snippet_name = attribute.value[0].data;
1155+
// the default slot in svelte 4 if what the children slot is for svelte 5
1156+
if (snippet_name === 'default') {
1157+
snippet_name = 'children';
1158+
}
11551159
if (!regex_is_valid_identifier.test(snippet_name)) {
11561160
has_migration_task = true;
11571161
state.str.appendLeft(

packages/svelte/tests/migrate/samples/slot-usages/input.svelte

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@
7777
<div slot="bar">bar</div>
7878
</Component>
7979

80+
<Component>
81+
<span slot="default">should be children</span>
82+
</Component>
83+
84+
<Component>
85+
<span slot="default" let:with_prop>should be children {with_prop} too</span>
86+
</Component>
87+
8088
<c-e>
8189
<div slot="named">unchanged</div>
8290
</c-e>

packages/svelte/tests/migrate/samples/slot-usages/output.svelte

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,16 @@
121121
{/snippet}
122122
</Component>
123123

124+
<Component>
125+
<span >should be children</span>
126+
</Component>
127+
128+
<Component>
129+
<span >{#snippet children({ with_prop })}
130+
should be children {with_prop} too {/snippet}
131+
</span>
132+
</Component>
133+
124134
<c-e>
125135
<div slot="named">unchanged</div>
126136
</c-e>

0 commit comments

Comments
 (0)