Skip to content

Commit 602aec2

Browse files
committed
Never create redirect for sourceFiles that get emitted to single output file
Fixes microsoft#30591
1 parent b559e81 commit 602aec2

File tree

3 files changed

+598
-7
lines changed

3 files changed

+598
-7
lines changed

src/compiler/program.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2266,8 +2266,13 @@ namespace ts {
22662266

22672267
let redirectedPath: Path | undefined;
22682268
if (refFile) {
2269-
const redirect = getProjectReferenceRedirect(fileName);
2270-
if (redirect) {
2269+
const redirectProject = getProjectReferenceRedirectProject(fileName);
2270+
if (redirectProject) {
2271+
if (redirectProject.commandLine.options.outFile || redirectProject.commandLine.options.out) {
2272+
// Shouldnt create many to 1 mapping file in --out scenario
2273+
return undefined;
2274+
}
2275+
const redirect = getProjectReferenceOutputName(redirectProject, fileName);
22712276
fileName = redirect;
22722277
// Once we start redirecting to a file, we can potentially come back to it
22732278
// via a back-reference from another file in the .d.ts folder. If that happens we'll
@@ -2364,17 +2369,23 @@ namespace ts {
23642369
}
23652370

23662371
function getProjectReferenceRedirect(fileName: string): string | undefined {
2372+
const referencedProject = getProjectReferenceRedirectProject(fileName);
2373+
return referencedProject && getProjectReferenceOutputName(referencedProject, fileName);
2374+
}
2375+
2376+
function getProjectReferenceRedirectProject(fileName: string) {
23672377
// Ignore dts or any of the non ts files
23682378
if (!resolvedProjectReferences || !resolvedProjectReferences.length || fileExtensionIs(fileName, Extension.Dts) || !fileExtensionIsOneOf(fileName, supportedTSExtensions)) {
23692379
return undefined;
23702380
}
23712381

23722382
// If this file is produced by a referenced project, we need to rewrite it to
23732383
// look in the output folder of the referenced project rather than the input
2374-
const referencedProject = getResolvedProjectReferenceToRedirect(fileName);
2375-
if (!referencedProject) {
2376-
return undefined;
2377-
}
2384+
return getResolvedProjectReferenceToRedirect(fileName);
2385+
}
2386+
2387+
2388+
function getProjectReferenceOutputName(referencedProject: ResolvedProjectReference, fileName: string) {
23782389
const out = referencedProject.commandLine.options.outFile || referencedProject.commandLine.options.out;
23792390
return out ?
23802391
changeExtension(out, Extension.Dts) :

src/testRunner/unittests/tsbuild/amdModulesWithOut.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,14 @@ ${internal} export enum internalEnum { a, b, c }`);
233233
],
234234
lastProjectOutputJs: outputFiles[project.app][ext.js],
235235
initialBuild: {
236-
modifyFs
236+
modifyFs,
237+
expectedDiagnostics: [
238+
getExpectedDiagnosticForProjectsInBuild("src/lib/tsconfig.json", "src/app/tsconfig.json"),
239+
[Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, "src/lib/tsconfig.json", "src/module.js"],
240+
[Diagnostics.Building_project_0, sources[project.lib][source.config]],
241+
[Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, "src/app/tsconfig.json", "src/app/module.js"],
242+
[Diagnostics.Building_project_0, sources[project.app][source.config]],
243+
]
237244
},
238245
outputFiles: [
239246
...libOutputFile,

0 commit comments

Comments
 (0)