@@ -1050,14 +1050,6 @@ namespace ts {
10501050 return buildErrors ( syntaxDiagnostics , BuildResultFlags . SyntaxErrors , "Syntactic" ) ;
10511051 }
10521052
1053- // Don't emit .d.ts if there are decl file errors
1054- if ( getEmitDeclarations ( program . getCompilerOptions ( ) ) ) {
1055- const declDiagnostics = program . getDeclarationDiagnostics ( ) ;
1056- if ( declDiagnostics . length ) {
1057- return buildErrors ( declDiagnostics , BuildResultFlags . DeclarationEmitErrors , "Declaration file" ) ;
1058- }
1059- }
1060-
10611053 // Same as above but now for semantic diagnostics
10621054 const semanticDiagnostics = program . getSemanticDiagnostics ( ) ;
10631055 if ( semanticDiagnostics . length ) {
@@ -1066,29 +1058,39 @@ namespace ts {
10661058
10671059 let newestDeclarationFileContentChangedTime = minimumDate ;
10681060 let anyDtsChanged = false ;
1069- let emitDiagnostics : Diagnostic [ ] | undefined ;
1070- const reportEmitDiagnostic = ( d : Diagnostic ) => ( emitDiagnostics || ( emitDiagnostics = [ ] ) ) . push ( d ) ;
1071- emitFilesAndReportErrors ( program , reportEmitDiagnostic , writeFileName , /*reportSummary*/ undefined , ( fileName , content , writeBom , onError ) => {
1061+ let declDiagnostics : Diagnostic [ ] | undefined ;
1062+ const reportDeclarationDiagnostics = ( d : Diagnostic ) => ( declDiagnostics || ( declDiagnostics = [ ] ) ) . push ( d ) ;
1063+ const outputFiles : OutputFile [ ] = [ ] ;
1064+ emitFilesAndReportErrors ( program , reportDeclarationDiagnostics , writeFileName , /*reportSummary*/ undefined , ( name , text , writeByteOrderMark ) => outputFiles . push ( { name, text, writeByteOrderMark } ) ) ;
1065+ // Don't emit .d.ts if there are decl file errors
1066+ if ( declDiagnostics ) {
1067+ return buildErrors ( declDiagnostics , BuildResultFlags . DeclarationEmitErrors , "Declaration file" ) ;
1068+ }
1069+
1070+ // Actual Emit
1071+ const emitterDiagnostics = createDiagnosticCollection ( ) ;
1072+ outputFiles . forEach ( ( { name, text, writeByteOrderMark } ) => {
10721073 let priorChangeTime : Date | undefined ;
1073- if ( ! anyDtsChanged && isDeclarationFile ( fileName ) ) {
1074+ if ( ! anyDtsChanged && isDeclarationFile ( name ) ) {
10741075 // Check for unchanged .d.ts files
1075- if ( host . fileExists ( fileName ) && host . readFile ( fileName ) === content ) {
1076- priorChangeTime = host . getModifiedTime ( fileName ) ;
1076+ if ( host . fileExists ( name ) && host . readFile ( name ) === text ) {
1077+ priorChangeTime = host . getModifiedTime ( name ) ;
10771078 }
10781079 else {
10791080 resultFlags &= ~ BuildResultFlags . DeclarationOutputUnchanged ;
10801081 anyDtsChanged = true ;
10811082 }
10821083 }
10831084
1084- host . writeFile ( fileName , content , writeBom , onError , emptyArray ) ;
1085+ writeFile ( host , emitterDiagnostics , name , text , writeByteOrderMark ) ;
10851086 if ( priorChangeTime !== undefined ) {
10861087 newestDeclarationFileContentChangedTime = newer ( priorChangeTime , newestDeclarationFileContentChangedTime ) ;
1087- unchangedOutputs . setValue ( fileName , priorChangeTime ) ;
1088+ unchangedOutputs . setValue ( name , priorChangeTime ) ;
10881089 }
10891090 } ) ;
10901091
1091- if ( emitDiagnostics ) {
1092+ const emitDiagnostics = emitterDiagnostics . getDiagnostics ( ) ;
1093+ if ( emitDiagnostics . length ) {
10921094 return buildErrors ( emitDiagnostics , BuildResultFlags . EmitErrors , "Emit" ) ;
10931095 }
10941096
0 commit comments