Skip to content

Commit ae60046

Browse files
fix: array destructuring after await (#17254)
1 parent 5c821c1 commit ae60046

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

.changeset/green-cloths-happen.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: array destructuring after await

packages/svelte/src/compiler/phases/3-transform/shared/transform-async.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ export function transform_body(instance_body, runner, transform) {
5454
);
5555

5656
const statements = visited.declarations.map((node) => {
57-
if (node.id.type === 'Identifier' && node.id.name.startsWith('$$d')) {
57+
if (
58+
node.id.type === 'Identifier' &&
59+
(node.id.name.startsWith('$$d') || node.id.name.startsWith('$$array'))
60+
) {
5861
// this is an intermediate declaration created in VariableDeclaration.js;
5962
// subsequent statements depend on it
6063
return b.var(node.id, node.init);

packages/svelte/tests/runtime-runes/samples/async-derived-destructured/Child.svelte

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script>
22
let count = $state(1);
3+
let arr = $state([1,2]);
34
45
// More complex init
56
let { squared, cubed } = $derived(await {
@@ -8,10 +9,14 @@
89
});
910
// Simple init with multiple destructurings after await
1011
let { toFixed, toString } = $derived(count);
12+
13+
// Simple init with array destructurings after await
14+
let [a, b] = $derived(arr);
1115
</script>
1216

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

1519
<p>{count} ** 2 = {squared}</p>
1620
<p>{count} ** 3 = {cubed}</p>
1721
<p>{typeof toFixed} {typeof toString}</p>
22+
<p>{a} {b}</p>

packages/svelte/tests/runtime-runes/samples/async-derived-destructured/_config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export default test({
1414
<p>1 ** 2 = 1</p>
1515
<p>1 ** 3 = 1</p>
1616
<p>function function</p>
17+
<p>1 2</p>
1718
`
1819
);
1920

@@ -27,6 +28,7 @@ export default test({
2728
<p>2 ** 2 = 4</p>
2829
<p>2 ** 3 = 8</p>
2930
<p>function function</p>
31+
<p>1 2</p>
3032
`
3133
);
3234
}

0 commit comments

Comments
 (0)