Skip to content

Commit 5d1ffcf

Browse files
authored
fix: allow await in if block consequent and alternate (#16890)
Closes #16885
1 parent 303750a commit 5d1ffcf

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

.changeset/kind-tigers-retire.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: allow await in if block consequent and alternate

packages/svelte/src/compiler/phases/3-transform/server/visitors/IfBlock.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ export function IfBlock(node, context) {
2323
/** @type {Statement} */
2424
let statement = b.if(test, consequent, alternate);
2525

26-
if (node.metadata.expression.has_await) {
26+
if (
27+
node.metadata.expression.has_await ||
28+
node.consequent.metadata.has_await ||
29+
node.alternate?.metadata.has_await
30+
) {
2731
statement = create_async_block(b.block([statement]));
2832
}
2933

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{#if false}
2+
{@const one = await 1}
3+
{one}
4+
{:else if false}
5+
{@const two = await 2}
6+
{two}
7+
{:else}
8+
{@const three = await 3}
9+
{three}
10+
{/if}

0 commit comments

Comments
 (0)