Skip to content

Commit 9905a6b

Browse files
committed
fix: correctly transform {@const foo = await ...}
1 parent ce4a99e commit 9905a6b

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

.changeset/fluffy-ducks-happen.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: correctly transform `{@const foo = await ...}`

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/** @import { AST } from '#compiler' */
33
/** @import { ComponentContext } from '../types' */
44
import { dev } from '../../../../state.js';
5-
import { extract_identifiers } from '../../../../utils/ast.js';
5+
import { extract_identifiers, is_expression_async } from '../../../../utils/ast.js';
66
import * as b from '#compiler/builders';
77
import { create_derived } from '../utils.js';
88
import { get_value } from './shared/declarations.js';
@@ -17,7 +17,7 @@ export function ConstTag(node, context) {
1717
// TODO we can almost certainly share some code with $derived(...)
1818
if (declaration.id.type === 'Identifier') {
1919
const init = build_expression(context, declaration.init, node.metadata.expression);
20-
let expression = create_derived(context.state, b.thunk(init));
20+
let expression = create_derived(context.state, b.thunk(init, is_expression_async(init)));
2121

2222
if (dev) {
2323
expression = b.call('$.tag', expression, b.literal(declaration.id.name));
@@ -58,7 +58,8 @@ export function ConstTag(node, context) {
5858
b.block([
5959
b.const(/** @type {Pattern} */ (context.visit(declaration.id, child_state)), init),
6060
b.return(b.object(identifiers.map((node) => b.prop('init', node, node))))
61-
])
61+
]),
62+
is_expression_async(init)
6263
);
6364

6465
let expression = create_derived(context.state, fn);

0 commit comments

Comments
 (0)