From c52e9827a6893f034fc259f66530071795bd97dd Mon Sep 17 00:00:00 2001 From: paoloricciuti Date: Mon, 21 Oct 2024 22:04:13 +0200 Subject: [PATCH] fix: migrate default slots to children snippet --- .changeset/five-dingos-push.md | 5 +++++ packages/svelte/src/compiler/migrate/index.js | 4 ++++ .../tests/migrate/samples/slot-usages/input.svelte | 8 ++++++++ .../tests/migrate/samples/slot-usages/output.svelte | 10 ++++++++++ 4 files changed, 27 insertions(+) create mode 100644 .changeset/five-dingos-push.md diff --git a/.changeset/five-dingos-push.md b/.changeset/five-dingos-push.md new file mode 100644 index 000000000000..f359f0a9fee3 --- /dev/null +++ b/.changeset/five-dingos-push.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: migrate default slots to children snippet diff --git a/packages/svelte/src/compiler/migrate/index.js b/packages/svelte/src/compiler/migrate/index.js index 33a369b8c83a..c95b0734f97a 100644 --- a/packages/svelte/src/compiler/migrate/index.js +++ b/packages/svelte/src/compiler/migrate/index.js @@ -1152,6 +1152,10 @@ function migrate_slot_usage(node, path, state) { is_text_attribute(attribute) ) { snippet_name = attribute.value[0].data; + // the default slot in svelte 4 if what the children slot is for svelte 5 + if (snippet_name === 'default') { + snippet_name = 'children'; + } if (!regex_is_valid_identifier.test(snippet_name)) { has_migration_task = true; state.str.appendLeft( diff --git a/packages/svelte/tests/migrate/samples/slot-usages/input.svelte b/packages/svelte/tests/migrate/samples/slot-usages/input.svelte index 5646174c4c64..248ff0ac1312 100644 --- a/packages/svelte/tests/migrate/samples/slot-usages/input.svelte +++ b/packages/svelte/tests/migrate/samples/slot-usages/input.svelte @@ -77,6 +77,14 @@
bar
+ + should be children + + + + should be children {with_prop} too + +
unchanged
diff --git a/packages/svelte/tests/migrate/samples/slot-usages/output.svelte b/packages/svelte/tests/migrate/samples/slot-usages/output.svelte index 42e219a567f8..d2aea33c83ec 100644 --- a/packages/svelte/tests/migrate/samples/slot-usages/output.svelte +++ b/packages/svelte/tests/migrate/samples/slot-usages/output.svelte @@ -121,6 +121,16 @@ {/snippet} + + should be children + + + + {#snippet children({ with_prop })} + should be children {with_prop} too {/snippet} + + +
unchanged
\ No newline at end of file