diff --git a/.changeset/khaki-moose-arrive.md b/.changeset/khaki-moose-arrive.md new file mode 100644 index 0000000000..5e78822226 --- /dev/null +++ b/.changeset/khaki-moose-arrive.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: allow duplicate snippet declaration names diff --git a/packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js b/packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js index ef281d3197..e619f25247 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js @@ -2453,7 +2453,7 @@ export const template_visitors = { body = /** @type {import('estree').BlockStatement} */ (context.visit(node.body)); } - context.state.init.push(b.function_declaration(node.expression, args, body)); + context.state.init.push(b.const(node.expression, b.arrow(args, body))); if (context.state.options.dev) { context.state.init.push(b.stmt(b.call('$.add_snippet_symbol', node.expression))); } diff --git a/packages/svelte/src/compiler/phases/scope.js b/packages/svelte/src/compiler/phases/scope.js index e8e56bfe78..60e29e61cb 100644 --- a/packages/svelte/src/compiler/phases/scope.js +++ b/packages/svelte/src/compiler/phases/scope.js @@ -375,7 +375,7 @@ export function create_scopes(ast, root, allow_reactive_declarations, parent) { scopes.set(child, state.scope); visit(child); } else if (child.type === 'SnippetBlock') { - visit(child); + visit(child, { scope }); } else { visit(child, { scope }); } diff --git a/packages/svelte/tests/runtime-runes/samples/snippet-duplicate-children/Child.svelte b/packages/svelte/tests/runtime-runes/samples/snippet-duplicate-children/Child.svelte new file mode 100644 index 0000000000..441f7f5ee4 --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/snippet-duplicate-children/Child.svelte @@ -0,0 +1,4 @@ + +