parallelize-async-work
ComputerGuy 6 days ago
parent c17a1e3ed2
commit c41900c666

@ -51,11 +51,12 @@ export function VariableDeclaration(node, context) {
init?.type === 'AwaitExpression' && init?.type === 'AwaitExpression' &&
context.state.analysis.instance?.scope === context.state.scope context.state.analysis.instance?.scope === context.state.scope
) { ) {
const current_chunk = context.state.current_parallelized_chunk;
const parallelize = can_be_parallelized( const parallelize = can_be_parallelized(
init.argument, init.argument,
context.state.scope, context.state.scope,
context.state.analysis, context.state.analysis,
[...(context.state.current_parallelized_chunk?.bindings ?? []), ...bindings] [...(current_chunk?.bindings ?? []), ...bindings]
); );
if (parallelize) { if (parallelize) {
const { id, init: visited_init } = /** @type {VariableDeclarator} */ ( const { id, init: visited_init } = /** @type {VariableDeclarator} */ (
@ -68,15 +69,10 @@ export function VariableDeclaration(node, context) {
id, id,
init: /** @type {Expression} */ (visited_init) init: /** @type {Expression} */ (visited_init)
}; };
if ( if (current_chunk && current_chunk.kind === node.kind) {
context.state.current_parallelized_chunk && current_chunk.declarators.push(_declarator);
context.state.current_parallelized_chunk.kind === node.kind current_chunk.bindings.push(...bindings);
) { current_chunk.position = /** @type {Program} */ (parent).body.indexOf(node);
context.state.current_parallelized_chunk.declarators.push(_declarator);
context.state.current_parallelized_chunk.bindings.push(...bindings);
context.state.current_parallelized_chunk.position = /** @type {Program} */ (
parent
).body.indexOf(node);
} else { } else {
/** @type {ParallelizedChunk} */ /** @type {ParallelizedChunk} */
const chunk = { const chunk = {
@ -251,6 +247,7 @@ export function VariableDeclaration(node, context) {
/** @type {CallExpression} */ (init) /** @type {CallExpression} */ (init)
); );
let parallelize = false; let parallelize = false;
const current_chunk = context.state.current_parallelized_chunk;
if ( if (
is_async && is_async &&
context.state.analysis.instance && context.state.analysis.instance &&
@ -259,7 +256,7 @@ export function VariableDeclaration(node, context) {
declarator.id.type === 'Identifier' declarator.id.type === 'Identifier'
) { ) {
parallelize = can_be_parallelized(value, context.state.scope, context.state.analysis, [ parallelize = can_be_parallelized(value, context.state.scope, context.state.analysis, [
...(context.state.current_parallelized_chunk?.bindings ?? []), ...(current_chunk?.bindings ?? []),
...context.state.scope.get_bindings(declarator) ...context.state.scope.get_bindings(declarator)
]); ]);
} }
@ -369,18 +366,14 @@ export function VariableDeclaration(node, context) {
if (!parallelize) { if (!parallelize) {
declarations.push(...derived_declarators); declarations.push(...derived_declarators);
} else if (derived_declarators.length > 0) { } else if (derived_declarators.length > 0) {
/** @type {ParallelizedChunk['declarators']} */
const declarators = derived_declarators.map(({ id, init }) => ({ const declarators = derived_declarators.map(({ id, init }) => ({
id, id,
init: /** @type {Expression} */ (init) init: /** @type {Expression} */ (init)
})); }));
if ( if (current_chunk && current_chunk.kind === node.kind) {
context.state.current_parallelized_chunk && current_chunk.declarators.push(...declarators);
context.state.current_parallelized_chunk.kind === node.kind current_chunk.bindings.push(...bindings);
) { current_chunk.position = position;
context.state.current_parallelized_chunk.declarators.push(...declarators);
context.state.current_parallelized_chunk.bindings.push(...bindings);
context.state.current_parallelized_chunk.position = position;
} else { } else {
/** @type {ParallelizedChunk} */ /** @type {ParallelizedChunk} */
const chunk = { const chunk = {

Loading…
Cancel
Save