pull/17977/head
Simon Holthausen 1 month ago
parent 25f331921d
commit 5dd7e6d9fa

@ -1098,14 +1098,6 @@ function calculate_blockers(instance, analysis) {
sync_group = [];
}
/**
* @param {ESTree.Statement | ESTree.VariableDeclarator} node
*/
function push_async_entry(node) {
flush_sync_group();
analysis.instance_body.async.push({ nodes: [node], has_await: true });
}
/**
* Analysis of blockers for functions is deferred until we know which statements are async/blockers
* @type {Array<ESTree.FunctionDeclaration | ESTree.VariableDeclarator>}
@ -1167,6 +1159,9 @@ function calculate_blockers(instance, analysis) {
trace_references(declarator, reads, writes, instance.scope);
// Needs to happen before blocker computation
if (has_await) flush_sync_group();
const blocker = /** @type {NonNullable<Binding['blocker']>} */ (
b.member(promises, b.literal(analysis.instance_body.async.length), true)
);
@ -1181,7 +1176,7 @@ function calculate_blockers(instance, analysis) {
if (has_await) {
// one declarator per declaration, makes things simpler
push_async_entry(declarator);
analysis.instance_body.async.push({ nodes: [node], has_await: true });
} else {
sync_group.push(declarator);
}
@ -1196,6 +1191,9 @@ function calculate_blockers(instance, analysis) {
trace_references(node, reads, writes, instance.scope);
// Needs to happen before blocker computation
if (has_await) flush_sync_group();
const blocker = /** @type {NonNullable<Binding['blocker']>} */ (
b.member(promises, b.literal(analysis.instance_body.async.length), true)
);
@ -1209,7 +1207,7 @@ function calculate_blockers(instance, analysis) {
}
if (has_await) {
push_async_entry(node);
analysis.instance_body.async.push({ nodes: [node], has_await: true });
} else {
sync_group.push(node);
}

@ -85,22 +85,20 @@ function transform_async_node(node, transform) {
transform(b.var(node.id, node.init))
);
return (
visited.type === 'VariableDeclaration'
? visited.declarations.map((node) => {
if (
node.id.type === 'Identifier' &&
(node.id.name.startsWith('$$d') || node.id.name.startsWith('$$array'))
) {
// This intermediate declaration is created in VariableDeclaration.js;
// subsequent statements may depend on it.
return b.var(node.id, node.init);
}
return b.stmt(b.assignment('=', node.id, node.init ?? b.void0));
})
: []
);
return visited.type === 'VariableDeclaration'
? visited.declarations.map((node) => {
if (
node.id.type === 'Identifier' &&
(node.id.name.startsWith('$$d') || node.id.name.startsWith('$$array'))
) {
// This intermediate declaration is created in VariableDeclaration.js;
// subsequent statements may depend on it.
return b.var(node.id, node.init);
}
return b.stmt(b.assignment('=', node.id, node.init ?? b.void0));
})
: [];
}
if (node.type === 'ClassDeclaration') {

Loading…
Cancel
Save