mirror of https://github.com/sveltejs/svelte
parent
9d8f259db3
commit
ba391448eb
@ -1,29 +1,33 @@
|
||||
/** @import { BlockStatement, Expression, Pattern } from 'estree' */
|
||||
/** @import { BlockStatement, Expression, Pattern, Statement } from 'estree' */
|
||||
/** @import { AST } from '#compiler' */
|
||||
/** @import { ComponentContext } from '../types.js' */
|
||||
import * as b from '#compiler/builders';
|
||||
import { block_close } from './shared/utils.js';
|
||||
import { block_close, call_child_payload } from './shared/utils.js';
|
||||
|
||||
/**
|
||||
* @param {AST.AwaitBlock} node
|
||||
* @param {ComponentContext} context
|
||||
*/
|
||||
export function AwaitBlock(node, context) {
|
||||
context.state.template.push(
|
||||
b.stmt(
|
||||
b.call(
|
||||
'$.await',
|
||||
b.id('$$payload'),
|
||||
/** @type {Expression} */ (context.visit(node.expression)),
|
||||
b.thunk(
|
||||
node.pending ? /** @type {BlockStatement} */ (context.visit(node.pending)) : b.block([])
|
||||
),
|
||||
b.arrow(
|
||||
node.value ? [/** @type {Pattern} */ (context.visit(node.value))] : [],
|
||||
node.then ? /** @type {BlockStatement} */ (context.visit(node.then)) : b.block([])
|
||||
)
|
||||
/** @type {Statement} */
|
||||
let statement = b.stmt(
|
||||
b.call(
|
||||
'$.await',
|
||||
b.id('$$payload'),
|
||||
/** @type {Expression} */ (context.visit(node.expression)),
|
||||
b.thunk(
|
||||
node.pending ? /** @type {BlockStatement} */ (context.visit(node.pending)) : b.block([])
|
||||
),
|
||||
b.arrow(
|
||||
node.value ? [/** @type {Pattern} */ (context.visit(node.value))] : [],
|
||||
node.then ? /** @type {BlockStatement} */ (context.visit(node.then)) : b.block([])
|
||||
)
|
||||
),
|
||||
block_close
|
||||
)
|
||||
);
|
||||
|
||||
if (node.metadata.expression.has_await) {
|
||||
statement = call_child_payload(b.block([statement]), true);
|
||||
}
|
||||
|
||||
context.state.template.push(statement, block_close);
|
||||
}
|
||||
|
Loading…
Reference in new issue