fix: allow `await` in `{@const }` in more blocks

pull/16568/head
ComputerGuy 1 month ago
parent 97f263c3d4
commit 0ce79c24b1

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: allow `await` in `{@const }` in more blocks

@ -37,7 +37,11 @@ export function AwaitBlock(node, context) {
const declarations = argument?.declarations ?? []; const declarations = argument?.declarations ?? [];
const block = /** @type {BlockStatement} */ (then_context.visit(node.then, then_context.state)); const block = /** @type {BlockStatement} */ (then_context.visit(node.then, then_context.state));
then_block = b.arrow(args, b.block([...declarations, ...block.body])); then_block = b.arrow(
args,
b.block([...declarations, ...block.body]),
node.then.metadata.has_await
);
} }
if (node.catch) { if (node.catch) {
@ -53,7 +57,11 @@ export function AwaitBlock(node, context) {
catch_context.visit(node.catch, catch_context.state) catch_context.visit(node.catch, catch_context.state)
); );
catch_block = b.arrow(args, b.block([...declarations, ...block.body])); catch_block = b.arrow(
args,
b.block([...declarations, ...block.body]),
node.catch.metadata.has_await
);
} }
context.state.init.push( context.state.init.push(
@ -63,7 +71,11 @@ export function AwaitBlock(node, context) {
context.state.node, context.state.node,
expression, expression,
node.pending node.pending
? b.arrow([b.id('$$anchor')], /** @type {BlockStatement} */ (context.visit(node.pending))) ? b.arrow(
[b.id('$$anchor')],
/** @type {BlockStatement} */ (context.visit(node.pending)),
node.pending.metadata.has_await
)
: b.null, : b.null,
then_block, then_block,
catch_block catch_block

@ -326,12 +326,16 @@ export function EachBlock(node, context) {
b.literal(flags), b.literal(flags),
thunk, thunk,
key_function, key_function,
b.arrow(render_args, b.block(declarations.concat(block.body))) b.arrow(render_args, b.block(declarations.concat(block.body)), node.body.metadata.has_await)
]; ];
if (node.fallback) { if (node.fallback) {
args.push( args.push(
b.arrow([b.id('$$anchor')], /** @type {BlockStatement} */ (context.visit(node.fallback))) b.arrow(
[b.id('$$anchor')],
/** @type {BlockStatement} */ (context.visit(node.fallback)),
node.fallback.metadata.has_await
)
); );
} }

@ -15,14 +15,21 @@ export function IfBlock(node, context) {
const consequent = /** @type {BlockStatement} */ (context.visit(node.consequent)); const consequent = /** @type {BlockStatement} */ (context.visit(node.consequent));
const consequent_id = b.id(context.state.scope.generate('consequent')); const consequent_id = b.id(context.state.scope.generate('consequent'));
statements.push(b.var(consequent_id, b.arrow([b.id('$$anchor')], consequent))); statements.push(
b.var(
consequent_id,
b.arrow([b.id('$$anchor')], consequent, node.consequent.metadata.has_await)
)
);
let alternate_id; let alternate_id;
if (node.alternate) { if (node.alternate) {
const alternate = /** @type {BlockStatement} */ (context.visit(node.alternate)); const alternate = /** @type {BlockStatement} */ (context.visit(node.alternate));
alternate_id = b.id(context.state.scope.generate('alternate')); alternate_id = b.id(context.state.scope.generate('alternate'));
statements.push(b.var(alternate_id, b.arrow([b.id('$$anchor')], alternate))); statements.push(
b.var(alternate_id, b.arrow([b.id('$$anchor')], alternate, node.alternate.metadata.has_await))
);
} }
const { has_await } = node.metadata.expression; const { has_await } = node.metadata.expression;

@ -18,7 +18,12 @@ export function KeyBlock(node, context) {
const body = /** @type {Expression} */ (context.visit(node.fragment)); const body = /** @type {Expression} */ (context.visit(node.fragment));
let statement = add_svelte_meta( let statement = add_svelte_meta(
b.call('$.key', context.state.node, key, b.arrow([b.id('$$anchor')], body)), b.call(
'$.key',
context.state.node,
key,
b.arrow([b.id('$$anchor')], body, node.fragment.metadata.has_await)
),
node, node,
'key' 'key'
); );

@ -86,7 +86,12 @@ export function SvelteBoundary(node, context) {
block.body.unshift(...const_tags); block.body.unshift(...const_tags);
const boundary = b.stmt( const boundary = b.stmt(
b.call('$.boundary', context.state.node, props, b.arrow([b.id('$$anchor')], block)) b.call(
'$.boundary',
context.state.node,
props,
b.arrow([b.id('$$anchor')], block, node.fragment.metadata.has_await)
)
); );
context.state.template.push_comment(); context.state.template.push_comment();

Loading…
Cancel
Save