parallelize-async-work
ComputerGuy 2 weeks ago committed by GitHub
parent d4d82532ce
commit 229ab37134
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -37,17 +37,16 @@ export function is_state_source(binding, analysis) {
* @returns {boolean} * @returns {boolean}
*/ */
export function can_be_parallelized(expression, scope, analysis, bindings) { export function can_be_parallelized(expression, scope, analysis, bindings) {
let has_closures = false;
let should_stop = false; let should_stop = false;
/** @type {Set<string>} */ /** @type {Set<string>} */
const references = new Set(); const references = new Set();
walk(/** @type {Node} */ (expression), null, { walk(/** @type {Node} */ (expression), null, {
ArrowFunctionExpression(_, { stop }) { ArrowFunctionExpression(_, { stop }) {
has_closures = true; should_stop = true;
stop(); stop();
}, },
FunctionExpression(_, { stop }) { FunctionExpression(_, { stop }) {
has_closures = true; should_stop = true;
stop(); stop();
}, },
Identifier(node, { path }) { Identifier(node, { path }) {
@ -68,11 +67,11 @@ export function can_be_parallelized(expression, scope, analysis, bindings) {
stop(); stop();
}, },
StaticBlock(node, { stop }) { StaticBlock(node, { stop }) {
has_closures = true; should_stop = true;
stop(); stop();
} }
}); });
if (has_closures || should_stop) { if (should_stop) {
return false; return false;
} }
for (const reference of references) { for (const reference of references) {
@ -80,13 +79,14 @@ export function can_be_parallelized(expression, scope, analysis, bindings) {
if (!binding || binding.declaration_kind === 'import') { if (!binding || binding.declaration_kind === 'import') {
return false; return false;
} }
if ('template' in analysis) { if (binding.scope !== analysis.module.scope) {
if (binding.scope !== analysis.instance.scope) { if (!('template' in analysis)) {
return false; return false;
} }
} else if (binding.scope !== analysis.module.scope) { if (binding.scope !== analysis.instance.scope) {
return false; return false;
} }
}
if (bindings.includes(binding)) { if (bindings.includes(binding)) {
return false; return false;

Loading…
Cancel
Save