fix(reference): preserve unresolved absolute module specifiers (#670)
Signed-off-by: RudyCelekli <47457359+rudycelekli@users.noreply.github.com>
This commit is contained in:
1 parent
fa02df9ad3
commit
c8aed4740d
2 files changed
+34
No files matched your search
@@ -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),
|
||||
);
|
||||
|
||||
@@ -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",
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user