fix: ensure migrate correctly handles named slots (#13676)

* fix: ensure migrate correctly handles named slots

* tweak

* fix
pull/13678/head
Dominic Gannaway 2 months ago committed by GitHub
parent c9d85c2d52
commit 61391c8704
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: ensure migrate correctly handles named slots

@ -996,6 +996,10 @@ const template = {
if (attr.type === 'SpreadAttribute') { if (attr.type === 'SpreadAttribute') {
slot_props += `...${state.str.original.substring(/** @type {number} */ (attr.expression.start), attr.expression.end)}, `; slot_props += `...${state.str.original.substring(/** @type {number} */ (attr.expression.start), attr.expression.end)}, `;
} else if (attr.type === 'Attribute') { } else if (attr.type === 'Attribute') {
if (attr.name === 'slot') {
continue;
}
if (attr.name === 'name') { if (attr.name === 'name') {
slot_name = /** @type {any} */ (attr.value)[0].data; slot_name = /** @type {any} */ (attr.value)[0].data;
} else { } else {
@ -1200,7 +1204,13 @@ function migrate_slot_usage(node, path, state) {
[node.end, state.str.original.length] [node.end, state.str.original.length]
] ]
}); });
state.str.appendLeft(node.end, `\n${state.indent.repeat(path.length - 2)}{/snippet}`); const str = `\n${state.indent.repeat(path.length - 2)}{/snippet}`;
if (node.type === 'SlotElement') {
state.str.appendRight(node.end, str);
} else {
state.str.appendLeft(node.end, str);
}
} }
} }

@ -0,0 +1,7 @@
<script lang="ts">
import Component from './Component.svelte';
</script>
<Component>
<slot slot="msg"></slot>
</Component>

@ -0,0 +1,14 @@
<script lang="ts">
import Component from './Component.svelte';
interface Props {
children?: import('svelte').Snippet;
}
let { children }: Props = $props();
</script>
<Component>
{#snippet msg()}
{@render children?.()}
{/snippet}
</Component>
Loading…
Cancel
Save