@@ -1050,14 +1050,6 @@ namespace ts {
1050
1050
return buildErrors ( syntaxDiagnostics , BuildResultFlags . SyntaxErrors , "Syntactic" ) ;
1051
1051
}
1052
1052
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
-
1061
1053
// Same as above but now for semantic diagnostics
1062
1054
const semanticDiagnostics = program . getSemanticDiagnostics ( ) ;
1063
1055
if ( semanticDiagnostics . length ) {
@@ -1066,29 +1058,39 @@ namespace ts {
1066
1058
1067
1059
let newestDeclarationFileContentChangedTime = minimumDate ;
1068
1060
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 } ) => {
1072
1073
let priorChangeTime : Date | undefined ;
1073
- if ( ! anyDtsChanged && isDeclarationFile ( fileName ) ) {
1074
+ if ( ! anyDtsChanged && isDeclarationFile ( name ) ) {
1074
1075
// 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 ) ;
1077
1078
}
1078
1079
else {
1079
1080
resultFlags &= ~ BuildResultFlags . DeclarationOutputUnchanged ;
1080
1081
anyDtsChanged = true ;
1081
1082
}
1082
1083
}
1083
1084
1084
- host . writeFile ( fileName , content , writeBom , onError , emptyArray ) ;
1085
+ writeFile ( host , emitterDiagnostics , name , text , writeByteOrderMark ) ;
1085
1086
if ( priorChangeTime !== undefined ) {
1086
1087
newestDeclarationFileContentChangedTime = newer ( priorChangeTime , newestDeclarationFileContentChangedTime ) ;
1087
- unchangedOutputs . setValue ( fileName , priorChangeTime ) ;
1088
+ unchangedOutputs . setValue ( name , priorChangeTime ) ;
1088
1089
}
1089
1090
} ) ;
1090
1091
1091
- if ( emitDiagnostics ) {
1092
+ const emitDiagnostics = emitterDiagnostics . getDiagnostics ( ) ;
1093
+ if ( emitDiagnostics . length ) {
1092
1094
return buildErrors ( emitDiagnostics , BuildResultFlags . EmitErrors , "Emit" ) ;
1093
1095
}
1094
1096
0 commit comments