fix: account for shadowing children slot during migration (#14224)

Fixes #14171
pull/14227/head
Paolo Ricciuti 10 months ago committed by GitHub
parent 31e6bbb646
commit f0c2d4c698
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: account for shadowing children slot during migration

@ -1300,6 +1300,21 @@ const template = {
existing_prop.needs_refine_type = false;
}
if (
slot_name === 'default' &&
path.some(
(parent) =>
(parent.type === 'SvelteComponent' ||
parent.type === 'Component' ||
parent.type === 'RegularElement' ||
parent.type === 'SvelteElement' ||
parent.type === 'SvelteFragment') &&
parent.attributes.some((attr) => (attr.type = 'LetDirective'))
)
) {
aliased_slot_name = `${name}_render`;
state.derived_conflicting_slots.set(aliased_slot_name, name);
}
name = aliased_slot_name ?? name;
if (node.fragment.nodes.length > 0) {

@ -12,4 +12,14 @@
</div>
</MyComponent>
</div>
</MyInput>
<MyInput let:args>
<slot/>
</MyInput>
<MyInput>
<div let:args>
<slot/>
</div>
</MyInput>

@ -2,11 +2,13 @@
/**
* @typedef {Object} Props
* @property {import('svelte').Snippet} [label]
* @property {import('svelte').Snippet} [children]
*/
/** @type {Props} */
let { label } = $props();
let { label, children } = $props();
const label_render = $derived(label);
const children_render = $derived(children);
</script>
@ -30,4 +32,18 @@
</MyComponent>
</div>
{/snippet}
</MyInput>
<MyInput >
{#snippet children({ args })}
{@render children_render?.()}
{/snippet}
</MyInput>
<MyInput>
<div >
{#snippet children({ args })}
{@render children_render?.()}
{/snippet}
</div>
</MyInput>
Loading…
Cancel
Save