When source file is redirected, set the prototype correctly in node factory (#48862)

Fixes #48039
This commit is contained in:
Sheetal Nandi 2022-05-04 08:59:11 -07:00 committed by GitHub
parent d879880a37
commit c8ec855f9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 104 additions and 1 deletions

View File

@ -5275,7 +5275,7 @@ namespace ts {
hasNoDefaultLib: boolean,
libReferences: readonly FileReference[]
) {
const node = baseFactory.createBaseSourceFileNode(SyntaxKind.SourceFile) as Mutable<SourceFile>;
const node = (source.redirectInfo ? Object.create(source.redirectInfo.redirectTarget) : baseFactory.createBaseSourceFileNode(SyntaxKind.SourceFile)) as Mutable<SourceFile>;
for (const p in source) {
if (p === "emitNode" || hasProperty(node, p) || !hasProperty(source, p)) continue;
(node as any)[p] = (source as any)[p];

View File

@ -154,6 +154,7 @@
"unittests/tsc/incremental.ts",
"unittests/tsc/listFilesOnly.ts",
"unittests/tsc/projectReferences.ts",
"unittests/tsc/redirect.ts",
"unittests/tsc/runWithoutArgs.ts",
"unittests/tscWatch/consoleClearing.ts",
"unittests/tscWatch/emit.ts",

View File

@ -0,0 +1,34 @@
namespace ts {
describe("unittests:: tsc:: redirect::", () => {
verifyTsc({
scenario: "redirect",
subScenario: "when redirecting ts file",
fs: () => loadProjectFromFiles({
"/src/project/tsconfig.json": JSON.stringify({
compilerOptions: {
outDir: "out"
},
include: [
"copy1/node_modules/target/*",
"copy2/node_modules/target/*",
]
}),
"/src/project/copy1/node_modules/target/index.ts": "export const a = 1;",
"/src/project/copy1/node_modules/target/import.ts": `import {} from "./";`,
"/src/project/copy1/node_modules/target/package.json": JSON.stringify({
name: "target",
version: "1.0.0",
main: "index.js",
}),
"/src/project/copy2/node_modules/target/index.ts": "export const a = 1;",
"/src/project/copy2/node_modules/target/import.ts": `import {} from "./";`,
"/src/project/copy2/node_modules/target/package.json": JSON.stringify({
name: "target",
version: "1.0.0",
main: "index.js",
}),
}),
commandLineArgs: ["-p", "src/project"],
});
});
}

View File

@ -0,0 +1,68 @@
Input::
//// [/lib/lib.d.ts]
/// <reference no-default-lib="true"/>
interface Boolean {}
interface Function {}
interface CallableFunction {}
interface NewableFunction {}
interface IArguments {}
interface Number { toExponential: any; }
interface Object {}
interface RegExp {}
interface String { charAt: any; }
interface Array<T> { length: number; [n: number]: T; }
interface ReadonlyArray<T> {}
declare const console: { log(msg: any): void; };
//// [/src/project/copy1/node_modules/target/import.ts]
import {} from "./";
//// [/src/project/copy1/node_modules/target/index.ts]
export const a = 1;
//// [/src/project/copy1/node_modules/target/package.json]
{"name":"target","version":"1.0.0","main":"index.js"}
//// [/src/project/copy2/node_modules/target/import.ts]
import {} from "./";
//// [/src/project/copy2/node_modules/target/index.ts]
export const a = 1;
//// [/src/project/copy2/node_modules/target/package.json]
{"name":"target","version":"1.0.0","main":"index.js"}
//// [/src/project/tsconfig.json]
{"compilerOptions":{"outDir":"out"},"include":["copy1/node_modules/target/*","copy2/node_modules/target/*"]}
Output::
/lib/tsc -p src/project
exitCode:: ExitStatus.Success
//// [/src/project/out/copy1/node_modules/target/import.js]
"use strict";
exports.__esModule = true;
//// [/src/project/out/copy1/node_modules/target/index.js]
"use strict";
exports.__esModule = true;
exports.a = void 0;
exports.a = 1;
//// [/src/project/out/copy2/node_modules/target/import.js]
"use strict";
exports.__esModule = true;
//// [/src/project/out/copy2/node_modules/target/index.js]
"use strict";
exports.__esModule = true;
exports.a = void 0;
exports.a = 1;