Skip to content

Commit 0184d57

Browse files
committed
fix: visit expression when destructuring state declarations
1 parent 2342c87 commit 0184d57

File tree

5 files changed

+22
-1
lines changed

5 files changed

+22
-1
lines changed

.changeset/hip-penguins-unite.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: visit expression when destructuring state declarations

packages/svelte/src/compiler/phases/3-transform/client/visitors/VariableDeclaration.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ export function VariableDeclaration(node, context) {
148148
const { inserts, paths } = extract_paths(declarator.id, tmp);
149149

150150
declarations.push(
151-
b.declarator(tmp, value),
151+
b.declarator(tmp, /** @type {Expression} */ (context.visit(value))),
152152
...inserts.map(({ id, value }) => {
153153
id.name = context.state.scope.generate('$$array');
154154
context.state.transform[id.name] = { read: get_value };
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<script>
2+
let { data } = $props();
3+
let { foo } = $state(data);
4+
</script>
5+
6+
{foo}
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: `bar`
5+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<script>
2+
import Child from './Child.svelte';
3+
</script>
4+
5+
<Child data={{ foo: 'bar' }} />

0 commit comments

Comments
 (0)