@@ -274,7 +274,7 @@ namespace ts {
274274 result . relatedInformation = relatedInformation ?
275275 relatedInformation . length ?
276276 relatedInformation . map ( r => convertToDiagnosticRelatedInformation ( r , newProgram , toPath ) ) :
277- emptyArray :
277+ [ ] :
278278 undefined ;
279279 return result ;
280280 } ) ;
@@ -824,7 +824,7 @@ namespace ts {
824824 result . relatedInformation = relatedInformation ?
825825 relatedInformation . length ?
826826 relatedInformation . map ( r => convertToReusableDiagnosticRelatedInformation ( r , relativeToBuildInfo ) ) :
827- emptyArray :
827+ [ ] :
828828 undefined ;
829829 return result ;
830830 } ) ;
@@ -900,7 +900,7 @@ namespace ts {
900900 /**
901901 * Computing hash to for signature verification
902902 */
903- const computeHash = host . createHash || generateDjb2Hash ;
903+ const computeHash = maybeBind ( host , host . createHash ) ;
904904 let state = createBuilderProgramState ( newProgram , getCanonicalFileName , oldState ) ;
905905 let backupState : BuilderProgramState | undefined ;
906906 newProgram . getProgramBuildInfo = ( ) => getProgramBuildInfo ( state , getCanonicalFileName ) ;
@@ -1019,31 +1019,57 @@ 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 ) {
10231041 assertSourceFileOkWithoutNextAffectedCall ( state , targetSourceFile ) ;
1024- const result = handleNoEmitOptions ( builderProgram , targetSourceFile , writeFile , cancellationToken ) ;
1025- if ( result ) return result ;
1026- if ( ! targetSourceFile ) {
1027- // Emit and report any errors we ran into.
1028- let sourceMaps : SourceMapEmitResult [ ] = [ ] ;
1029- let emitSkipped = false ;
1030- let diagnostics : Diagnostic [ ] | undefined ;
1031- let emittedFiles : string [ ] = [ ] ;
1032-
1033- let affectedEmitResult : AffectedFileResult < EmitResult > ;
1034- while ( affectedEmitResult = emitNextAffectedFile ( writeFile , cancellationToken , emitOnlyDtsFiles , customTransformers ) ) {
1035- emitSkipped = emitSkipped || affectedEmitResult . result . emitSkipped ;
1036- diagnostics = addRange ( diagnostics , affectedEmitResult . result . diagnostics ) ;
1037- emittedFiles = addRange ( emittedFiles , affectedEmitResult . result . emittedFiles ) ;
1038- sourceMaps = addRange ( sourceMaps , affectedEmitResult . result . sourceMaps ) ;
1039- }
1040- return {
1041- emitSkipped,
1042- diagnostics : diagnostics || emptyArray ,
1043- emittedFiles,
1044- sourceMaps
1045- } ;
1042+ }
1043+ const result = handleNoEmitOptions ( builderProgram , targetSourceFile , writeFile , cancellationToken ) ;
1044+ if ( result ) return result ;
1045+
1046+ if ( restorePendingEmitOnHandlingNoEmitSuccess ) {
1047+ state . affectedFilesPendingEmit = savedAffectedFilesPendingEmit ;
1048+ state . affectedFilesPendingEmitKind = savedAffectedFilesPendingEmitKind ;
1049+ state . affectedFilesPendingEmitIndex = savedAffectedFilesPendingEmitIndex ;
1050+ }
1051+
1052+ // Emit only affected files if using builder for emit
1053+ if ( ! targetSourceFile && kind === BuilderProgramKind . EmitAndSemanticDiagnosticsBuilderProgram ) {
1054+ // Emit and report any errors we ran into.
1055+ let sourceMaps : SourceMapEmitResult [ ] = [ ] ;
1056+ let emitSkipped = false ;
1057+ let diagnostics : Diagnostic [ ] | undefined ;
1058+ let emittedFiles : string [ ] = [ ] ;
1059+
1060+ let affectedEmitResult : AffectedFileResult < EmitResult > ;
1061+ while ( affectedEmitResult = emitNextAffectedFile ( writeFile , cancellationToken , emitOnlyDtsFiles , customTransformers ) ) {
1062+ emitSkipped = emitSkipped || affectedEmitResult . result . emitSkipped ;
1063+ diagnostics = addRange ( diagnostics , affectedEmitResult . result . diagnostics ) ;
1064+ emittedFiles = addRange ( emittedFiles , affectedEmitResult . result . emittedFiles ) ;
1065+ sourceMaps = addRange ( sourceMaps , affectedEmitResult . result . sourceMaps ) ;
10461066 }
1067+ return {
1068+ emitSkipped,
1069+ diagnostics : diagnostics || emptyArray ,
1070+ emittedFiles,
1071+ sourceMaps
1072+ } ;
10471073 }
10481074 return Debug . checkDefined ( state . program ) . emit ( targetSourceFile , writeFile || maybeBind ( host , host . writeFile ) , cancellationToken , emitOnlyDtsFiles , customTransformers ) ;
10491075 }
@@ -1069,7 +1095,8 @@ namespace ts {
10691095 }
10701096
10711097 // Add file to affected file pending emit to handle for later emit time
1072- if ( kind === BuilderProgramKind . EmitAndSemanticDiagnosticsBuilderProgram ) {
1098+ // 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
1099+ if ( kind === BuilderProgramKind . EmitAndSemanticDiagnosticsBuilderProgram || state . compilerOptions . noEmit || state . compilerOptions . noEmitOnError ) {
10731100 addToAffectedFilesPendingEmit ( state , ( affected as SourceFile ) . resolvedPath , BuilderFileEmit . Full ) ;
10741101 }
10751102
0 commit comments