diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index edb2917f7eb..dcb17d34723 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -3472,18 +3472,14 @@ "category": "Message", "code": 6190 }, - "Found 1 error in 1 file.": { + "Found 1 error.": { "category": "Message", "code": 6191 }, - "Found {0} errors in 1 file.": { + "Found {0} errors.": { "category": "Message", "code": 6192 }, - "Found {0} errors in {1} files.": { - "category": "Message", - "code": 6193 - }, "Variable '{0}' implicitly has an '{1}' type.": { "category": "Error", "code": 7005 diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 2b0008f19c6..15e4867d7f7 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -144,8 +144,7 @@ namespace ts { enableStatistics(compilerOptions); const program = createProgram(rootFileNames, compilerOptions, compilerHost); - const diagnosticsAndEmit = getProgramDiagnosticsAndEmit(program); - const exitStatus = reportDiagnosticErrors(program, diagnosticsAndEmit, reportDiagnostic, s => sys.write(s + sys.newLine)); + const exitStatus = emitFilesAndReportErrors(program, reportDiagnostic, s => sys.write(s + sys.newLine)); reportStatistics(program); return sys.exit(exitStatus); } diff --git a/src/compiler/watch.ts b/src/compiler/watch.ts index 138ac628e6d..0382f17f9dc 100644 --- a/src/compiler/watch.ts +++ b/src/compiler/watch.ts @@ -33,9 +33,8 @@ namespace ts { const nonClearingMessageCodes: number[] = [ Diagnostics.Compilation_complete_Watching_for_file_changes.code, - Diagnostics.Found_1_error_in_1_file.code, - Diagnostics.Found_0_errors_in_1_file.code, - Diagnostics.Found_0_errors_in_1_files.code, + Diagnostics.Found_1_error.code, + Diagnostics.Found_0_errors.code ]; function clearScreenIfNotWatchingForFileChanges(system: System, diagnostic: Diagnostic, options: CompilerOptions) { @@ -135,7 +134,12 @@ namespace ts { } /** @internal */ - export function getProgramDiagnosticsAndEmit(program: ProgramToEmitFilesAndReportErrors): ProgramDiagnosticsAndEmit { + export type ReportEmitErrorSummary = (errorCount: number) => void; + + /** + * Helper that emit files, report diagnostics and lists emitted and/or source files depending on compiler options + */ + export function emitFilesAndReportErrors(program: ProgramToEmitFilesAndReportErrors, reportDiagnostic: DiagnosticReporter, reportSummary?: ReportEmitErrorSummary, writeFileName?: (s: string) => void) { // First get and report any syntactic errors. const diagnostics = program.getSyntacticDiagnostics().slice(); let reportSemanticDiagnostics = false; @@ -159,15 +163,6 @@ namespace ts { addRange(diagnostics, program.getSemanticDiagnostics()); } - return { diagnostics, emittedFiles, emitSkipped }; - } - - /** - * Helper that emit files, report diagnostics and lists emitted and/or source files depending on compiler options - */ - export function reportDiagnosticErrors(program: ProgramToEmitFilesAndReportErrors, diagnosticsAndEmit: ProgramDiagnosticsAndEmit, reportDiagnostic: DiagnosticReporter, writeFileName?: (s: string) => void) { - const { diagnostics, emittedFiles, emitSkipped } = diagnosticsAndEmit; - sortAndDeduplicateDiagnostics(diagnostics).forEach(reportDiagnostic); if (writeFileName) { const currentDir = program.getCurrentDirectory(); @@ -183,6 +178,10 @@ namespace ts { } } + if (reportSummary) { + reportSummary(diagnostics.filter(diagnostic => diagnostic.category === DiagnosticCategory.Error).length); + } + if (emitSkipped && diagnostics.length > 0) { // If the emitter didn't emit anything, then pass that value along. return ExitStatus.DiagnosticsPresent_OutputsSkipped; @@ -195,34 +194,6 @@ namespace ts { return ExitStatus.Success; } - function summarizeDiagnosticsAcrossFiles(diagnostics: Diagnostic[], reporter: WatchStatusReporter, newLine: string, compilerOptions: CompilerOptions): void { - if (diagnostics.length === 1) { - reporter(createCompilerDiagnostic(Diagnostics.Found_1_error_in_1_file), newLine, compilerOptions); - return; - } - - const uniqueFileNamesCount = countUniqueDiagnosticFileNames(diagnostics); - - if (uniqueFileNamesCount === 1) { - reporter(createCompilerDiagnostic(Diagnostics.Found_0_errors_in_1_file, diagnostics.length), newLine, compilerOptions); - } - else if (uniqueFileNamesCount !== 0) { - reporter(createCompilerDiagnostic(Diagnostics.Found_0_errors_in_1_files, diagnostics.length, uniqueFileNamesCount), newLine, compilerOptions); - } - } - - function countUniqueDiagnosticFileNames(diagnostics: Diagnostic[]): number { - const fileNames = createMap(); - - for (const diagnostic of diagnostics) { - if (diagnostic.file) { - fileNames.set(diagnostic.file.fileName, true); - } - } - - return fileNames.size; - } - const noopFileWatcher: FileWatcher = { close: noop }; /** @@ -269,13 +240,21 @@ namespace ts { } function emitFilesAndReportErrorUsingBuilder(builderProgram: BuilderProgram) { - const diagnosticsAndEmit = getProgramDiagnosticsAndEmit(builderProgram); - reportDiagnosticErrors(builderProgram, diagnosticsAndEmit, reportDiagnostic, writeFileName); - + let reportSummary: ReportEmitErrorSummary | undefined; const compilerOptions = builderProgram.getCompilerOptions(); + if (compilerOptions.pretty) { - summarizeDiagnosticsAcrossFiles(diagnosticsAndEmit.diagnostics, onWatchStatusChange, system.newLine, compilerOptions); + reportSummary = (errorCount: number) => { + if (errorCount === 1) { + onWatchStatusChange(createCompilerDiagnostic(Diagnostics.Found_1_error, errorCount), sys.newLine, compilerOptions); + } + else { + onWatchStatusChange(createCompilerDiagnostic(Diagnostics.Found_0_errors, errorCount, errorCount), sys.newLine, compilerOptions); + } + }; } + + emitFilesAndReportErrors(builderProgram, reportDiagnostic, reportSummary, writeFileName); } }