fix: destructuring snippet arguments (#16068)

pull/16064/head
Paolo Ricciuti 3 months ago committed by GitHub
parent b851b54e9d
commit 1b5f6af276
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: destructuring snippet arguments

@ -57,7 +57,7 @@ export function SnippetBlock(node, context) {
for (const path of paths) { for (const path of paths) {
const name = /** @type {Identifier} */ (path.node).name; const name = /** @type {Identifier} */ (path.node).name;
const needs_derived = path.has_default_value; // to ensure that default value is only called once 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)); declarations.push(b.let(path.node, needs_derived ? b.call('$.derived_safe_equal', fn) : fn));

@ -0,0 +1,5 @@
import { test } from '../../test';
export default test({
html: `a`
});

@ -0,0 +1,9 @@
<script>
let array = $state(['a', 'b', 'c'])
</script>
{#snippet content([x])}
{x}
{/snippet}
{@render content(array)}
Loading…
Cancel
Save