fix(javascript): retain unbound CommonJS semantic imports

Collect unbound literal CommonJS dependencies at the semantic module-link owner, retain null binding names and source provenance, and avoid duplicate links for calls already represented by bindings or re-exports. Preserve distinct nested calls, shadowing exclusions, dynamic binding uncertainty, and existing static asset references.

Fixes #1793.
This commit is contained in:
Ysopwnable authored and GitHub committed 2026-10-11 19:16:32 +08:00
1 parent 40d9c7b836
commit 3a17882cc4
10 files changed
+388 -33

No files matched your search

@@ -384,7 +384,7 @@ export function* classifyParsedJavaScriptElectronBindingsSteps(
}
return exported ?? undefined;
}
const origin = semanticRequireOrigin(root, state);
const origin = semanticRequireOrigin(root, state)?.origin;
return origin !== undefined && ELECTRON_MODULE.test(origin.specifier)
? electronExportPath(origin.importedPath)
: undefined;
@@ -459,7 +459,7 @@ const bindingOrigin = (
state.conditionalInitializers.has(initializer.node)
)
return undefined;
const origin = semanticRequireOrigin(initializer.node, state);
const origin = semanticRequireOrigin(initializer.node, state)?.origin;
const projection = initializer.projection;
return origin === undefined ||
!projection.every((key): key is string => typeof key === "string")
@@ -485,6 +485,7 @@ const createState = (program: t.Program): JavaScriptSemanticAnalysisState => {
callables: [],
callableNodesById: new Map(),
moduleLinks: [],
linkedRequireCalls: new WeakSet(),
moduleLinkBindings: new WeakMap(),
conditionalInitializers: new WeakSet(),
};