fix(javascript): share TypeScript emitted import resolution

This commit is contained in:
morluto
2026-10-12 01:31:32 +08:00
parent 486b56724c
commit 1dfb933e47
5 changed files with 217 additions and 23 deletions
@@ -75,7 +75,7 @@ cliTest(
);
cliTest(
"discloses CommonJS and TypeScript self-imports while retaining unresolved extension rewrites",
"discloses CommonJS and TypeScript self-imports including emitted-name rewrites",
async ({ cli }) => {
const root = await createTestTempDirectory("rea-self-require-");
await writeFixtureFiles(root, {
@@ -94,8 +94,10 @@ cliTest(
expect(
graph.edges.filter((edge) => edge.source_node_id === edge.target_node_id),
).toEqual([]);
// ./util.ts is a literal self-import and ./util.js resolves under NodeNext
// emitted-name semantics back to util.ts itself, as ./c.cjs does for CJS.
expect(graph.limitations).toContainEqual(
expect.stringMatching(/^2 import specifiers .*were omitted;/u),
expect.stringMatching(/^3 import specifiers .*were omitted;/u),
);
expect(result.limitations).toEqual(
expect.arrayContaining(graph.limitations),
@@ -128,12 +130,21 @@ cliTest(
).toBe(false);
}
expect(
graph.edges.find(
graph.edges.some(
(edge) =>
edge.source_node_id === findSourceModule(graph, "util.ts")?.node_id &&
edge.properties.specifier === "./util.js" &&
edge.properties.module_link_kind === "import",
)?.properties,
).toMatchObject({ resolved_path: null, resolution_status: "not-found" });
(edge.properties.module_link_kind === "import" ||
edge.properties.resolution_status === "not-found"),
),
).toBe(false);
expect(
graph.nodes.some((node) =>
node.observations.some(
({ properties }) =>
properties.semantic_role === "module-reference" &&
properties.declared_specifier === "./util.js",
),
),
).toBe(false);
},
);