mirror of
https://github.com/morluto/rea
synced 2026-10-27 22:45:19 -04:00
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:
@@ -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)
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user