@@ -33,9 +33,8 @@ namespace ts {
3333
3434 const nonClearingMessageCodes : number [ ] = [
3535 Diagnostics . Compilation_complete_Watching_for_file_changes . code ,
36- Diagnostics . Found_1_error_in_1_file . code ,
37- Diagnostics . Found_0_errors_in_1_file . code ,
38- Diagnostics . Found_0_errors_in_1_files . code ,
36+ Diagnostics . Found_1_error . code ,
37+ Diagnostics . Found_0_errors . code
3938 ] ;
4039
4140 function clearScreenIfNotWatchingForFileChanges ( system : System , diagnostic : Diagnostic , options : CompilerOptions ) {
@@ -135,7 +134,12 @@ namespace ts {
135134 }
136135
137136 /** @internal */
138- export function getProgramDiagnosticsAndEmit ( program : ProgramToEmitFilesAndReportErrors ) : ProgramDiagnosticsAndEmit {
137+ export type ReportEmitErrorSummary = ( errorCount : number ) => void ;
138+
139+ /**
140+ * Helper that emit files, report diagnostics and lists emitted and/or source files depending on compiler options
141+ */
142+ export function emitFilesAndReportErrors ( program : ProgramToEmitFilesAndReportErrors , reportDiagnostic : DiagnosticReporter , reportSummary ?: ReportEmitErrorSummary , writeFileName ?: ( s : string ) => void ) {
139143 // First get and report any syntactic errors.
140144 const diagnostics = program . getSyntacticDiagnostics ( ) . slice ( ) ;
141145 let reportSemanticDiagnostics = false ;
@@ -159,15 +163,6 @@ namespace ts {
159163 addRange ( diagnostics , program . getSemanticDiagnostics ( ) ) ;
160164 }
161165
162- return { diagnostics, emittedFiles, emitSkipped } ;
163- }
164-
165- /**
166- * Helper that emit files, report diagnostics and lists emitted and/or source files depending on compiler options
167- */
168- export function reportDiagnosticErrors ( program : ProgramToEmitFilesAndReportErrors , diagnosticsAndEmit : ProgramDiagnosticsAndEmit , reportDiagnostic : DiagnosticReporter , writeFileName ?: ( s : string ) => void ) {
169- const { diagnostics, emittedFiles, emitSkipped } = diagnosticsAndEmit ;
170-
171166 sortAndDeduplicateDiagnostics ( diagnostics ) . forEach ( reportDiagnostic ) ;
172167 if ( writeFileName ) {
173168 const currentDir = program . getCurrentDirectory ( ) ;
@@ -183,6 +178,10 @@ namespace ts {
183178 }
184179 }
185180
181+ if ( reportSummary ) {
182+ reportSummary ( diagnostics . filter ( diagnostic => diagnostic . category === DiagnosticCategory . Error ) . length ) ;
183+ }
184+
186185 if ( emitSkipped && diagnostics . length > 0 ) {
187186 // If the emitter didn't emit anything, then pass that value along.
188187 return ExitStatus . DiagnosticsPresent_OutputsSkipped ;
@@ -195,34 +194,6 @@ namespace ts {
195194 return ExitStatus . Success ;
196195 }
197196
198- function summarizeDiagnosticsAcrossFiles ( diagnostics : Diagnostic [ ] , reporter : WatchStatusReporter , newLine : string , compilerOptions : CompilerOptions ) : void {
199- if ( diagnostics . length === 1 ) {
200- reporter ( createCompilerDiagnostic ( Diagnostics . Found_1_error_in_1_file ) , newLine , compilerOptions ) ;
201- return ;
202- }
203-
204- const uniqueFileNamesCount = countUniqueDiagnosticFileNames ( diagnostics ) ;
205-
206- if ( uniqueFileNamesCount === 1 ) {
207- reporter ( createCompilerDiagnostic ( Diagnostics . Found_0_errors_in_1_file , diagnostics . length ) , newLine , compilerOptions ) ;
208- }
209- else if ( uniqueFileNamesCount !== 0 ) {
210- reporter ( createCompilerDiagnostic ( Diagnostics . Found_0_errors_in_1_files , diagnostics . length , uniqueFileNamesCount ) , newLine , compilerOptions ) ;
211- }
212- }
213-
214- function countUniqueDiagnosticFileNames ( diagnostics : Diagnostic [ ] ) : number {
215- const fileNames = createMap < boolean > ( ) ;
216-
217- for ( const diagnostic of diagnostics ) {
218- if ( diagnostic . file ) {
219- fileNames . set ( diagnostic . file . fileName , true ) ;
220- }
221- }
222-
223- return fileNames . size ;
224- }
225-
226197 const noopFileWatcher : FileWatcher = { close : noop } ;
227198
228199 /**
@@ -269,13 +240,21 @@ namespace ts {
269240 }
270241
271242 function emitFilesAndReportErrorUsingBuilder ( builderProgram : BuilderProgram ) {
272- const diagnosticsAndEmit = getProgramDiagnosticsAndEmit ( builderProgram ) ;
273- reportDiagnosticErrors ( builderProgram , diagnosticsAndEmit , reportDiagnostic , writeFileName ) ;
274-
243+ let reportSummary : ReportEmitErrorSummary | undefined ;
275244 const compilerOptions = builderProgram . getCompilerOptions ( ) ;
245+
276246 if ( compilerOptions . pretty ) {
277- summarizeDiagnosticsAcrossFiles ( diagnosticsAndEmit . diagnostics , onWatchStatusChange , system . newLine , compilerOptions ) ;
247+ reportSummary = ( errorCount : number ) => {
248+ if ( errorCount === 1 ) {
249+ onWatchStatusChange ( createCompilerDiagnostic ( Diagnostics . Found_1_error , errorCount ) , sys . newLine , compilerOptions ) ;
250+ }
251+ else {
252+ onWatchStatusChange ( createCompilerDiagnostic ( Diagnostics . Found_0_errors , errorCount , errorCount ) , sys . newLine , compilerOptions ) ;
253+ }
254+ } ;
278255 }
256+
257+ emitFilesAndReportErrors ( builderProgram , reportDiagnostic , reportSummary , writeFileName ) ;
279258 }
280259 }
281260
0 commit comments