From d0c0f1cc238e22bd4bea329c48d77112bb431dc7 Mon Sep 17 00:00:00 2001 From: paoloricciuti Date: Wed, 26 Nov 2025 20:11:45 +0100 Subject: [PATCH] fix: array destructuring after await --- .changeset/green-cloths-happen.md | 5 +++++ .../compiler/phases/3-transform/shared/transform-async.js | 5 ++++- .../samples/async-derived-destructured/Child.svelte | 5 +++++ .../samples/async-derived-destructured/_config.js | 2 ++ 4 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 .changeset/green-cloths-happen.md diff --git a/.changeset/green-cloths-happen.md b/.changeset/green-cloths-happen.md new file mode 100644 index 000000000000..a9677c8fc16a --- /dev/null +++ b/.changeset/green-cloths-happen.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: array destructuring after await diff --git a/packages/svelte/src/compiler/phases/3-transform/shared/transform-async.js b/packages/svelte/src/compiler/phases/3-transform/shared/transform-async.js index b55356a38c39..2b9c219d7d60 100644 --- a/packages/svelte/src/compiler/phases/3-transform/shared/transform-async.js +++ b/packages/svelte/src/compiler/phases/3-transform/shared/transform-async.js @@ -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); diff --git a/packages/svelte/tests/runtime-runes/samples/async-derived-destructured/Child.svelte b/packages/svelte/tests/runtime-runes/samples/async-derived-destructured/Child.svelte index fdf7184e3c87..04adc8e97f48 100644 --- a/packages/svelte/tests/runtime-runes/samples/async-derived-destructured/Child.svelte +++ b/packages/svelte/tests/runtime-runes/samples/async-derived-destructured/Child.svelte @@ -1,5 +1,6 @@ @@ -15,3 +19,4 @@

{count} ** 2 = {squared}

{count} ** 3 = {cubed}

{typeof toFixed} {typeof toString}

+

{a} {b}

\ No newline at end of file diff --git a/packages/svelte/tests/runtime-runes/samples/async-derived-destructured/_config.js b/packages/svelte/tests/runtime-runes/samples/async-derived-destructured/_config.js index bfd582ea9719..26f1dfdeb342 100644 --- a/packages/svelte/tests/runtime-runes/samples/async-derived-destructured/_config.js +++ b/packages/svelte/tests/runtime-runes/samples/async-derived-destructured/_config.js @@ -14,6 +14,7 @@ export default test({

1 ** 2 = 1

1 ** 3 = 1

function function

+

1 2

` ); @@ -27,6 +28,7 @@ export default test({

2 ** 2 = 4

2 ** 3 = 8

function function

+

1 2

` ); }