Skip to content

Commit a7a2d7d

Browse files
committed
Resolve module specifier relative to moduleFile.originalFileName
1 parent 33a6509 commit a7a2d7d

File tree

4 files changed

+61
-2
lines changed

4 files changed

+61
-2
lines changed

src/compiler/moduleSpecifiers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ namespace ts.moduleSpecifiers {
9393

9494
const info = getInfo(importingSourceFile.path, host);
9595
const moduleSourceFile = getSourceFileOfNode(moduleSymbol.valueDeclaration || getNonAugmentationDeclaration(moduleSymbol));
96-
const modulePaths = getAllModulePaths(files, importingSourceFile.path, moduleSourceFile.fileName, info.getCanonicalFileName, host, redirectTargetsMap);
96+
const modulePaths = getAllModulePaths(files, importingSourceFile.path, moduleSourceFile.originalFileName, info.getCanonicalFileName, host, redirectTargetsMap);
9797

9898
const preferences = getPreferences(userPreferences, compilerOptions, importingSourceFile);
9999
const global = mapDefined(modulePaths, moduleFileName => tryGetModuleNameAsNodeModule(moduleFileName, info, host, compilerOptions));

src/testRunner/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
"unittests/tsbuild/inferredTypeFromTransitiveModule.ts",
9898
"unittests/tsbuild/lateBoundSymbol.ts",
9999
"unittests/tsbuild/missingExtendedFile.ts",
100+
"unittests/tsbuild/moduleSpecifiers.ts",
100101
"unittests/tsbuild/outFile.ts",
101102
"unittests/tsbuild/referencesWithRootDirInParent.ts",
102103
"unittests/tsbuild/resolveJsonModule.ts",

src/testRunner/unittests/config/projectReferences.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,5 +348,4 @@ namespace ts {
348348
});
349349
});
350350
});
351-
352351
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
namespace ts {
2+
// https://github.com/microsoft/TypeScript/issues/31696
3+
it("unittests:: tsbuild:: synthesized module specifiers to referenced projects resolve correctly", () => {
4+
const fs = vfs.createFromFileSystem(Harness.IO, /*ignoreCase*/ false, {
5+
files: {
6+
"/src/common/nominal.ts": "export declare type Nominal<T, Name extends string> = T & {\n\t[Symbol.species]: Name;\n};\n",
7+
"/src/common/tsconfig.json": JSON.stringify({
8+
extends: "../../tsconfig.base.json",
9+
compilerOptions: { composite: true },
10+
include: ["nominal.ts"]
11+
}),
12+
"/src/sub-project/index.ts": "import { Nominal } from '../common/nominal';\n\nexport type MyNominal = Nominal<string, 'MyNominal'>;\n",
13+
"/src/sub-project/tsconfig.json": JSON.stringify({
14+
extends: "../../tsconfig.base.json",
15+
compilerOptions: { composite: true },
16+
references: [{ path: "../common" }],
17+
include: ["./index.ts"]
18+
}),
19+
"/src/sub-project-2/index.ts":
20+
"import { MyNominal } from '../sub-project/index';\n\n" +
21+
"const variable = {\n\tkey: 'value' as MyNominal,\n};\n\n" +
22+
"export function getVar(): keyof typeof variable {\n\treturn 'key';\n}\n",
23+
"/src/sub-project-2/tsconfig.json": JSON.stringify({
24+
extends: "../../tsconfig.base.json",
25+
compilerOptions: { composite: true },
26+
references: [{ path: "../sub-project" }],
27+
include: ["./index.ts"]
28+
}),
29+
"/src/tsconfig.json": JSON.stringify({
30+
compilerOptions: { composite: true },
31+
references: [{ path: "./sub-project" }, { path: "./sub-project-2" }],
32+
include: []
33+
}),
34+
"/tsconfig.base.json": JSON.stringify({
35+
compilerOptions: {
36+
rootDir: "./",
37+
outDir: "lib",
38+
lib: ["dom", "es2015", "es2015.symbol.wellknown"]
39+
},
40+
}),
41+
"/tsconfig.json": JSON.stringify({
42+
compilerOptions: { composite: true },
43+
references: [{ path: "./src" }],
44+
include: []
45+
})
46+
},
47+
cwd: "/"
48+
});
49+
const sys = new fakes.System(fs, { executingFilePath: "/", newLine: "\n" });
50+
const host = new fakes.SolutionBuilderHost(sys);
51+
const builder = createSolutionBuilder(host, ["/tsconfig.json"], { dry: false, force: false, verbose: false });
52+
builder.build("/tsconfig.json");
53+
54+
const data = host.vfs.readFileSync("/lib/src/sub-project-2/index.d.ts", "utf8");
55+
56+
// Prior to fixing GH31696 the import below was `import("../../lib/src/common/nonterminal")`
57+
assert.equal(data, `declare const variable: {\n key: import("../common/nominal").Nominal<string, "MyNominal">;\n};\nexport declare function getVar(): keyof typeof variable;\nexport {};\n`);
58+
});
59+
}

0 commit comments

Comments
 (0)