Skip to content

Commit f0c47c3

Browse files
authored
fix: allow duplicate snippet declaration names (#9759)
Fixes #9756
1 parent ef5bcfe commit f0c47c3

File tree

6 files changed

+31
-2
lines changed

6 files changed

+31
-2
lines changed

.changeset/khaki-moose-arrive.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: allow duplicate snippet declaration names

packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2453,7 +2453,7 @@ export const template_visitors = {
24532453
body = /** @type {import('estree').BlockStatement} */ (context.visit(node.body));
24542454
}
24552455

2456-
context.state.init.push(b.function_declaration(node.expression, args, body));
2456+
context.state.init.push(b.const(node.expression, b.arrow(args, body)));
24572457
if (context.state.options.dev) {
24582458
context.state.init.push(b.stmt(b.call('$.add_snippet_symbol', node.expression)));
24592459
}

packages/svelte/src/compiler/phases/scope.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ export function create_scopes(ast, root, allow_reactive_declarations, parent) {
375375
scopes.set(child, state.scope);
376376
visit(child);
377377
} else if (child.type === 'SnippetBlock') {
378-
visit(child);
378+
visit(child, { scope });
379379
} else {
380380
visit(child, { scope });
381381
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<script>
2+
const {children} = $props();
3+
</script>
4+
<div>{@render children()}</div>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
html: `<div>Hello</div><div>World</div>`
5+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<script>
2+
import Child from './Child.svelte';
3+
</script>
4+
5+
<Child>
6+
{#snippet children()}
7+
Hello
8+
{/snippet}
9+
</Child>
10+
11+
<Child>
12+
{#snippet children()}
13+
World
14+
{/snippet}
15+
</Child>

0 commit comments

Comments
 (0)