fix: allow duplicate snippet declaration names (#9759)

Fixes #9756
pull/9753/head
Dominic Gannaway 1 year ago committed by GitHub
parent ef5bcfe542
commit f0c47c31bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: allow duplicate snippet declaration names

@ -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)));
}

@ -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 });
}

@ -0,0 +1,4 @@
<script>
const {children} = $props();
</script>
<div>{@render children()}</div>

@ -0,0 +1,5 @@
import { test } from '../../test';
export default test({
html: `<div>Hello</div><div>World</div>`
});

@ -0,0 +1,15 @@
<script>
import Child from './Child.svelte';
</script>
<Child>
{#snippet children()}
Hello
{/snippet}
</Child>
<Child>
{#snippet children()}
World
{/snippet}
</Child>
Loading…
Cancel
Save