@@ -328,28 +328,11 @@ module ts {
328328 ts . emitTime = 0 ;
329329
330330 var start = new Date ( ) . getTime ( ) ;
331- var program = createProgram ( fileNames , compilerOptions , compilerHost ) ;
332-
333- var errors : Diagnostic [ ] = program . getDiagnostics ( ) ;
334- var exitStatus : EmitReturnStatus ;
335331
336- if ( errors . length ) {
337- exitStatus = EmitReturnStatus . AllOutputGenerationSkipped ;
338- }
339- else {
340- errors = program . getTypeCheckerDiagnostics ( ) ;
341- if ( compilerOptions . noEmit ) {
342- exitStatus = EmitReturnStatus . Succeeded ;
343- }
344- else {
345- var emitOutput = program . emit ( ) ;
346- exitStatus = emitOutput . emitResultStatus ;
347- errors = concatenate ( errors , emitOutput . diagnostics ) ;
348- }
349- }
332+ var program = createProgram ( fileNames , compilerOptions , compilerHost ) ;
333+ var exitStatus = compileProgram ( ) ;
350334
351335 var end = start - new Date ( ) . getTime ( ) ;
352- reportDiagnostics ( errors ) ;
353336
354337 if ( compilerOptions . listFiles ) {
355338 forEach ( program . getSourceFiles ( ) , file => {
@@ -378,6 +361,29 @@ module ts {
378361 }
379362
380363 return { program, exitStatus } ;
364+
365+ function compileProgram ( ) : EmitReturnStatus {
366+ // First get any syntactic errors.
367+ var errors = program . getDiagnostics ( ) ;
368+ reportDiagnostics ( errors ) ;
369+
370+ // If we didn't have any syntactic errors, then also try getting the semantic errors.
371+ if ( errors . length === 0 ) {
372+ var errors = program . getTypeCheckerDiagnostics ( ) ;
373+ reportDiagnostics ( errors ) ;
374+ }
375+
376+ // If the user doesn't want us to emit, then we're done at this point.
377+ if ( compilerOptions . noEmit ) {
378+ return EmitReturnStatus . Succeeded ;
379+ }
380+
381+ // Otherwise, emit and report any errors we ran into.
382+ var emitOutput = program . emit ( ) ;
383+ reportDiagnostics ( emitOutput . diagnostics ) ;
384+
385+ return emitOutput . emitResultStatus ;
386+ }
381387 }
382388
383389 function printVersion ( ) {
0 commit comments