From c8aed4740d52b1eecaa93b3a527e8b3814dc88a4 Mon Sep 17 00:00:00 2001 From: Rudy Mizrahi Celekli <47457359+rudycelekli@users.noreply.github.com> Date: Tue, 6 Oct 2026 03:18:17 -0500 Subject: [PATCH] fix(reference): preserve unresolved absolute module specifiers (#670) Signed-off-by: RudyCelekli <47457359+rudycelekli@users.noreply.github.com> --- .../ReferenceSourceImportEntries.ts | 2 ++ .../filesystem/referenceSourceImport.test.ts | 32 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/application/ReferenceSourceImportEntries.ts b/src/application/ReferenceSourceImportEntries.ts index 168a2f698c..9aa9d401e4 100644 --- a/src/application/ReferenceSourceImportEntries.ts +++ b/src/application/ReferenceSourceImportEntries.ts @@ -77,6 +77,8 @@ const resolveInternalSpecifier = ( specifier: string, filePaths: ReadonlySet, ): { to: string; resolution: "internal" | "unresolved" } => { + if (posix.isAbsolute(specifier)) + return { to: specifier, resolution: "unresolved" }; const normalized = posix.normalize( posix.join(posix.dirname(fromPath), specifier), ); diff --git a/tests/boundary/filesystem/referenceSourceImport.test.ts b/tests/boundary/filesystem/referenceSourceImport.test.ts index 0b6864d266..1d2d3f4aa6 100644 --- a/tests/boundary/filesystem/referenceSourceImport.test.ts +++ b/tests/boundary/filesystem/referenceSourceImport.test.ts @@ -365,3 +365,35 @@ describe("reference source path selection", () => { } }); }); + +describe("reference source rooted module specifiers", () => { + it("does not rebase an absolute import onto a coincidentally matching source member", async () => { + const root = await createTestTempDirectory("rea-reference-rooted-"); + await mkdir(join(root, "src", "outside"), { recursive: true }); + await writeFile( + join(root, "src", "main.js"), + 'import "/outside/dep.js"; import "./outside/dep.js";\n', + ); + await writeFile( + join(root, "src", "outside", "dep.js"), + "export const value = 1;\n", + ); + const result = await importTree(root); + expect(result.ok).toBe(true); + if (!result.ok) return; + expect(result.value.relationships).toContainEqual({ + from_path: "src/main.js", + to: "/outside/dep.js", + kind: "imports", + resolution: "unresolved", + parse_state: "parsed", + }); + expect(result.value.relationships).toContainEqual({ + from_path: "src/main.js", + to: "src/outside/dep.js", + kind: "imports", + resolution: "internal", + parse_state: "parsed", + }); + }); +});