Skip to content

Commit d8d9be3

Browse files
authored
fix: apply correct snippet scope (#9623)
1 parent 509f92d commit d8d9be3

File tree

5 files changed

+31
-0
lines changed

5 files changed

+31
-0
lines changed

.changeset/serious-zebras-scream.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: ensure snippets have correct scope

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,7 @@ export function create_scopes(ast, root, allow_reactive_declarations, parent) {
557557
},
558558

559559
SnippetBlock(node, context) {
560+
const state = context.state;
560561
// Special-case for root-level snippets: they become part of the instance scope
561562
const is_top_level = !context.path.at(-2);
562563
let scope = state.scope;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script>
2+
let { inner } = $props();
3+
</script>
4+
5+
{#if inner}
6+
{@render inner()}
7+
{/if}
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: `<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>`
5+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<script>
2+
import Component from './Component.svelte';
3+
let name = "Svelte";
4+
</script>
5+
6+
{#each name.split('') as character}
7+
<p>{character}</p>
8+
<Component>
9+
{#snippet inner()}
10+
<a href={'#'}>{character}</a>
11+
{/snippet}
12+
</Component>
13+
{/each}

0 commit comments

Comments
 (0)