refactor: consolidate shared analysis boundaries (#10293)

This commit is contained in:
morluto authored and GitHub committed 2026-11-12 22:05:32 -05:00
1 parent 6878a84796
commit c836f57b7d
70 files changed
+1240 -1131

No files matched your search

@@ -16,6 +16,10 @@ export const isErasedJavaScriptDeclaration = (node: t.Node): boolean =>
export const isUnmodeledJavaScriptRuntimeScope = (node: t.Node): boolean =>
t.isTSModuleDeclaration(node) || t.isTSEnumDeclaration(node);
/** Compiler options determine whether an inline type-only declaration retains a side effect. */
export const TYPE_ONLY_MODULE_SIDE_EFFECT_LIMITATION =
"Compiler options are unavailable; inline type-only imports or re-exports may preserve a module side-effect dependency.";
/** Whether TypeScript explicitly erases this entire import declaration. */
export const isTypeOnlyImportDeclaration = (
node: t.ImportDeclaration,
@@ -92,6 +92,7 @@ import {
} from "./javascriptSemanticAmbientWrites.js";
import {
hasUncertainTypeOnlyModuleSideEffect,
TYPE_ONLY_MODULE_SIDE_EFFECT_LIMITATION,
isTypeOnlyImportDeclaration,
isTypeOnlyImportSpecifier,
semanticImportEqualsSpecifier,
@@ -507,9 +508,7 @@ export function* analyzeParsedJavaScriptSemanticsSteps(
]
: []),
...(hasUncertainTypeOnlyModuleSideEffect(file.program)
? [
"Compiler options are unavailable; inline type-only imports or re-exports may preserve a module side-effect dependency.",
]
? [TYPE_ONLY_MODULE_SIDE_EFFECT_LIMITATION]
: []),
"Values and aliases were recovered from inert syntax only; no JavaScript was executed.",
"Return sites include only direct callable returns; nested callable returns remain separate.",
@@ -95,6 +95,19 @@ export const collectJavaScriptSemanticResources = (
];
};
/** Literal kinds Node rejects for both open flags and modes. */
const rejectsFlagOrModeLiteral = (value: t.Node): boolean => {
return (
t.isBigIntLiteral(value) ||
t.isBooleanLiteral(value) ||
t.isRegExpLiteral(value) ||
t.isObjectExpression(value) ||
t.isArrayExpression(value) ||
(t.isUnaryExpression(value) &&
t.isBigIntLiteral(unwrapJavaScriptExpression(value.argument).node))
);
};
/**
* `fs.open`/`fs.openSync` validate the flag before touching the filesystem, so
* a flag Node rejects at the call site throws synchronously and no descriptor
@@ -136,15 +149,7 @@ const rejectsOpenFlagLiteral = (
if (isNonFiniteNumber(value, context)) return true;
// BigInt, boolean, object and array literals all fail Node's flag check. A
// unary operator over a BigInt literal is a BigInt too.
return (
t.isBigIntLiteral(value) ||
t.isBooleanLiteral(value) ||
t.isRegExpLiteral(value) ||
t.isObjectExpression(value) ||
t.isArrayExpression(value) ||
(t.isUnaryExpression(value) &&
t.isBigIntLiteral(unwrapJavaScriptExpression(value.argument).node))
);
return rejectsFlagOrModeLiteral(value);
};
/**
@@ -325,15 +330,7 @@ const rejectsOpenModeLiteral = (
// BigInt, boolean, object and array literals all fail Node's mode check. A
// unary operator over a BigInt literal is a BigInt too, and the range helpers
// above only price numeric operands.
return (
t.isBigIntLiteral(value) ||
t.isBooleanLiteral(value) ||
t.isRegExpLiteral(value) ||
t.isObjectExpression(value) ||
t.isArrayExpression(value) ||
(t.isUnaryExpression(value) &&
t.isBigIntLiteral(unwrapJavaScriptExpression(value.argument).node))
);
return rejectsFlagOrModeLiteral(value);
};
/** `fs.open`, `fs.openSync` and `fs/promises.open` take the flag in slot 1. */
@@ -72,6 +72,7 @@ import type { ParsedJavaScriptSource } from "./javascriptSourceParser.js";
import { createJavaScriptRpcScan } from "./javascriptRpcEndpoints.js";
import {
hasUncertainTypeOnlyModuleSideEffect,
TYPE_ONLY_MODULE_SIDE_EFFECT_LIMITATION,
semanticStaticModuleSource,
semanticImportEqualsSpecifier,
} from "./javascriptModuleDeclaration.js";
@@ -279,11 +280,7 @@ const finalizeStaticAnalysis = (
: [
"One or more static keys, expressions, or Electron boundary values were dynamic and remain unknown.",
]),
...(typeOnlySideEffect
? [
"Compiler options are unavailable; inline type-only imports or re-exports may preserve a module side-effect dependency.",
]
: []),
...(typeOnlySideEffect ? [TYPE_ONLY_MODULE_SIDE_EFFECT_LIMITATION] : []),
...(electronObserved ? [ELECTRON_IDENTITY_LIMITATION] : []),
...(candidateElectron
? [