diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 9a984b9a2f1..5d7c1bc1690 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -20,6 +20,17 @@ namespace ts { name: "diagnostics", type: "boolean", }, + { + name: "diagnosticStyle", + paramType: Diagnostics.KIND, + description: Diagnostics.Specify_diagnostic_printing_style_Colon_simple_default_or_pretty, + type: { + "simple": DiagnosticStyle.Simple, + "pretty": DiagnosticStyle.Pretty, + }, + error: Diagnostics.Argument_for_diagnosticStyle_must_be_simple_or_pretty, + experimental: true, + }, { name: "emitBOM", type: "boolean" diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 5ccc0a0db9b..4fdb2221762 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -567,6 +567,8 @@ namespace ts { Specifies_the_end_of_line_sequence_to_be_used_when_emitting_files_Colon_CRLF_dos_or_LF_unix: { code: 6060, category: DiagnosticCategory.Message, key: "Specifies the end of line sequence to be used when emitting files: 'CRLF' (dos) or 'LF' (unix)." }, NEWLINE: { code: 6061, category: DiagnosticCategory.Message, key: "NEWLINE" }, Argument_for_newLine_option_must_be_CRLF_or_LF: { code: 6062, category: DiagnosticCategory.Error, key: "Argument for '--newLine' option must be 'CRLF' or 'LF'." }, + Specify_diagnostic_printing_style_Colon_simple_default_or_pretty: { code: 6063, category: DiagnosticCategory.Message, key: "Specify diagnostic printing style: 'simple' (default) or 'pretty'." }, + Argument_for_diagnosticStyle_must_be_simple_or_pretty: { code: 6064, category: DiagnosticCategory.Error, key: "Argument for '--diagnosticStyle' must be 'simple' or 'pretty'." }, Specify_JSX_code_generation_Colon_preserve_or_react: { code: 6080, category: DiagnosticCategory.Message, key: "Specify JSX code generation: 'preserve' or 'react'" }, Argument_for_jsx_must_be_preserve_or_react: { code: 6081, category: DiagnosticCategory.Message, key: "Argument for '--jsx' must be 'preserve' or 'react'." }, Option_experimentalDecorators_must_also_be_specified_when_option_emitDecoratorMetadata_is_specified: { code: 6064, category: DiagnosticCategory.Error, key: "Option 'experimentalDecorators' must also be specified when option 'emitDecoratorMetadata' is specified." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index e138e2ddac4..4a7280f5fda 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2258,6 +2258,15 @@ "category": "Error", "code": 6062 }, + "Specify diagnostic printing style: 'simple' (default) or 'pretty'.": { + "category": "Message", + "code": 6063 + }, + "Argument for '--diagnosticStyle' must be 'simple' or 'pretty'.": { + "category": "Error", + "code": 6064 + }, + "Specify JSX code generation: 'preserve' or 'react'": { "category": "Message", "code": 6080 diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 10eddc41b7e..ae1a7cda220 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -6,9 +6,11 @@ namespace ts { fileWatcher?: FileWatcher; } - const reportDiagnostic = sys.writesToTty && sys.writesToTty() ? - reportDiagnosticWithColorAndContext : - reportDiagnosticSimply; + export interface CompilerOptions { + diagnosticStyle?: DiagnosticStyle; + } + + let reportDiagnostic = reportDiagnosticSimply; function reportDiagnostics(diagnostics: Diagnostic[]): void { for (let diagnostic of diagnostics) { @@ -221,7 +223,7 @@ namespace ts { if (commandLine.options.locale) { if (!isJSONSupported()) { - reportDiagnosticSimply(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--locale")); + reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--locale")); return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped); } validateLocaleAndSetLanguage(commandLine.options.locale, commandLine.errors); @@ -235,7 +237,7 @@ namespace ts { } if (commandLine.options.version) { - reportDiagnosticSimply(createCompilerDiagnostic(Diagnostics.Version_0, ts.version)); + reportDiagnostic(createCompilerDiagnostic(Diagnostics.Version_0, ts.version)); return sys.exit(ExitStatus.Success); } @@ -247,12 +249,12 @@ namespace ts { if (commandLine.options.project) { if (!isJSONSupported()) { - reportDiagnosticSimply(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--project")); + reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--project")); return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped); } configFileName = normalizePath(combinePaths(commandLine.options.project, "tsconfig.json")); if (commandLine.fileNames.length !== 0) { - reportDiagnosticSimply(createCompilerDiagnostic(Diagnostics.Option_project_cannot_be_mixed_with_source_files_on_a_command_line)); + reportDiagnostic(createCompilerDiagnostic(Diagnostics.Option_project_cannot_be_mixed_with_source_files_on_a_command_line)); return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped); } } @@ -270,7 +272,7 @@ namespace ts { // Firefox has Object.prototype.watch if (commandLine.options.watch && commandLine.options.hasOwnProperty("watch")) { if (!sys.watchFile) { - reportDiagnosticSimply(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--watch")); + reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--watch")); return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped); } if (configFileName) { @@ -288,7 +290,7 @@ namespace ts { let result = readConfigFile(configFileName); if (result.error) { - reportDiagnosticSimply(result.error); + reportDiagnostic(result.error); return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped); } @@ -310,6 +312,10 @@ namespace ts { compilerHost.getSourceFile = getSourceFile; } + if (compilerOptions.diagnosticStyle === DiagnosticStyle.Pretty) { + reportDiagnostic = reportDiagnosticWithColorAndContext; + } + let compileResult = compile(rootFileNames, compilerOptions, compilerHost); if (!compilerOptions.watch) { @@ -317,7 +323,7 @@ namespace ts { } setCachedProgram(compileResult.program); - reportDiagnosticSimply(createCompilerDiagnostic(Diagnostics.Compilation_complete_Watching_for_file_changes)); + reportDiagnostic(createCompilerDiagnostic(Diagnostics.Compilation_complete_Watching_for_file_changes)); } function getSourceFile(fileName: string, languageVersion: ScriptTarget, onError?: (message: string) => void) { @@ -379,7 +385,7 @@ namespace ts { function recompile() { timerHandle = undefined; - reportDiagnosticSimply(createCompilerDiagnostic(Diagnostics.File_change_detected_Starting_incremental_compilation)); + reportDiagnostic(createCompilerDiagnostic(Diagnostics.File_change_detected_Starting_incremental_compilation)); performCompilation(); } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 1338d19e1a7..01a791237ad 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2094,6 +2094,12 @@ namespace ts { JSX } + /* @internal */ + export const enum DiagnosticStyle { + Simple, + Pretty, + } + export interface ParsedCommandLine { options: CompilerOptions; fileNames: string[];