|
|
|
@ -1,13 +1,16 @@
|
|
|
|
|
/** @import { Expression, ExpressionStatement } from 'estree' */
|
|
|
|
|
/** @import { ComponentContext } from '../types' */
|
|
|
|
|
/** @import { Expression, ExpressionStatement, Node, Program } from 'estree' */
|
|
|
|
|
/** @import { ComponentContext, ParallelizedChunk } from '../types' */
|
|
|
|
|
import * as b from '#compiler/builders';
|
|
|
|
|
import { get_rune } from '../../../scope.js';
|
|
|
|
|
import { can_be_parallelized } from '../utils.js';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param {ExpressionStatement} node
|
|
|
|
|
* @param {ComponentContext} context
|
|
|
|
|
*/
|
|
|
|
|
export function ExpressionStatement(node, context) {
|
|
|
|
|
const parent = /** @type {Node} */ (context.path.at(-1));
|
|
|
|
|
const position = /** @type {Program} */ (parent).body?.indexOf?.(node);
|
|
|
|
|
if (node.expression.type === 'CallExpression') {
|
|
|
|
|
const rune = get_rune(node.expression, context.state.scope);
|
|
|
|
|
|
|
|
|
@ -25,6 +28,39 @@ export function ExpressionStatement(node, context) {
|
|
|
|
|
return b.empty;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (
|
|
|
|
|
node.expression.type === 'AwaitExpression' &&
|
|
|
|
|
context.state.analysis.instance?.scope === context.state.scope
|
|
|
|
|
) {
|
|
|
|
|
const current_chunk = context.state.current_parallelized_chunk;
|
|
|
|
|
const parallelize = can_be_parallelized(
|
|
|
|
|
node.expression.argument,
|
|
|
|
|
context.state.scope,
|
|
|
|
|
context.state.analysis,
|
|
|
|
|
current_chunk?.bindings ?? []
|
|
|
|
|
);
|
|
|
|
|
if (parallelize) {
|
|
|
|
|
const declarator = {
|
|
|
|
|
id: null,
|
|
|
|
|
init: /** @type {Expression} */ (context.visit(node.expression))
|
|
|
|
|
};
|
|
|
|
|
if (current_chunk) {
|
|
|
|
|
current_chunk.declarators.push(declarator);
|
|
|
|
|
current_chunk.position = position;
|
|
|
|
|
} else {
|
|
|
|
|
/** @type {ParallelizedChunk} */
|
|
|
|
|
const chunk = {
|
|
|
|
|
kind: null,
|
|
|
|
|
declarators: [declarator],
|
|
|
|
|
position,
|
|
|
|
|
bindings: []
|
|
|
|
|
};
|
|
|
|
|
context.state.current_parallelized_chunk = chunk;
|
|
|
|
|
context.state.parallelized_chunks.push(chunk);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
context.next();
|
|
|
|
|
}
|
|
|
|
|