@@ -403,6 +403,12 @@ namespace ts {
403
403
}
404
404
}
405
405
406
+ function clearAffectedFilesPendingEmit ( state : BuilderProgramState ) {
407
+ state . affectedFilesPendingEmit = undefined ;
408
+ state . affectedFilesPendingEmitKind = undefined ;
409
+ state . affectedFilesPendingEmitIndex = undefined ;
410
+ }
411
+
406
412
/**
407
413
* Returns next file to be emitted from files that retrieved semantic diagnostics but did not emit yet
408
414
*/
@@ -422,9 +428,7 @@ namespace ts {
422
428
}
423
429
}
424
430
}
425
- state . affectedFilesPendingEmit = undefined ;
426
- state . affectedFilesPendingEmitKind = undefined ;
427
- state . affectedFilesPendingEmitIndex = undefined ;
431
+ clearAffectedFilesPendingEmit ( state ) ;
428
432
}
429
433
return undefined ;
430
434
}
@@ -1101,57 +1105,47 @@ namespace ts {
1101
1105
* in that order would be used to write the files
1102
1106
*/
1103
1107
function emit ( targetSourceFile ?: SourceFile , writeFile ?: WriteFileCallback , cancellationToken ?: CancellationToken , emitOnlyDtsFiles ?: boolean , customTransformers ?: CustomTransformers ) : EmitResult {
1104
- let restorePendingEmitOnHandlingNoEmitSuccess = false ;
1105
- let savedAffectedFilesPendingEmit ;
1106
- let savedAffectedFilesPendingEmitKind ;
1107
- let savedAffectedFilesPendingEmitIndex ;
1108
- // 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
1109
- // This ensures pending files to emit is updated in tsbuildinfo
1110
- // 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)
1111
- if ( kind !== BuilderProgramKind . EmitAndSemanticDiagnosticsBuilderProgram &&
1112
- ! targetSourceFile &&
1113
- ! outFile ( state . compilerOptions ) &&
1114
- ! state . compilerOptions . noEmit &&
1115
- state . compilerOptions . noEmitOnError ) {
1116
- restorePendingEmitOnHandlingNoEmitSuccess = true ;
1117
- savedAffectedFilesPendingEmit = state . affectedFilesPendingEmit && state . affectedFilesPendingEmit . slice ( ) ;
1118
- savedAffectedFilesPendingEmitKind = state . affectedFilesPendingEmitKind && new Map ( state . affectedFilesPendingEmitKind ) ;
1119
- savedAffectedFilesPendingEmitIndex = state . affectedFilesPendingEmitIndex ;
1120
- }
1121
-
1122
1108
if ( kind === BuilderProgramKind . EmitAndSemanticDiagnosticsBuilderProgram ) {
1123
1109
assertSourceFileOkWithoutNextAffectedCall ( state , targetSourceFile ) ;
1124
1110
}
1125
1111
const result = handleNoEmitOptions ( builderProgram , targetSourceFile , writeFile , cancellationToken ) ;
1126
1112
if ( result ) return result ;
1127
1113
1128
- if ( restorePendingEmitOnHandlingNoEmitSuccess ) {
1129
- state . affectedFilesPendingEmit = savedAffectedFilesPendingEmit ;
1130
- state . affectedFilesPendingEmitKind = savedAffectedFilesPendingEmitKind ;
1131
- state . affectedFilesPendingEmitIndex = savedAffectedFilesPendingEmitIndex ;
1132
- }
1133
-
1134
1114
// Emit only affected files if using builder for emit
1135
- if ( ! targetSourceFile && kind === BuilderProgramKind . EmitAndSemanticDiagnosticsBuilderProgram ) {
1136
- // Emit and report any errors we ran into.
1137
- let sourceMaps : SourceMapEmitResult [ ] = [ ] ;
1138
- let emitSkipped = false ;
1139
- let diagnostics : Diagnostic [ ] | undefined ;
1140
- let emittedFiles : string [ ] = [ ] ;
1141
-
1142
- let affectedEmitResult : AffectedFileResult < EmitResult > ;
1143
- while ( affectedEmitResult = emitNextAffectedFile ( writeFile , cancellationToken , emitOnlyDtsFiles , customTransformers ) ) {
1144
- emitSkipped = emitSkipped || affectedEmitResult . result . emitSkipped ;
1145
- diagnostics = addRange ( diagnostics , affectedEmitResult . result . diagnostics ) ;
1146
- emittedFiles = addRange ( emittedFiles , affectedEmitResult . result . emittedFiles ) ;
1147
- sourceMaps = addRange ( sourceMaps , affectedEmitResult . result . sourceMaps ) ;
1115
+ if ( ! targetSourceFile ) {
1116
+ if ( kind === BuilderProgramKind . EmitAndSemanticDiagnosticsBuilderProgram ) {
1117
+ // Emit and report any errors we ran into.
1118
+ let sourceMaps : SourceMapEmitResult [ ] = [ ] ;
1119
+ let emitSkipped = false ;
1120
+ let diagnostics : Diagnostic [ ] | undefined ;
1121
+ let emittedFiles : string [ ] = [ ] ;
1122
+
1123
+ let affectedEmitResult : AffectedFileResult < EmitResult > ;
1124
+ while ( affectedEmitResult = emitNextAffectedFile ( writeFile , cancellationToken , emitOnlyDtsFiles , customTransformers ) ) {
1125
+ emitSkipped = emitSkipped || affectedEmitResult . result . emitSkipped ;
1126
+ diagnostics = addRange ( diagnostics , affectedEmitResult . result . diagnostics ) ;
1127
+ emittedFiles = addRange ( emittedFiles , affectedEmitResult . result . emittedFiles ) ;
1128
+ sourceMaps = addRange ( sourceMaps , affectedEmitResult . result . sourceMaps ) ;
1129
+ }
1130
+ return {
1131
+ emitSkipped,
1132
+ diagnostics : diagnostics || emptyArray ,
1133
+ emittedFiles,
1134
+ sourceMaps
1135
+ } ;
1136
+ }
1137
+ // In non Emit builder, clear affected files pending emit
1138
+ else if ( state . affectedFilesPendingEmitKind ?. size ) {
1139
+ Debug . assert ( kind === BuilderProgramKind . SemanticDiagnosticsBuilderProgram ) ;
1140
+ // State can clear affected files pending emit if
1141
+ if ( ! emitOnlyDtsFiles // If we are doing complete emit, affected files pending emit can be cleared
1142
+ // If every file pending emit is pending on only dts emit
1143
+ || every ( state . affectedFilesPendingEmit , ( path , index ) =>
1144
+ index < state . affectedFilesPendingEmitIndex ! ||
1145
+ state . affectedFilesPendingEmitKind ! . get ( path ) === BuilderFileEmit . DtsOnly ) ) {
1146
+ clearAffectedFilesPendingEmit ( state ) ;
1147
+ }
1148
1148
}
1149
- return {
1150
- emitSkipped,
1151
- diagnostics : diagnostics || emptyArray ,
1152
- emittedFiles,
1153
- sourceMaps
1154
- } ;
1155
1149
}
1156
1150
return Debug . checkDefined ( state . program ) . emit ( targetSourceFile , writeFile || maybeBind ( host , host . writeFile ) , cancellationToken , emitOnlyDtsFiles , customTransformers ) ;
1157
1151
}
0 commit comments