@@ -6,9 +6,19 @@ namespace ts {
6
6
fileWatcher ?: FileWatcher ;
7
7
}
8
8
9
- let reportDiagnostic = reportDiagnosticSimply ;
9
+ const defaultFormatDiagnosticsHost : FormatDiagnosticsHost = {
10
+ getCurrentDirectory : ( ) => sys . getCurrentDirectory ( ) ,
11
+ getNewLine : ( ) => sys . newLine ,
12
+ getCanonicalFileName : createGetCanonicalFileName ( sys . useCaseSensitiveFileNames )
13
+ } ;
14
+
15
+ let reportDiagnosticWorker = reportDiagnosticSimply ;
16
+
17
+ function reportDiagnostic ( diagnostic : Diagnostic , host : FormatDiagnosticsHost ) {
18
+ reportDiagnosticWorker ( diagnostic , host || defaultFormatDiagnosticsHost ) ;
19
+ }
10
20
11
- function reportDiagnostics ( diagnostics : Diagnostic [ ] , host : CompilerHost ) : void {
21
+ function reportDiagnostics ( diagnostics : Diagnostic [ ] , host : FormatDiagnosticsHost ) : void {
12
22
for ( const diagnostic of diagnostics ) {
13
23
reportDiagnostic ( diagnostic , host ) ;
14
24
}
@@ -101,7 +111,7 @@ namespace ts {
101
111
return < string > diagnostic . messageText ;
102
112
}
103
113
104
- function reportDiagnosticSimply ( diagnostic : Diagnostic , host : CompilerHost ) : void {
114
+ function reportDiagnosticSimply ( diagnostic : Diagnostic , host : FormatDiagnosticsHost ) : void {
105
115
sys . write ( ts . formatDiagnostics ( [ diagnostic ] , host ) ) ;
106
116
}
107
117
@@ -122,7 +132,7 @@ namespace ts {
122
132
return formatStyle + text + resetEscapeSequence ;
123
133
}
124
134
125
- function reportDiagnosticWithColorAndContext ( diagnostic : Diagnostic , host : CompilerHost ) : void {
135
+ function reportDiagnosticWithColorAndContext ( diagnostic : Diagnostic , host : FormatDiagnosticsHost ) : void {
126
136
let output = "" ;
127
137
128
138
if ( diagnostic . file ) {
@@ -257,7 +267,7 @@ namespace ts {
257
267
258
268
if ( commandLine . options . locale ) {
259
269
if ( ! isJSONSupported ( ) ) {
260
- reportDiagnostic ( createCompilerDiagnostic ( Diagnostics . The_current_host_does_not_support_the_0_option , "--locale" ) , /* compilerHost */ undefined ) ;
270
+ reportDiagnostic ( createCompilerDiagnostic ( Diagnostics . The_current_host_does_not_support_the_0_option , "--locale" ) , /* host */ undefined ) ;
261
271
return sys . exit ( ExitStatus . DiagnosticsPresent_OutputsSkipped ) ;
262
272
}
263
273
validateLocaleAndSetLanguage ( commandLine . options . locale , commandLine . errors ) ;
@@ -288,26 +298,26 @@ namespace ts {
288
298
289
299
if ( commandLine . options . project ) {
290
300
if ( ! isJSONSupported ( ) ) {
291
- reportDiagnostic ( createCompilerDiagnostic ( Diagnostics . The_current_host_does_not_support_the_0_option , "--project" ) , /* compilerHost */ undefined ) ;
301
+ reportDiagnostic ( createCompilerDiagnostic ( Diagnostics . The_current_host_does_not_support_the_0_option , "--project" ) , /* host */ undefined ) ;
292
302
return sys . exit ( ExitStatus . DiagnosticsPresent_OutputsSkipped ) ;
293
303
}
294
304
if ( commandLine . fileNames . length !== 0 ) {
295
- reportDiagnostic ( createCompilerDiagnostic ( Diagnostics . Option_project_cannot_be_mixed_with_source_files_on_a_command_line ) , /* compilerHost */ undefined ) ;
305
+ reportDiagnostic ( createCompilerDiagnostic ( Diagnostics . Option_project_cannot_be_mixed_with_source_files_on_a_command_line ) , /* host */ undefined ) ;
296
306
return sys . exit ( ExitStatus . DiagnosticsPresent_OutputsSkipped ) ;
297
307
}
298
308
299
309
const fileOrDirectory = normalizePath ( commandLine . options . project ) ;
300
310
if ( ! fileOrDirectory /* current directory "." */ || sys . directoryExists ( fileOrDirectory ) ) {
301
311
configFileName = combinePaths ( fileOrDirectory , "tsconfig.json" ) ;
302
312
if ( ! sys . fileExists ( configFileName ) ) {
303
- reportDiagnostic ( createCompilerDiagnostic ( Diagnostics . Cannot_find_a_tsconfig_json_file_at_the_specified_directory_Colon_0 , commandLine . options . project ) , /* compilerHost */ undefined ) ;
313
+ reportDiagnostic ( createCompilerDiagnostic ( Diagnostics . Cannot_find_a_tsconfig_json_file_at_the_specified_directory_Colon_0 , commandLine . options . project ) , /* host */ undefined ) ;
304
314
return sys . exit ( ExitStatus . DiagnosticsPresent_OutputsSkipped ) ;
305
315
}
306
316
}
307
317
else {
308
318
configFileName = fileOrDirectory ;
309
319
if ( ! sys . fileExists ( configFileName ) ) {
310
- reportDiagnostic ( createCompilerDiagnostic ( Diagnostics . The_specified_path_does_not_exist_Colon_0 , commandLine . options . project ) , /* compilerHost */ undefined ) ;
320
+ reportDiagnostic ( createCompilerDiagnostic ( Diagnostics . The_specified_path_does_not_exist_Colon_0 , commandLine . options . project ) , /* host */ undefined ) ;
311
321
return sys . exit ( ExitStatus . DiagnosticsPresent_OutputsSkipped ) ;
312
322
}
313
323
}
@@ -325,7 +335,7 @@ namespace ts {
325
335
326
336
if ( isWatchSet ( commandLine . options ) ) {
327
337
if ( ! sys . watchFile ) {
328
- reportDiagnostic ( createCompilerDiagnostic ( Diagnostics . The_current_host_does_not_support_the_0_option , "--watch" ) , /* compilerHost */ undefined ) ;
338
+ reportDiagnostic ( createCompilerDiagnostic ( Diagnostics . The_current_host_does_not_support_the_0_option , "--watch" ) , /* host */ undefined ) ;
329
339
return sys . exit ( ExitStatus . DiagnosticsPresent_OutputsSkipped ) ;
330
340
}
331
341
if ( configFileName ) {
@@ -378,7 +388,7 @@ namespace ts {
378
388
}
379
389
if ( isWatchSet ( configParseResult . options ) ) {
380
390
if ( ! sys . watchFile ) {
381
- reportDiagnostic ( createCompilerDiagnostic ( Diagnostics . The_current_host_does_not_support_the_0_option , "--watch" ) , /* compilerHost */ undefined ) ;
391
+ reportDiagnostic ( createCompilerDiagnostic ( Diagnostics . The_current_host_does_not_support_the_0_option , "--watch" ) , /* host */ undefined ) ;
382
392
sys . exit ( ExitStatus . DiagnosticsPresent_OutputsSkipped ) ;
383
393
}
384
394
@@ -417,7 +427,7 @@ namespace ts {
417
427
}
418
428
419
429
if ( compilerOptions . pretty ) {
420
- reportDiagnostic = reportDiagnosticWithColorAndContext ;
430
+ reportDiagnosticWorker = reportDiagnosticWithColorAndContext ;
421
431
}
422
432
423
433
// reset the cache of existing files
@@ -742,7 +752,7 @@ namespace ts {
742
752
const currentDirectory = sys . getCurrentDirectory ( ) ;
743
753
const file = normalizePath ( combinePaths ( currentDirectory , "tsconfig.json" ) ) ;
744
754
if ( sys . fileExists ( file ) ) {
745
- reportDiagnostic ( createCompilerDiagnostic ( Diagnostics . A_tsconfig_json_file_is_already_defined_at_Colon_0 , file ) , /* compilerHost */ undefined ) ;
755
+ reportDiagnostic ( createCompilerDiagnostic ( Diagnostics . A_tsconfig_json_file_is_already_defined_at_Colon_0 , file ) , /* host */ undefined ) ;
746
756
}
747
757
else {
748
758
const compilerOptions = extend ( options , defaultInitCompilerOptions ) ;
@@ -762,7 +772,7 @@ namespace ts {
762
772
}
763
773
764
774
sys . writeFile ( file , JSON . stringify ( configurations , undefined , 4 ) ) ;
765
- reportDiagnostic ( createCompilerDiagnostic ( Diagnostics . Successfully_created_a_tsconfig_json_file ) , /* compilerHost */ undefined ) ;
775
+ reportDiagnostic ( createCompilerDiagnostic ( Diagnostics . Successfully_created_a_tsconfig_json_file ) , /* host */ undefined ) ;
766
776
}
767
777
768
778
return ;
0 commit comments