mirror of
https://github.com/morluto/rea.git
synced 2026-11-16 11:43:20 +00:00
fix(javascript): resolve module-level Electron options in functions (#8960)
* fix(javascript): resolve module-level Electron options in functions * fix(javascript): limit module option ancestry walk * fix(javascript): preserve uncertain captured argument ordering * fix(javascript): retain hoisted activation uncertainty * fix(javascript): retain function ownership through loops * fix(javascript): account for classic global activations * fix(javascript): bind first activations to lexical identities * fix(javascript): retain uncertain global activation timing * fix(javascript): isolate receiver facts and share computed reads * fix(javascript): retain projected and opaque global activations * fix(javascript): refresh activation bounds as opaque effects grow * fix(ci): format website watch directories without changing configuration * fix(javascript): share source reads across opaque-effect updates * fix(javascript): retain constructed-code global activation bounds * fix(javascript): share runtime activation and receiver facts * fix(javascript): reuse pattern reads and function positions * fix(javascript): isolate copied paths and preserve runtime reads * style(javascript): format migrated reference imports * fix(javascript): normalize constructor activation and receiver effects * fix(javascript): retain aliased receiver timing and lexical global this * fix(javascript): preserve effect-free receiver identity across activations * fix(javascript): retain outer activation and prototype effects * fix(javascript): index implicit reads without deep path rescans * fix(javascript): retain aliased prototype and parameter read uncertainty * fix(javascript): index reflected reads through intrinsic invocation facts * fix(javascript): retain unresolved global activation reads * chore: refresh PR branch after review fix publication * fix(javascript): retain projected receiver reads and cache method facts * fix(javascript): retain inherited and implicit activation reads * fix(javascript): retain caller-owned this uncertainty * fix(javascript): retain reflected reads with unresolved spread arguments * fix(javascript): preserve enclosing activation for decorators * fix(javascript): track intrinsic literal prototype effects * fix(javascript): retain catch activation from implicit reads * perf(javascript): reuse effective keys for projected reads * fix(javascript): retain possible caller-owned ambient effects
This commit is contained in:
1 parent
ce07d358cd
commit
a2134b3a74
40 files changed
+2585
-191
No files matched your search
@@ -11,7 +11,10 @@ import {
|
||||
type JavaScriptSemanticPropertyPath,
|
||||
} from "./javascriptSemanticPropertyPaths.js";
|
||||
import { compareUnicodeCodePoints } from "../unicodeCodePointOrder.js";
|
||||
import { semanticCopiedReferencePath } from "./javascriptSemanticReferenceSources.js";
|
||||
|
||||
import { semanticCopiedReferencePath } from "./javascriptSemanticCopiedReferencePaths.js";
|
||||
import { semanticMethodDefinitionExpression } from "./javascriptSemanticEvaluationOrder.js";
|
||||
import { childNodes } from "./javascriptSemanticTraversal.js";
|
||||
import type {
|
||||
IterationSourceValue,
|
||||
SemanticIterationSource,
|
||||
@@ -274,6 +277,50 @@ const emptySourceFacts: SemanticSourceFacts = {
|
||||
iterations: [],
|
||||
propertyReads: [],
|
||||
};
|
||||
// Immutable AST subtree summaries are reused by enclosing and nested catches.
|
||||
// Property reads can invoke getters; tags and coercions can execute user code.
|
||||
const guardedExecutions = new WeakMap<t.Node, boolean>();
|
||||
const guardedBodyMayCall = (body: t.BlockStatement): boolean => {
|
||||
const pending: { node: t.Node; parent: t.Node | null; finish: boolean }[] = [
|
||||
{ node: body, parent: null, finish: false },
|
||||
];
|
||||
while (pending.length > 0) {
|
||||
const frame = pending.pop();
|
||||
if (frame === undefined || guardedExecutions.has(frame.node)) continue;
|
||||
const { node, parent } = frame;
|
||||
const children = [...childNodes(node)].filter(
|
||||
(child) =>
|
||||
!t.isFunction(node) || semanticMethodDefinitionExpression(node, child),
|
||||
);
|
||||
if (!frame.finish) {
|
||||
pending.push({ node, parent, finish: true });
|
||||
for (const child of children)
|
||||
pending.push({ node: child, parent: node, finish: false });
|
||||
} else {
|
||||
const direct =
|
||||
t.isCallExpression(node) ||
|
||||
t.isOptionalCallExpression(node) ||
|
||||
t.isNewExpression(node) ||
|
||||
t.isTaggedTemplateExpression(node) ||
|
||||
t.isMemberExpression(node) ||
|
||||
t.isOptionalMemberExpression(node) ||
|
||||
t.isBinaryExpression(node) ||
|
||||
t.isUnaryExpression(node) ||
|
||||
t.isUpdateExpression(node) ||
|
||||
t.isSpreadElement(node) ||
|
||||
t.isForOfStatement(node) ||
|
||||
t.isAwaitExpression(node) ||
|
||||
((t.isVariableDeclarator(node) || t.isAssignmentExpression(node)) &&
|
||||
semanticSourceFacts(node, parent).propertyReads.length > 0);
|
||||
guardedExecutions.set(
|
||||
node,
|
||||
direct ||
|
||||
children.some((child) => guardedExecutions.get(child) === true),
|
||||
);
|
||||
}
|
||||
}
|
||||
return guardedExecutions.get(body) === true;
|
||||
};
|
||||
const sourceFacts = new WeakMap<
|
||||
t.Node,
|
||||
{ readonly parent: t.Node | null; readonly facts: SemanticSourceFacts }
|
||||
@@ -291,6 +338,7 @@ const semanticSourceFacts = (
|
||||
t.isForOfStatement(node) ||
|
||||
t.isSpreadElement(node) ||
|
||||
t.isYieldExpression(node) ||
|
||||
t.isCatchClause(node) ||
|
||||
t.isFunction(node)
|
||||
)
|
||||
)
|
||||
@@ -330,9 +378,19 @@ const semanticSourceFacts = (
|
||||
node.argument != null
|
||||
)
|
||||
add(sources, { node: node.argument, projection: [] }, node, {});
|
||||
else if (
|
||||
t.isCatchClause(node) &&
|
||||
node.param != null &&
|
||||
t.isTryStatement(parent) &&
|
||||
guardedBodyMayCall(parent.block)
|
||||
)
|
||||
visit(context, node.param, { node: node.param, projection: [null] });
|
||||
else if (t.isFunction(node))
|
||||
for (const parameter of runtimeFunctionParameters(node))
|
||||
visit(context, parameter, undefined);
|
||||
// A caller-supplied value is unknown, not an absent property-read source.
|
||||
// Retain the owning pattern as an unresolved source, including alongside
|
||||
// default-value projections, instead of dropping its property lookups.
|
||||
visit(context, parameter, { node: parameter, projection: [] });
|
||||
const facts = { iterations: sources, propertyReads };
|
||||
sourceFacts.set(node, { parent, facts });
|
||||
return facts;
|
||||
@@ -344,8 +402,28 @@ export const semanticIterationSources = (
|
||||
): readonly SemanticIterationSource[] =>
|
||||
semanticSourceFacts(node, parent).iterations;
|
||||
|
||||
/** Pattern reads from an explicitly retained source, including thrown values. */
|
||||
export const semanticPatternPropertyReadSources = (
|
||||
pattern: t.Node,
|
||||
source: IterationSourceValue,
|
||||
mutation: t.Node,
|
||||
): readonly SemanticPropertyReadSource[] => {
|
||||
const propertyReads: SemanticPropertyReadSource[] = [];
|
||||
visit({ sources: [], propertyReads, mutation }, pattern, source);
|
||||
return propertyReads;
|
||||
};
|
||||
|
||||
export const semanticPropertyReadSources = (
|
||||
node: t.Node,
|
||||
parent: t.Node | null,
|
||||
): readonly SemanticPropertyReadSource[] =>
|
||||
semanticSourceFacts(node, parent).propertyReads;
|
||||
supplemental?: {
|
||||
readonly implicitPropertyReads: WeakMap<
|
||||
t.Node,
|
||||
readonly SemanticPropertyReadSource[]
|
||||
>;
|
||||
},
|
||||
): readonly SemanticPropertyReadSource[] => {
|
||||
const ordinary = semanticSourceFacts(node, parent).propertyReads;
|
||||
const implicit = supplemental?.implicitPropertyReads.get(node);
|
||||
return implicit === undefined ? ordinary : [...ordinary, ...implicit];
|
||||
};
|
||||
Reference in new issue
Block a user