fix(javascript): trace wrapped Electron IPC paths in large bundles (#1874)

Co-authored-by: David <17119984+fengdwx@users.noreply.github.com>
This commit is contained in:
David
2026-10-12 09:28:59 +08:00
committed by GitHub
parent d93fbda390
commit 87b9793c53
46 changed files with 3213 additions and 355 deletions
@@ -0,0 +1,53 @@
import * as t from "@babel/types";
import {
symbolicTruth,
type SymbolicValue,
} from "./javascriptSymbolicValues.js";
/** Whether short-circuit evaluation reaches the right operand; unknown stays unknown. */
export const symbolicLogicalRight = (
operator: t.LogicalExpression["operator"],
left: SymbolicValue,
): boolean | undefined => {
if (left.kind === "union") {
const choices = left.values.map((value) =>
symbolicLogicalRight(operator, value),
);
return choices.length > 0 &&
choices.every((choice) => choice === choices[0])
? choices[0]
: undefined;
}
if (operator === "??") {
if (left.kind === "literal")
return left.value === null || left.value === undefined;
return [
"function",
"object",
"namespace",
"array",
"record",
"loader",
].includes(left.kind)
? false
: undefined;
}
const truth = symbolicTruth(left);
return truth === undefined ? undefined : operator === "&&" ? truth : !truth;
};
/** Only definite synchronous exits; unsupported control flow stays unknown. */
export const symbolicDefiniteExit = (
node: t.Node | null | undefined,
depth = 0,
): boolean => {
if (!node || depth >= 128) return false;
if (t.isReturnStatement(node) || t.isThrowStatement(node)) return true;
if (t.isBlockStatement(node))
return node.body.some((child) => symbolicDefiniteExit(child, depth + 1));
return (
t.isIfStatement(node) &&
symbolicDefiniteExit(node.consequent, depth + 1) &&
symbolicDefiniteExit(node.alternate, depth + 1)
);
};