From de308664604cd50e8f1690a60ec33eadd27fafbd Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 4 Feb 2015 22:26:03 -0800 Subject: [PATCH] Simplify the code for actually compiling within tsc. --- src/compiler/tsc.ts | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index e4a9f92164d..f0dcb872950 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -328,28 +328,11 @@ module ts { ts.emitTime = 0; var start = new Date().getTime(); + var program = createProgram(fileNames, compilerOptions, compilerHost); - - var errors: Diagnostic[] = program.getDiagnostics(); - var exitStatus: EmitReturnStatus; - - if (errors.length) { - exitStatus = EmitReturnStatus.AllOutputGenerationSkipped; - } - else { - errors = program.getTypeCheckerDiagnostics(); - if (compilerOptions.noEmit) { - exitStatus = EmitReturnStatus.Succeeded; - } - else { - var emitOutput = program.emit(); - exitStatus = emitOutput.emitResultStatus; - errors = concatenate(errors, emitOutput.diagnostics); - } - } + var exitStatus = compileProgram(); var end = start - new Date().getTime(); - reportDiagnostics(errors); if (compilerOptions.listFiles) { forEach(program.getSourceFiles(), file => { @@ -378,6 +361,29 @@ module ts { } return { program, exitStatus }; + + function compileProgram(): EmitReturnStatus { + // First get any syntactic errors. + var errors = program.getDiagnostics(); + reportDiagnostics(errors); + + // If we didn't have any syntactic errors, then also try getting the semantic errors. + if (errors.length === 0) { + var errors = program.getTypeCheckerDiagnostics(); + reportDiagnostics(errors); + } + + // If the user doesn't want us to emit, then we're done at this point. + if (compilerOptions.noEmit) { + return EmitReturnStatus.Succeeded; + } + + // Otherwise, emit and report any errors we ran into. + var emitOutput = program.emit(); + reportDiagnostics(emitOutput.diagnostics); + + return emitOutput.emitResultStatus; + } } function printVersion() {