@@ -165,7 +165,7 @@ module ts {
165165 if ( commandLine . options . locale ) {
166166 if ( ! isJSONSupported ( ) ) {
167167 reportDiagnostic ( createCompilerDiagnostic ( Diagnostics . The_current_host_does_not_support_the_0_option , "--locale" ) ) ;
168- return sys . exit ( EmitReturnStatus . CompilerOptionsErrors ) ;
168+ return sys . exit ( ExitStatus . DiagnosticsPresent_OutputsSkipped ) ;
169169 }
170170 validateLocaleAndSetLanguage ( commandLine . options . locale , commandLine . errors ) ;
171171 }
@@ -174,29 +174,29 @@ module ts {
174174 // setting up localization, report them and quit.
175175 if ( commandLine . errors . length > 0 ) {
176176 reportDiagnostics ( commandLine . errors ) ;
177- return sys . exit ( EmitReturnStatus . CompilerOptionsErrors ) ;
177+ return sys . exit ( ExitStatus . DiagnosticsPresent_OutputsSkipped ) ;
178178 }
179179
180180 if ( commandLine . options . version ) {
181181 reportDiagnostic ( createCompilerDiagnostic ( Diagnostics . Version_0 , version ) ) ;
182- return sys . exit ( EmitReturnStatus . Succeeded ) ;
182+ return sys . exit ( ExitStatus . Success ) ;
183183 }
184184
185185 if ( commandLine . options . help ) {
186186 printVersion ( ) ;
187187 printHelp ( ) ;
188- return sys . exit ( EmitReturnStatus . Succeeded ) ;
188+ return sys . exit ( ExitStatus . Success ) ;
189189 }
190190
191191 if ( commandLine . options . project ) {
192192 if ( ! isJSONSupported ( ) ) {
193193 reportDiagnostic ( createCompilerDiagnostic ( Diagnostics . The_current_host_does_not_support_the_0_option , "--project" ) ) ;
194- return sys . exit ( EmitReturnStatus . CompilerOptionsErrors ) ;
194+ return sys . exit ( ExitStatus . DiagnosticsPresent_OutputsSkipped ) ;
195195 }
196196 configFileName = normalizePath ( combinePaths ( commandLine . options . project , "tsconfig.json" ) ) ;
197197 if ( commandLine . fileNames . length !== 0 ) {
198198 reportDiagnostic ( createCompilerDiagnostic ( Diagnostics . Option_project_cannot_be_mixed_with_source_files_on_a_command_line ) ) ;
199- return sys . exit ( EmitReturnStatus . CompilerOptionsErrors ) ;
199+ return sys . exit ( ExitStatus . DiagnosticsPresent_OutputsSkipped ) ;
200200 }
201201 }
202202 else if ( commandLine . fileNames . length === 0 && isJSONSupported ( ) ) {
@@ -206,13 +206,13 @@ module ts {
206206 if ( commandLine . fileNames . length === 0 && ! configFileName ) {
207207 printVersion ( ) ;
208208 printHelp ( ) ;
209- return sys . exit ( EmitReturnStatus . CompilerOptionsErrors ) ;
209+ return sys . exit ( ExitStatus . Success ) ;
210210 }
211211
212212 if ( commandLine . options . watch ) {
213213 if ( ! sys . watchFile ) {
214214 reportDiagnostic ( createCompilerDiagnostic ( Diagnostics . The_current_host_does_not_support_the_0_option , "--watch" ) ) ;
215- return sys . exit ( EmitReturnStatus . CompilerOptionsErrors ) ;
215+ return sys . exit ( ExitStatus . DiagnosticsPresent_OutputsSkipped ) ;
216216 }
217217 if ( configFileName ) {
218218 configFileWatcher = sys . watchFile ( configFileName , configFileChanged ) ;
@@ -229,12 +229,12 @@ module ts {
229229 var configObject = readConfigFile ( configFileName ) ;
230230 if ( ! configObject ) {
231231 reportDiagnostic ( createCompilerDiagnostic ( Diagnostics . Unable_to_open_file_0 , configFileName ) ) ;
232- return sys . exit ( EmitReturnStatus . CompilerOptionsErrors ) ;
232+ return sys . exit ( ExitStatus . DiagnosticsPresent_OutputsSkipped ) ;
233233 }
234234 var configParseResult = parseConfigFile ( configObject , getDirectoryPath ( configFileName ) ) ;
235235 if ( configParseResult . errors . length > 0 ) {
236236 reportDiagnostics ( configParseResult . errors ) ;
237- return sys . exit ( EmitReturnStatus . CompilerOptionsErrors ) ;
237+ return sys . exit ( ExitStatus . DiagnosticsPresent_OutputsSkipped ) ;
238238 }
239239 rootFileNames = configParseResult . fileNames ;
240240 compilerOptions = extend ( commandLine . options , configParseResult . options ) ;
@@ -362,33 +362,46 @@ module ts {
362362
363363 return { program, exitStatus } ;
364364
365- function compileProgram ( ) : EmitReturnStatus {
365+ function compileProgram ( ) : ExitStatus {
366366 // First get any syntactic errors.
367- var errors = program . getSyntacticDiagnostics ( ) ;
368- reportDiagnostics ( errors ) ;
367+ var diagnostics = program . getSyntacticDiagnostics ( ) ;
368+ reportDiagnostics ( diagnostics ) ;
369369
370370 // If we didn't have any syntactic errors, then also try getting the global and
371371 // semantic errors.
372- if ( errors . length === 0 ) {
373- var errors = program . getGlobalDiagnostics ( ) ;
374- reportDiagnostics ( errors ) ;
372+ if ( diagnostics . length === 0 ) {
373+ var diagnostics = program . getGlobalDiagnostics ( ) ;
374+ reportDiagnostics ( diagnostics ) ;
375375
376- if ( errors . length === 0 ) {
377- var errors = program . getSemanticDiagnostics ( ) ;
378- reportDiagnostics ( errors ) ;
376+ if ( diagnostics . length === 0 ) {
377+ var diagnostics = program . getSemanticDiagnostics ( ) ;
378+ reportDiagnostics ( diagnostics ) ;
379379 }
380380 }
381381
382382 // If the user doesn't want us to emit, then we're done at this point.
383383 if ( compilerOptions . noEmit ) {
384- return EmitReturnStatus . Succeeded ;
384+ return diagnostics . length
385+ ? ExitStatus . DiagnosticsPresent_OutputsSkipped
386+ : ExitStatus . Success ;
385387 }
386388
387389 // Otherwise, emit and report any errors we ran into.
388390 var emitOutput = program . emit ( ) ;
389391 reportDiagnostics ( emitOutput . diagnostics ) ;
390392
391- return emitOutput . emitResultStatus ;
393+ // If the emitter didn't emit anything, then pass that value along.
394+ if ( emitOutput . emitSkipped ) {
395+ return ExitStatus . DiagnosticsPresent_OutputsSkipped ;
396+ }
397+
398+ // The emitter emitted something, inform the caller if that happened in the presence
399+ // of diagnostics or not.
400+ if ( diagnostics . length > 0 || emitOutput . diagnostics . length > 0 ) {
401+ ExitStatus . DiagnosticsPresent_OutputsGenerated ;
402+ }
403+
404+ return ExitStatus . Success ;
392405 }
393406 }
394407
0 commit comments