Skip to content

Commit e108e1a

Browse files
committed
fix: $$props messing with $$slots
1 parent faa5f74 commit e108e1a

File tree

3 files changed

+61
-4
lines changed

3 files changed

+61
-4
lines changed

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -741,11 +741,15 @@ const template = {
741741
state.str.update(
742742
node.start,
743743
node.fragment.nodes[0].start,
744-
`{#if ${name}}{@render ${name}(${slot_props})}{:else}`
744+
`{#if ${name}}{@render ${state.analysis.uses_props ? `${state.names.props}.` : ''}${name}(${slot_props})}{:else}`
745745
);
746746
state.str.update(node.fragment.nodes[node.fragment.nodes.length - 1].end, node.end, '{/if}');
747747
} else {
748-
state.str.update(node.start, node.end, `{@render ${name}?.(${slot_props})}`);
748+
state.str.update(
749+
node.start,
750+
node.end,
751+
`{@render ${state.analysis.uses_props ? `${state.names.props}.` : ''}${name}?.(${slot_props})}`
752+
);
749753
}
750754
},
751755
Comment(node, { state }) {
@@ -939,7 +943,9 @@ function handle_identifier(node, state, path) {
939943
const parent = path.at(-1);
940944
if (parent?.type === 'MemberExpression' && parent.property === node) return;
941945

942-
if (state.analysis.uses_props) {
946+
console.log(node);
947+
948+
if (state.analysis.uses_props && node.name !== '$$slots') {
943949
if (node.name === '$$props' || node.name === '$$restProps') {
944950
// not 100% correct for $$restProps but it'll do
945951
state.str.update(
@@ -991,7 +997,11 @@ function handle_identifier(node, state, path) {
991997
});
992998
}
993999

994-
state.str.update(/** @type {number} */ (node.start), parent.property.start, '');
1000+
state.str.update(
1001+
/** @type {number} */ (node.start),
1002+
parent.property.start,
1003+
state.analysis.uses_props ? `${state.names.props}.` : ''
1004+
);
9951005
state.str.update(parent.property.start, parent.end, name);
9961006
}
9971007
// else passed as identifier, we don't know what to do here, so let it error
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<button><slot /></button>
2+
3+
{#if foo}
4+
<slot name="foo" {foo} />
5+
{/if}
6+
7+
{#if $$slots.bar}
8+
{$$slots}
9+
<slot name="bar" />
10+
{/if}
11+
12+
{#if $$slots.default}foo{/if}
13+
14+
{#if $$slots['default']}foo{/if}
15+
16+
{#if $$slots['dashed-name']}foo{/if}
17+
18+
<slot name="dashed-name" />
19+
20+
<slot header="something" title={$$props.cool} {id} />
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<script>
2+
/** @type {Record<string, any>} */
3+
let {
4+
...props
5+
} = $props();
6+
</script>
7+
8+
<button>{@render props.children?.()}</button>
9+
10+
{#if foo}
11+
{@render props.foo_1?.({ foo, })}
12+
{/if}
13+
14+
{#if props.bar}
15+
{$$slots}
16+
{@render props.bar?.()}
17+
{/if}
18+
19+
{#if props.children}foo{/if}
20+
21+
{#if props.children}foo{/if}
22+
23+
{#if props.dashed_name}foo{/if}
24+
25+
{@render props.dashed_name?.()}
26+
27+
{@render props.children?.({ header: "something", title: props.cool, id, })}

0 commit comments

Comments
 (0)