Skip to content

Commit ff522e2

Browse files
committed
fix: allow await expressions inside {#await ...} argument
1 parent 9945205 commit ff522e2

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

.changeset/long-roses-train.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 expressions inside `{#await ...}` argument

packages/svelte/src/compiler/phases/3-transform/client/visitors/AwaitBlock.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/** @import { BlockStatement, Pattern, Statement } from 'estree' */
22
/** @import { AST } from '#compiler' */
33
/** @import { ComponentClientTransformState, ComponentContext } from '../types' */
4-
import { extract_identifiers } from '../../../../utils/ast.js';
4+
import { extract_identifiers, is_expression_async } from '../../../../utils/ast.js';
55
import * as b from '#compiler/builders';
66
import { create_derived } from '../utils.js';
77
import { get_value } from './shared/declarations.js';
@@ -15,7 +15,11 @@ export function AwaitBlock(node, context) {
1515
context.state.template.push_comment();
1616

1717
// Visit {#await <expression>} first to ensure that scopes are in the correct order
18-
const expression = b.thunk(build_expression(context, node.expression, node.metadata.expression));
18+
const unthunked = build_expression(context, node.expression, node.metadata.expression);
19+
const expression = b.thunk(
20+
unthunked,
21+
context.state.options.experimental.async && is_expression_async(unthunked)
22+
);
1923

2024
let then_block;
2125
let catch_block;

0 commit comments

Comments
 (0)