@@ -21,10 +21,10 @@ namespace ts {
2121 return < string > diagnostic . messageText ;
2222 }
2323
24- let reportDiagnostic = createDiagnosticReporter ( sys , reportDiagnosticSimply ) ;
24+ let reportDiagnostic = createDiagnosticReporter ( ) ;
2525 function udpateReportDiagnostic ( options : CompilerOptions ) {
2626 if ( options . pretty ) {
27- reportDiagnostic = createDiagnosticReporter ( sys , reportDiagnosticWithColorAndContext ) ;
27+ reportDiagnostic = createDiagnosticReporter ( sys , /*pretty*/ true ) ;
2828 }
2929 }
3030
@@ -55,7 +55,7 @@ namespace ts {
5555 // If there are any errors due to command line parsing and/or
5656 // setting up localization, report them and quit.
5757 if ( commandLine . errors . length > 0 ) {
58- reportDiagnostics ( commandLine . errors , reportDiagnostic ) ;
58+ commandLine . errors . forEach ( reportDiagnostic ) ;
5959 return sys . exit ( ExitStatus . DiagnosticsPresent_OutputsSkipped ) ;
6060 }
6161
@@ -110,12 +110,11 @@ namespace ts {
110110
111111 const commandLineOptions = commandLine . options ;
112112 if ( configFileName ) {
113- const reportWatchDiagnostic = createWatchDiagnosticReporter ( ) ;
114- const configParseResult = parseConfigFile ( configFileName , commandLineOptions , sys , reportDiagnostic , reportWatchDiagnostic ) ;
113+ const configParseResult = parseConfigFile ( configFileName , commandLineOptions , sys , reportDiagnostic ) ;
115114 udpateReportDiagnostic ( configParseResult . options ) ;
116115 if ( isWatchSet ( configParseResult . options ) ) {
117116 reportWatchModeWithoutSysSupport ( ) ;
118- createWatchModeWithConfigFile ( configParseResult , commandLineOptions , createWatchingSystemHost ( reportWatchDiagnostic ) ) ;
117+ createWatchOfConfigFile ( configParseResult , commandLineOptions ) ;
119118 }
120119 else {
121120 performCompilation ( configParseResult . fileNames , configParseResult . options ) ;
@@ -125,7 +124,7 @@ namespace ts {
125124 udpateReportDiagnostic ( commandLineOptions ) ;
126125 if ( isWatchSet ( commandLineOptions ) ) {
127126 reportWatchModeWithoutSysSupport ( ) ;
128- createWatchModeWithoutConfigFile ( commandLine . fileNames , commandLineOptions , createWatchingSystemHost ( ) ) ;
127+ createWatchOfFilesAndCompilerOptions ( commandLine . fileNames , commandLineOptions ) ;
129128 }
130129 else {
131130 performCompilation ( commandLine . fileNames , commandLineOptions ) ;
@@ -151,15 +150,37 @@ namespace ts {
151150 return sys . exit ( exitStatus ) ;
152151 }
153152
154- function createWatchingSystemHost ( reportWatchDiagnostic ?: DiagnosticReporter ) {
155- const watchingHost = ts . createWatchingSystemHost ( /*pretty*/ undefined , sys , parseConfigFile , reportDiagnostic , reportWatchDiagnostic ) ;
156- watchingHost . beforeCompile = enableStatistics ;
157- const afterCompile = watchingHost . afterCompile ;
158- watchingHost . afterCompile = ( host , program ) => {
159- afterCompile ( host , program ) ;
153+ function createProgramCompilerWithBuilderState ( ) {
154+ const compilerWithBuilderState = ts . createProgramCompilerWithBuilderState ( sys , reportDiagnostic ) ;
155+ return ( host : DirectoryStructureHost , program : Program ) => {
156+ compilerWithBuilderState ( host , program ) ;
160157 reportStatistics ( program ) ;
161158 } ;
162- return watchingHost ;
159+ }
160+
161+ function createWatchOfConfigFile ( configParseResult : ParsedCommandLine , optionsToExtend : CompilerOptions ) {
162+ createWatch ( {
163+ system : sys ,
164+ beforeProgramCreate : enableStatistics ,
165+ afterProgramCreate : createProgramCompilerWithBuilderState ( ) ,
166+ onConfigFileDiagnostic : reportDiagnostic ,
167+ rootFiles : configParseResult . fileNames ,
168+ options : configParseResult . options ,
169+ configFileName : configParseResult . options . configFilePath ,
170+ optionsToExtend,
171+ configFileSpecs : configParseResult . configFileSpecs ,
172+ configFileWildCardDirectories : configParseResult . wildcardDirectories
173+ } ) ;
174+ }
175+
176+ function createWatchOfFilesAndCompilerOptions ( rootFiles : string [ ] , options : CompilerOptions ) {
177+ createWatch ( {
178+ system : sys ,
179+ beforeProgramCreate : enableStatistics ,
180+ afterProgramCreate : createProgramCompilerWithBuilderState ( ) ,
181+ rootFiles,
182+ options
183+ } ) ;
163184 }
164185
165186 function compileProgram ( program : Program ) : ExitStatus {
@@ -182,7 +203,18 @@ namespace ts {
182203 const { emittedFiles, emitSkipped, diagnostics : emitDiagnostics } = program . emit ( ) ;
183204 addRange ( diagnostics , emitDiagnostics ) ;
184205
185- return handleEmitOutputAndReportErrors ( sys , program , emittedFiles , emitSkipped , diagnostics , reportDiagnostic ) ;
206+ sortAndDeduplicateDiagnostics ( diagnostics ) . forEach ( reportDiagnostic ) ;
207+ writeFileAndEmittedFileList ( sys , program , emittedFiles ) ;
208+ if ( emitSkipped && diagnostics . length > 0 ) {
209+ // If the emitter didn't emit anything, then pass that value along.
210+ return ExitStatus . DiagnosticsPresent_OutputsSkipped ;
211+ }
212+ else if ( diagnostics . length > 0 ) {
213+ // The emitter emitted something, inform the caller if that happened in the presence
214+ // of diagnostics or not.
215+ return ExitStatus . DiagnosticsPresent_OutputsGenerated ;
216+ }
217+ return ExitStatus . Success ;
186218 }
187219
188220 function enableStatistics ( compilerOptions : CompilerOptions ) {
0 commit comments