Skip to content
Open
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/kind-tigers-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: allow await in if block consequent and alternate
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ export function IfBlock(node, context) {
/** @type {Statement} */
let statement = b.if(test, consequent, alternate);

if (node.metadata.expression.has_await) {
if (
node.metadata.expression.has_await ||
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my understanding, node.metadata.expression.has_await checks {#if await Promise.resolve(true)}.

So it doesn't return true when only consequent or alternate have await operator.

node.consequent.metadata.has_await ||
node.alternate?.metadata.has_await
) {
statement = create_async_block(b.block([statement]));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{#if false}
{@const one = await 1}
{one}
{:else if false}
{@const two = await 2}
{two}
{:else}
{@const three = await 3}
{three}
{/if}
Loading