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:
1 parent
ded199abcd
commit
c923fb0dc9
18 files changed
+503
-100
No files matched your search
@@ -0,0 +1,23 @@
|
||||
import { posix } from "node:path";
|
||||
|
||||
/** Loader evidence retained for a source-level module reference. */
|
||||
export type JavaScriptModuleResolutionMode =
|
||||
| "import"
|
||||
| "require"
|
||||
| "compiler-dependent";
|
||||
|
||||
/** Derive source mode only when syntax or an explicit source format owns it. */
|
||||
export const moduleResolutionModeForJavaScriptReference = (
|
||||
sourcePath: string,
|
||||
referenceKind: "static-import" | "dynamic-import" | "require",
|
||||
explicitMode?: JavaScriptModuleResolutionMode,
|
||||
): JavaScriptModuleResolutionMode => {
|
||||
if (explicitMode !== undefined) return explicitMode;
|
||||
if (referenceKind === "require") return "require";
|
||||
if (referenceKind === "dynamic-import") return "import";
|
||||
const extension = posix.extname(sourcePath).toLowerCase();
|
||||
if (extension === ".cts") return "require";
|
||||
if (extension === ".mts") return "import";
|
||||
if (extension === ".ts" || extension === ".tsx") return "compiler-dependent";
|
||||
return "import";
|
||||
};
|
||||
Reference in new issue
Block a user