pull/17038/head
Rich Harris 4 weeks ago
parent 7ef05151cd
commit 75487f6162

@ -25,13 +25,7 @@ export function IfBlock(node, context) {
statements.push(b.var(alternate_id, b.arrow([b.id('$$anchor')], alternate))); statements.push(b.var(alternate_id, b.arrow([b.id('$$anchor')], alternate)));
} }
// TODO helperise const is_async = node.metadata.expression.is_async();
const blockers = new Set();
for (const d of node.metadata.expression.dependencies) {
if (d.blocker) blockers.add(d.blocker);
}
const is_async = blockers.size > 0 || node.metadata.expression.has_await;
const expression = build_expression(context, node.test, node.metadata.expression); const expression = build_expression(context, node.test, node.metadata.expression);
const test = is_async ? b.call('$.get', b.id('$$condition')) : expression; const test = is_async ? b.call('$.get', b.id('$$condition')) : expression;
@ -84,7 +78,7 @@ export function IfBlock(node, context) {
b.call( b.call(
'$.async', '$.async',
context.state.node, context.state.node,
b.array([...blockers]), node.metadata.expression.blockers(),
b.array([b.thunk(expression, node.metadata.expression.has_await)]), b.array([b.thunk(expression, node.metadata.expression.has_await)]),
b.arrow([context.state.node, b.id('$$condition')], b.block(statements)) b.arrow([context.state.node, b.id('$$condition')], b.block(statements))
) )

@ -1,5 +1,6 @@
/** @import { Expression, PrivateIdentifier } from 'estree' */ /** @import { Expression, PrivateIdentifier } from 'estree' */
/** @import { AST, Binding } from '#compiler' */ /** @import { AST, Binding } from '#compiler' */
import * as b from '#compiler/builders';
/** /**
* All nodes that can appear elsewhere than the top level, have attributes and can contain children * All nodes that can appear elsewhere than the top level, have attributes and can contain children
@ -91,6 +92,29 @@ export class ExpressionMetadata {
* @type {Set<Binding>} * @type {Set<Binding>}
*/ */
references = new Set(); references = new Set();
/** @type {null | Set<Expression>} */
#blockers = null;
#get_blockers() {
if (!this.#blockers) {
this.#blockers = new Set();
for (const d of this.dependencies) {
if (d.blocker) this.#blockers.add(d.blocker);
}
}
return this.#blockers;
}
blockers() {
return b.array([...this.#get_blockers()]);
}
is_async() {
return this.has_await || this.#get_blockers().size > 0;
}
} }
export function new ExpressionMetadata() { export function new ExpressionMetadata() {

Loading…
Cancel
Save