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 { AST } from '#compiler' */
|
||||||
/** @import { ComponentContext } from '../types.js' */
|
/** @import { ComponentContext } from '../types.js' */
|
||||||
import * as b from '#compiler/builders';
|
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 {AST.AwaitBlock} node
|
||||||
* @param {ComponentContext} context
|
* @param {ComponentContext} context
|
||||||
*/
|
*/
|
||||||
export function AwaitBlock(node, context) {
|
export function AwaitBlock(node, context) {
|
||||||
context.state.template.push(
|
/** @type {Statement} */
|
||||||
b.stmt(
|
let statement = b.stmt(
|
||||||
b.call(
|
b.call(
|
||||||
'$.await',
|
'$.await',
|
||||||
b.id('$$payload'),
|
b.id('$$payload'),
|
||||||
/** @type {Expression} */ (context.visit(node.expression)),
|
/** @type {Expression} */ (context.visit(node.expression)),
|
||||||
b.thunk(
|
b.thunk(
|
||||||
node.pending ? /** @type {BlockStatement} */ (context.visit(node.pending)) : b.block([])
|
node.pending ? /** @type {BlockStatement} */ (context.visit(node.pending)) : b.block([])
|
||||||
),
|
),
|
||||||
b.arrow(
|
b.arrow(
|
||||||
node.value ? [/** @type {Pattern} */ (context.visit(node.value))] : [],
|
node.value ? [/** @type {Pattern} */ (context.visit(node.value))] : [],
|
||||||
node.then ? /** @type {BlockStatement} */ (context.visit(node.then)) : b.block([])
|
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