fix(javascript): retain compiler-dependent module resolution facts
Compare import and require outcomes for static TypeScript references when compiler options are unknown. Preserve branch facts through worker IR and both graph projections; retain declaration fallbacks as candidates without changing explicitly selected paths. Validation: 210 focused resolver and semantic tests; 21 production-boundary and source-extension tests. A bounded 2,000-reference probe adds about 16–17 ms wall time for dual resolution; full task token costs and real compiled application behavior remain unmeasured.
This commit is contained in:
@@ -8,6 +8,11 @@ const EMITTED_SUFFIXES: ReadonlyArray<
|
||||
[".jsx", [".tsx", ".d.ts"]],
|
||||
];
|
||||
|
||||
export interface TypeScriptEmittedSourceCandidate {
|
||||
readonly path: string;
|
||||
readonly kind: "implementation" | "declaration";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return TypeScript source counterparts for an explicit emitted filename.
|
||||
* Callers retain exact runtime-file precedence and must not use these for
|
||||
@@ -16,7 +21,7 @@ const EMITTED_SUFFIXES: ReadonlyArray<
|
||||
export const typescriptEmittedSourceCandidates = (
|
||||
sourcePath: string,
|
||||
candidate: string,
|
||||
): readonly string[] => {
|
||||
): readonly TypeScriptEmittedSourceCandidate[] => {
|
||||
if (!/\.(?:ts|tsx|mts|cts)$/u.test(sourcePath)) return [];
|
||||
const emitted = EMITTED_SUFFIXES.find(([suffix]) =>
|
||||
candidate.endsWith(suffix),
|
||||
@@ -25,5 +30,8 @@ export const typescriptEmittedSourceCandidates = (
|
||||
// Strip the matched suffix by length. posix.extname would miss dotfile
|
||||
// names such as ".js", whose whole basename is the emitted suffix itself.
|
||||
const stem = candidate.slice(0, candidate.length - emitted[0].length);
|
||||
return emitted[1].map((suffix) => `${stem}${suffix}`);
|
||||
return emitted[1].map((suffix) => ({
|
||||
path: `${stem}${suffix}`,
|
||||
kind: suffix.startsWith(".d.") ? "declaration" : "implementation",
|
||||
}));
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user