Skip to content

Commit c8ec855

Browse files
authored
When source file is redirected, set the prototype correctly in node factory (microsoft#48862)
Fixes microsoft#48039
1 parent d879880 commit c8ec855

File tree

4 files changed

+104
-1
lines changed

4 files changed

+104
-1
lines changed

src/compiler/factory/nodeFactory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5275,7 +5275,7 @@ namespace ts {
52755275
hasNoDefaultLib: boolean,
52765276
libReferences: readonly FileReference[]
52775277
) {
5278-
const node = baseFactory.createBaseSourceFileNode(SyntaxKind.SourceFile) as Mutable<SourceFile>;
5278+
const node = (source.redirectInfo ? Object.create(source.redirectInfo.redirectTarget) : baseFactory.createBaseSourceFileNode(SyntaxKind.SourceFile)) as Mutable<SourceFile>;
52795279
for (const p in source) {
52805280
if (p === "emitNode" || hasProperty(node, p) || !hasProperty(source, p)) continue;
52815281
(node as any)[p] = (source as any)[p];

src/testRunner/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@
154154
"unittests/tsc/incremental.ts",
155155
"unittests/tsc/listFilesOnly.ts",
156156
"unittests/tsc/projectReferences.ts",
157+
"unittests/tsc/redirect.ts",
157158
"unittests/tsc/runWithoutArgs.ts",
158159
"unittests/tscWatch/consoleClearing.ts",
159160
"unittests/tscWatch/emit.ts",
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
namespace ts {
2+
describe("unittests:: tsc:: redirect::", () => {
3+
verifyTsc({
4+
scenario: "redirect",
5+
subScenario: "when redirecting ts file",
6+
fs: () => loadProjectFromFiles({
7+
"/src/project/tsconfig.json": JSON.stringify({
8+
compilerOptions: {
9+
outDir: "out"
10+
},
11+
include: [
12+
"copy1/node_modules/target/*",
13+
"copy2/node_modules/target/*",
14+
]
15+
}),
16+
"/src/project/copy1/node_modules/target/index.ts": "export const a = 1;",
17+
"/src/project/copy1/node_modules/target/import.ts": `import {} from "./";`,
18+
"/src/project/copy1/node_modules/target/package.json": JSON.stringify({
19+
name: "target",
20+
version: "1.0.0",
21+
main: "index.js",
22+
}),
23+
"/src/project/copy2/node_modules/target/index.ts": "export const a = 1;",
24+
"/src/project/copy2/node_modules/target/import.ts": `import {} from "./";`,
25+
"/src/project/copy2/node_modules/target/package.json": JSON.stringify({
26+
name: "target",
27+
version: "1.0.0",
28+
main: "index.js",
29+
}),
30+
}),
31+
commandLineArgs: ["-p", "src/project"],
32+
});
33+
});
34+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
Input::
2+
//// [/lib/lib.d.ts]
3+
/// <reference no-default-lib="true"/>
4+
interface Boolean {}
5+
interface Function {}
6+
interface CallableFunction {}
7+
interface NewableFunction {}
8+
interface IArguments {}
9+
interface Number { toExponential: any; }
10+
interface Object {}
11+
interface RegExp {}
12+
interface String { charAt: any; }
13+
interface Array<T> { length: number; [n: number]: T; }
14+
interface ReadonlyArray<T> {}
15+
declare const console: { log(msg: any): void; };
16+
17+
//// [/src/project/copy1/node_modules/target/import.ts]
18+
import {} from "./";
19+
20+
//// [/src/project/copy1/node_modules/target/index.ts]
21+
export const a = 1;
22+
23+
//// [/src/project/copy1/node_modules/target/package.json]
24+
{"name":"target","version":"1.0.0","main":"index.js"}
25+
26+
//// [/src/project/copy2/node_modules/target/import.ts]
27+
import {} from "./";
28+
29+
//// [/src/project/copy2/node_modules/target/index.ts]
30+
export const a = 1;
31+
32+
//// [/src/project/copy2/node_modules/target/package.json]
33+
{"name":"target","version":"1.0.0","main":"index.js"}
34+
35+
//// [/src/project/tsconfig.json]
36+
{"compilerOptions":{"outDir":"out"},"include":["copy1/node_modules/target/*","copy2/node_modules/target/*"]}
37+
38+
39+
40+
Output::
41+
/lib/tsc -p src/project
42+
exitCode:: ExitStatus.Success
43+
44+
45+
//// [/src/project/out/copy1/node_modules/target/import.js]
46+
"use strict";
47+
exports.__esModule = true;
48+
49+
50+
//// [/src/project/out/copy1/node_modules/target/index.js]
51+
"use strict";
52+
exports.__esModule = true;
53+
exports.a = void 0;
54+
exports.a = 1;
55+
56+
57+
//// [/src/project/out/copy2/node_modules/target/import.js]
58+
"use strict";
59+
exports.__esModule = true;
60+
61+
62+
//// [/src/project/out/copy2/node_modules/target/index.js]
63+
"use strict";
64+
exports.__esModule = true;
65+
exports.a = void 0;
66+
exports.a = 1;
67+
68+

0 commit comments

Comments
 (0)