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/wicked-goats-begin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: generate correct code for `each` blocks with async body
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ export function EachBlock(node, context) {
each.push(b.let(node.index, index));
}

each.push(.../** @type {BlockStatement} */ (context.visit(node.body)).body);
const new_body = /** @type {BlockStatement} */ (context.visit(node.body)).body;

each.push(...(node.body.metadata.has_await ? [create_async_block(b.block(new_body))] : new_body));

const for_loop = b.for(
b.declaration('let', [
Expand All @@ -55,7 +57,7 @@ export function EachBlock(node, context) {
b.if(
b.binary('!==', b.member(array_id, 'length'), b.literal(0)),
b.block([open, for_loop]),
fallback
node.fallback.metadata.has_await ? create_async_block(fallback) : fallback
)
);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { test } from '../../test';

export default test({
mode: ['async']
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!--[--><!--[--><!--[--><!---->each<!--]--><!--]--> <!--[--><!--[!--><!---->else<!--]--><!--]--><!--]-->
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{#each { length: 1 }}
{@const data = await Promise.resolve("each")}
{data}
{/each}

{#each { length: 0 }}
should not see this
{:else}
{@const data = await Promise.resolve("else")}
{data}
{/each}
Loading