diff --git a/.changeset/violet-actors-teach.md b/.changeset/violet-actors-teach.md new file mode 100644 index 0000000000..39ce420226 --- /dev/null +++ b/.changeset/violet-actors-teach.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: destructuring snippet arguments diff --git a/packages/svelte/src/compiler/phases/3-transform/client/visitors/SnippetBlock.js b/packages/svelte/src/compiler/phases/3-transform/client/visitors/SnippetBlock.js index 0809aa21b2..203cf62b37 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/visitors/SnippetBlock.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/visitors/SnippetBlock.js @@ -57,7 +57,7 @@ export function SnippetBlock(node, context) { for (const path of paths) { const name = /** @type {Identifier} */ (path.node).name; const needs_derived = path.has_default_value; // to ensure that default value is only called once - const fn = b.thunk(/** @type {Expression} */ (context.visit(path.expression))); + const fn = b.thunk(/** @type {Expression} */ (context.visit(path.expression, child_state))); declarations.push(b.let(path.node, needs_derived ? b.call('$.derived_safe_equal', fn) : fn)); diff --git a/packages/svelte/tests/runtime-runes/samples/snippet-destructure-array/_config.js b/packages/svelte/tests/runtime-runes/samples/snippet-destructure-array/_config.js new file mode 100644 index 0000000000..05e3e80b79 --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/snippet-destructure-array/_config.js @@ -0,0 +1,5 @@ +import { test } from '../../test'; + +export default test({ + html: `a` +}); diff --git a/packages/svelte/tests/runtime-runes/samples/snippet-destructure-array/main.svelte b/packages/svelte/tests/runtime-runes/samples/snippet-destructure-array/main.svelte new file mode 100644 index 0000000000..37345c629e --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/snippet-destructure-array/main.svelte @@ -0,0 +1,9 @@ + + +{#snippet content([x])} + {x} +{/snippet} + +{@render content(array)} \ No newline at end of file