Skip to content

Commit 4fa1d78

Browse files
committed
Fix tsbuildinfo emit with SemanticDiagnosticsBuilder on noEmitOnError
1 parent 0fd4a08 commit 4fa1d78

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

src/compiler/builder.ts

+25-1
Original file line numberDiff line numberDiff line change
@@ -1019,10 +1019,34 @@ namespace ts {
10191019
* in that order would be used to write the files
10201020
*/
10211021
function emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback, cancellationToken?: CancellationToken, emitOnlyDtsFiles?: boolean, customTransformers?: CustomTransformers): EmitResult {
1022+
let restorePendingEmitOnHandlingNoEmitSuccess = false;
1023+
let savedAffectedFilesPendingEmit;
1024+
let savedAffectedFilesPendingEmitKind;
1025+
let savedAffectedFilesPendingEmitIndex;
1026+
// Backup and restore affected pendings emit state for non emit Builder if noEmitOnError is enabled and emitBuildInfo could be written in case there are errors
1027+
// This ensures pending files to emit is updated in tsbuildinfo
1028+
// Note that when there are no errors, emit proceeds as if everything is emitted as it is callers reponsibility to write the files to disk if at all (because its builder that doesnt track files to emit)
1029+
if (kind !== BuilderProgramKind.EmitAndSemanticDiagnosticsBuilderProgram &&
1030+
!targetSourceFile &&
1031+
!outFile(state.compilerOptions) &&
1032+
!state.compilerOptions.noEmit &&
1033+
state.compilerOptions.noEmitOnError) {
1034+
restorePendingEmitOnHandlingNoEmitSuccess = true;
1035+
savedAffectedFilesPendingEmit = state.affectedFilesPendingEmit && state.affectedFilesPendingEmit.slice();
1036+
savedAffectedFilesPendingEmitKind = state.affectedFilesPendingEmitKind && new Map(state.affectedFilesPendingEmitKind);
1037+
savedAffectedFilesPendingEmitIndex = state.affectedFilesPendingEmitIndex;
1038+
}
1039+
10221040
if (kind === BuilderProgramKind.EmitAndSemanticDiagnosticsBuilderProgram) assertSourceFileOkWithoutNextAffectedCall(state, targetSourceFile);
10231041
const result = handleNoEmitOptions(builderProgram, targetSourceFile, writeFile, cancellationToken);
10241042
if (result) return result;
10251043

1044+
if (restorePendingEmitOnHandlingNoEmitSuccess) {
1045+
state.affectedFilesPendingEmit = savedAffectedFilesPendingEmit;
1046+
state.affectedFilesPendingEmitKind = savedAffectedFilesPendingEmitKind;
1047+
state.affectedFilesPendingEmitIndex = savedAffectedFilesPendingEmitIndex;
1048+
}
1049+
10261050
// Emit only affected files if using builder for emit
10271051
if (!targetSourceFile && kind === BuilderProgramKind.EmitAndSemanticDiagnosticsBuilderProgram) {
10281052
// Emit and report any errors we ran into.
@@ -1070,7 +1094,7 @@ namespace ts {
10701094

10711095
// Add file to affected file pending emit to handle for later emit time
10721096
// Apart for emit builder do this for tsbuildinfo, do this for non emit builder when noEmit is set as tsbuildinfo is written and reused between emitters
1073-
if (kind === BuilderProgramKind.EmitAndSemanticDiagnosticsBuilderProgram || state.compilerOptions.noEmit) {
1097+
if (kind === BuilderProgramKind.EmitAndSemanticDiagnosticsBuilderProgram || state.compilerOptions.noEmit || state.compilerOptions.noEmitOnError) {
10741098
addToAffectedFilesPendingEmit(state, (affected as SourceFile).resolvedPath, BuilderFileEmit.Full);
10751099
}
10761100

0 commit comments

Comments
 (0)