@@ -1051,14 +1051,6 @@ namespace ts {
1051
1051
return buildErrors ( syntaxDiagnostics , BuildResultFlags . SyntaxErrors , "Syntactic" ) ;
1052
1052
}
1053
1053
1054
- // Don't emit .d.ts if there are decl file errors
1055
- if ( getEmitDeclarations ( program . getCompilerOptions ( ) ) ) {
1056
- const declDiagnostics = program . getDeclarationDiagnostics ( ) ;
1057
- if ( declDiagnostics . length ) {
1058
- return buildErrors ( declDiagnostics , BuildResultFlags . DeclarationEmitErrors , "Declaration file" ) ;
1059
- }
1060
- }
1061
-
1062
1054
// Same as above but now for semantic diagnostics
1063
1055
const semanticDiagnostics = program . getSemanticDiagnostics ( ) ;
1064
1056
if ( semanticDiagnostics . length ) {
@@ -1067,29 +1059,39 @@ namespace ts {
1067
1059
1068
1060
let newestDeclarationFileContentChangedTime = minimumDate ;
1069
1061
let anyDtsChanged = false ;
1070
- let emitDiagnostics : Diagnostic [ ] | undefined ;
1071
- const reportEmitDiagnostic = ( d : Diagnostic ) => ( emitDiagnostics || ( emitDiagnostics = [ ] ) ) . push ( d ) ;
1072
- emitFilesAndReportErrors ( program , reportEmitDiagnostic , writeFileName , /*reportSummary*/ undefined , ( fileName , content , writeBom , onError ) => {
1062
+ let declDiagnostics : Diagnostic [ ] | undefined ;
1063
+ const reportDeclarationDiagnostics = ( d : Diagnostic ) => ( declDiagnostics || ( declDiagnostics = [ ] ) ) . push ( d ) ;
1064
+ const outputFiles : OutputFile [ ] = [ ] ;
1065
+ emitFilesAndReportErrors ( program , reportDeclarationDiagnostics , writeFileName , /*reportSummary*/ undefined , ( name , text , writeByteOrderMark ) => outputFiles . push ( { name, text, writeByteOrderMark } ) ) ;
1066
+ // Don't emit .d.ts if there are decl file errors
1067
+ if ( declDiagnostics ) {
1068
+ return buildErrors ( declDiagnostics , BuildResultFlags . DeclarationEmitErrors , "Declaration file" ) ;
1069
+ }
1070
+
1071
+ // Actual Emit
1072
+ const emitterDiagnostics = createDiagnosticCollection ( ) ;
1073
+ outputFiles . forEach ( ( { name, text, writeByteOrderMark } ) => {
1073
1074
let priorChangeTime : Date | undefined ;
1074
- if ( ! anyDtsChanged && isDeclarationFile ( fileName ) ) {
1075
+ if ( ! anyDtsChanged && isDeclarationFile ( name ) ) {
1075
1076
// Check for unchanged .d.ts files
1076
- if ( host . fileExists ( fileName ) && readFileWithCache ( fileName ) === content ) {
1077
- priorChangeTime = host . getModifiedTime ( fileName ) ;
1077
+ if ( host . fileExists ( name ) && readFileWithCache ( name ) === text ) {
1078
+ priorChangeTime = host . getModifiedTime ( name ) ;
1078
1079
}
1079
1080
else {
1080
1081
resultFlags &= ~ BuildResultFlags . DeclarationOutputUnchanged ;
1081
1082
anyDtsChanged = true ;
1082
1083
}
1083
1084
}
1084
1085
1085
- host . writeFile ( fileName , content , writeBom , onError , emptyArray ) ;
1086
+ writeFile ( host , emitterDiagnostics , name , text , writeByteOrderMark ) ;
1086
1087
if ( priorChangeTime !== undefined ) {
1087
1088
newestDeclarationFileContentChangedTime = newer ( priorChangeTime , newestDeclarationFileContentChangedTime ) ;
1088
- unchangedOutputs . setValue ( fileName , priorChangeTime ) ;
1089
+ unchangedOutputs . setValue ( name , priorChangeTime ) ;
1089
1090
}
1090
1091
} ) ;
1091
1092
1092
- if ( emitDiagnostics ) {
1093
+ const emitDiagnostics = emitterDiagnostics . getDiagnostics ( ) ;
1094
+ if ( emitDiagnostics . length ) {
1093
1095
return buildErrors ( emitDiagnostics , BuildResultFlags . EmitErrors , "Emit" ) ;
1094
1096
}
1095
1097
0 commit comments