Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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/green-cloths-happen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: array destructuring after await
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ export function transform_body(instance_body, runner, transform) {
);

const statements = visited.declarations.map((node) => {
if (node.id.type === 'Identifier' && node.id.name.startsWith('$$d')) {
if (
node.id.type === 'Identifier' &&
(node.id.name.startsWith('$$d') || node.id.name.startsWith('$$array'))
) {
// this is an intermediate declaration created in VariableDeclaration.js;
// subsequent statements depend on it
return b.var(node.id, node.init);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script>
let count = $state(1);
let arr = $state([1,2]);

// More complex init
let { squared, cubed } = $derived(await {
Expand All @@ -8,10 +9,14 @@
});
// Simple init with multiple destructurings after await
let { toFixed, toString } = $derived(count);

// Simple init with array destructurings after await
let [a, b] = $derived(arr);
</script>

<button onclick={() => count++}>increment</button>

<p>{count} ** 2 = {squared}</p>
<p>{count} ** 3 = {cubed}</p>
<p>{typeof toFixed} {typeof toString}</p>
<p>{a} {b}</p>
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default test({
<p>1 ** 2 = 1</p>
<p>1 ** 3 = 1</p>
<p>function function</p>
<p>1 2</p>
`
);

Expand All @@ -27,6 +28,7 @@ export default test({
<p>2 ** 2 = 4</p>
<p>2 ** 3 = 8</p>
<p>function function</p>
<p>1 2</p>
`
);
}
Expand Down
Loading