fix: apply correct snippet scope (#9623)

pull/9607/head
Dominic Gannaway 1 year ago committed by GitHub
parent 509f92d29e
commit d8d9be39d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: ensure snippets have correct scope

@ -557,6 +557,7 @@ export function create_scopes(ast, root, allow_reactive_declarations, parent) {
}, },
SnippetBlock(node, context) { SnippetBlock(node, context) {
const state = context.state;
// Special-case for root-level snippets: they become part of the instance scope // Special-case for root-level snippets: they become part of the instance scope
const is_top_level = !context.path.at(-2); const is_top_level = !context.path.at(-2);
let scope = state.scope; let scope = state.scope;

@ -0,0 +1,7 @@
<script>
let { inner } = $props();
</script>
{#if inner}
{@render inner()}
{/if}

@ -0,0 +1,5 @@
import { test } from '../../test';
export default test({
html: `<p>S</p><a href="#">S</a><p>v</p><a href="#">v</a><p>e</p><a href="#">e</a><p>l</p><a href="#">l</a><p>t</p><a href="#">t</a><p>e</p><a href="#">e</a>`
});

@ -0,0 +1,13 @@
<script>
import Component from './Component.svelte';
let name = "Svelte";
</script>
{#each name.split('') as character}
<p>{character}</p>
<Component>
{#snippet inner()}
<a href={'#'}>{character}</a>
{/snippet}
</Component>
{/each}
Loading…
Cancel
Save