Skip to content

armgit / rea

Public Imported from GitHub
0

Reverse engineer anything with agents, from app behavior down to native binaries.

fix(reference): preserve unresolved absolute module specifiers (#670)

Rudy Mizrahi Celeklic8aed4740d52
diff --git a/src/application/ReferenceSourceImportEntries.ts b/src/application/ReferenceSourceImportEntries.ts
index 168a2f698..9aa9d401e 100644
--- a/src/application/ReferenceSourceImportEntries.ts
+++ b/src/application/ReferenceSourceImportEntries.ts
@@ -77,6 +77,8 @@ const resolveInternalSpecifier = (
specifier: string,
filePaths: ReadonlySet<string>,
): { 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 0b6864d26..1d2d3f4aa 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",
+ });
+ });
+});