Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/chatty-windows-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: ensure snippet hoisting works in the correct scope
6 changes: 1 addition & 5 deletions packages/svelte/src/compiler/phases/scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -628,12 +628,8 @@ export function create_scopes(ast, root, allow_reactive_declarations, parent) {

SnippetBlock(node, context) {
const state = context.state;
// Special-case for root-level snippets: they become part of the instance scope
const is_top_level = !context.path.at(-2);
let scope = state.scope;
if (is_top_level) {
scope = /** @type {Scope} */ (parent);
}

scope.declare(node.expression, 'normal', 'function', node);

const child_scope = state.scope.child();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { test } from '../../test';

export default test({
html: 'a'
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<script>
let abc = 'a'
</script>

{@render b()}

{#snippet a()}
{abc}
{/snippet}

{#snippet b()}
{@render a()}
{/snippet}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ import "svelte/internal/disclose-version";
import * as $ from "svelte/internal/client";
import TextInput from './Child.svelte';

const snippet = ($$anchor) => {
$.next();
var root = $.template(`<!> `, 1);

var text = $.text("Something");
export default function Bind_component_snippet($$anchor) {
const snippet = ($$anchor) => {
$.next();

$.append($$anchor, text);
};
var text = $.text("Something");

var root = $.template(`<!> `, 1);
$.append($$anchor, text);
};

export default function Bind_component_snippet($$anchor) {
let value = $.state('');
const _snippet = snippet;
var fragment = root();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import * as $ from "svelte/internal/server";
import TextInput from './Child.svelte';

function snippet($$payload) {
$$payload.out += `<!---->Something`;
}

export default function Bind_component_snippet($$payload) {
let value = '';
const _snippet = snippet;

function snippet($$payload) {
$$payload.out += `<!---->Something`;
}

let $$settled = true;
let $$inner_payload;

Expand Down
Loading