fix: visit expression when destructuring state declarations (#16081)

pull/16096/head
Paolo Ricciuti 3 months ago committed by GitHub
parent 370b18f278
commit 8faa178cd7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: visit expression when destructuring state declarations

@ -148,7 +148,7 @@ export function VariableDeclaration(node, context) {
const { inserts, paths } = extract_paths(declarator.id, tmp);
declarations.push(
b.declarator(tmp, value),
b.declarator(tmp, /** @type {Expression} */ (context.visit(value))),
...inserts.map(({ id, value }) => {
id.name = context.state.scope.generate('$$array');
context.state.transform[id.name] = { read: get_value };

@ -0,0 +1,6 @@
<script>
let { data } = $props();
let { foo } = $state(data);
</script>
{foo}

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

@ -0,0 +1,5 @@
<script>
import Child from './Child.svelte';
</script>
<Child data={{ foo: 'bar' }} />
Loading…
Cancel
Save