fix(reference-source): respect require bindings

Reuse lexical ownership to exclude shadowed require calls while retaining native CommonJS and direct createRequire bindings. Preserve candidate edges when JavaScript or TypeScript runtime mode is unknown.

Co-authored-by: Rudy Celekli <rudy@gradiahq.com>
This commit is contained in:
morluto
2026-10-11 09:59:23 +08:00
parent f88c99021b
commit f998fcb1cc
5 changed files with 335 additions and 4 deletions
@@ -29,6 +29,7 @@ import {
resolveSemanticBindingState,
semanticResolutionBlocked,
resolveSemanticBindingFromScope,
semanticBindingId,
semanticScopeId,
semanticVariableScope,
} from "./javascriptSemanticState.js";
@@ -105,7 +106,7 @@ export const analyzeJavaScriptSemantics = (
/** Recover lexical references, optionally for one name, without evaluating values or provenance. */
export const analyzeParsedJavaScriptReferences = (
file: ParsedJavaScriptSource,
file: Pick<ParsedJavaScriptSource, "program">,
name?: string,
): readonly JavaScriptSemanticReference[] => {
const state = createState(file.program);
@@ -1101,7 +1102,7 @@ const createBinding = (
kind: JavaScriptSemanticDefinition["kind"],
mutable: boolean,
): JavaScriptSemanticBindingState => ({
bindingId: `${scope.scopeId}:binding:${encodeURIComponent(name)}`,
bindingId: semanticBindingId(scope.scopeId, name),
scopeId: scope.scopeId,
name,
kind,