From eaa4daaee5d9e1094e7bb650f916903b92d535da Mon Sep 17 00:00:00 2001 From: Yui T Date: Fri, 19 Sep 2014 15:17:19 -0700 Subject: [PATCH 1/3] Return exit code --- src/compiler/tsc.ts | 43 +++++++++++++++++++++++++++++++------------ src/compiler/types.ts | 3 ++- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 8188cb8e4d1..38aab5396b4 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -208,18 +208,18 @@ module ts { // setting up localization, report them and quit. if (commandLine.errors.length > 0) { reportDiagnostics(commandLine.errors); - return sys.exit(1); + return sys.exit(EmitReturnStatus.CompilerOptionsErrors); } if (commandLine.options.version) { reportDiagnostic(createCompilerDiagnostic(Diagnostics.Version_0, version)); - return sys.exit(0); + return sys.exit(EmitReturnStatus.CompilerOptionsErrors); } if (commandLine.options.help || commandLine.filenames.length === 0) { printVersion(); printHelp(); - return sys.exit(0); + return sys.exit(EmitReturnStatus.CompilerOptionsErrors); } var defaultCompilerHost = createCompilerHost(commandLine.options); @@ -227,13 +227,13 @@ module ts { if (commandLine.options.watch) { if (!sys.watchFile) { reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--watch")); - return sys.exit(1); + return sys.exit(EmitReturnStatus.CompilerOptionsErrors); } watchProgram(commandLine, defaultCompilerHost); } else { - var result = compile(commandLine, defaultCompilerHost).errors.length > 0 ? 1 : 0; + var result = compile(commandLine, defaultCompilerHost).exitStatus return sys.exit(result); } } @@ -328,11 +328,16 @@ module ts { function compile(commandLine: ParsedCommandLine, compilerHost: CompilerHost) { var parseStart = new Date().getTime(); - var program = createProgram(commandLine.filenames, commandLine.options, compilerHost); + var compilerOptions = commandLine.options; + var program = createProgram(commandLine.filenames, compilerOptions, compilerHost); var bindStart = new Date().getTime(); - var errors = program.getDiagnostics(); - if (errors.length) { + var syntacticErrors = program.getDiagnostics(); + var emitErrors: Diagnostic[]; + var semanticErrors: Diagnostic[]; + var errors: Diagnostic[]; + + if (syntacticErrors.length) { var checkStart = bindStart; var emitStart = bindStart; var reportStart = bindStart; @@ -340,11 +345,11 @@ module ts { else { var checker = program.getTypeChecker(/*fullTypeCheckMode*/ true); var checkStart = new Date().getTime(); - var semanticErrors = checker.getDiagnostics(); + semanticErrors = checker.getDiagnostics(); var emitStart = new Date().getTime(); - var emitErrors = checker.emitFiles().errors; + emitErrors = checker.emitFiles().errors; var reportStart = new Date().getTime(); - errors = concatenate(semanticErrors, emitErrors); + errors = concatenate(syntacticErrors, concatenate(semanticErrors, emitErrors)); } reportDiagnostics(errors); @@ -366,7 +371,21 @@ module ts { reportTimeStatistic("Total time", reportStart - parseStart); } - return { program: program, errors: errors }; + // Check types of diagnostics and return associated exit code + if (syntacticErrors.length > 0) { + return { program: program, exitStatus: EmitReturnStatus.AllOutputGenerationSkipped }; + } else if (semanticErrors.length > 0 && !compilerOptions.declaration) { + // No '-d' is specified; javascript file is generated with semantic errors + return { program: program, exitStatus: EmitReturnStatus.JSGeneratedWithSemanticErrors }; + } else if (semanticErrors.length > 0 && compilerOptions.declaration) { + // '-d' is specified; javascript file will be emitted with semantic errors but declaration file will be skipped + return { program: program, exitStatus: EmitReturnStatus.DeclarationGenerationSkipped }; + } else if (emitErrors.length > 0 && compilerOptions.declaration) { + return { program: program, exitStatus: EmitReturnStatus.EmitErrorsEncountered }; + } else { + // There is no error message + return { program: program, exitStatus: EmitReturnStatus.Succeeded }; + } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index e1116150e34..af418551543 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -606,7 +606,8 @@ module ts { AllOutputGenerationSkipped = 1, // No .js generated because of syntax errors, or compiler options errors, nothing generated JSGeneratedWithSemanticErrors = 2, // .js and .map generated with semantic errors DeclarationGenerationSkipped = 3, // .d.ts generation skipped because of semantic errors or declaration emitter specific errors; Output .js with semantic errors - EmitErrorsEncountered = 4 // Emitter errors occurred during emitting process + EmitErrorsEncountered = 4, // Emitter errors occurred during emitting process + CompilerOptionsErrors = 5, // Errors occurred in parsing compiler options } export interface EmitResult { From 76656f2460bd06396ff224cc9655ad1bb349993b Mon Sep 17 00:00:00 2001 From: Yui T Date: Fri, 19 Sep 2014 16:18:16 -0700 Subject: [PATCH 2/3] Address code reviews --- src/compiler/tsc.ts | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 38aab5396b4..30428568d50 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -333,9 +333,8 @@ module ts { var bindStart = new Date().getTime(); var syntacticErrors = program.getDiagnostics(); - var emitErrors: Diagnostic[]; - var semanticErrors: Diagnostic[]; var errors: Diagnostic[]; + var exitStatus: EmitReturnStatus; if (syntacticErrors.length) { var checkStart = bindStart; @@ -345,9 +344,11 @@ module ts { else { var checker = program.getTypeChecker(/*fullTypeCheckMode*/ true); var checkStart = new Date().getTime(); - semanticErrors = checker.getDiagnostics(); + var semanticErrors = checker.getDiagnostics(); var emitStart = new Date().getTime(); - emitErrors = checker.emitFiles().errors; + var emitOutput = checker.emitFiles(); + var emitErrors = emitOutput.errors; + exitStatus = emitOutput.emitResultStatus; var reportStart = new Date().getTime(); errors = concatenate(syntacticErrors, concatenate(semanticErrors, emitErrors)); } @@ -371,22 +372,11 @@ module ts { reportTimeStatistic("Total time", reportStart - parseStart); } - // Check types of diagnostics and return associated exit code + // Check if there exists syntactic errors if (syntacticErrors.length > 0) { - return { program: program, exitStatus: EmitReturnStatus.AllOutputGenerationSkipped }; - } else if (semanticErrors.length > 0 && !compilerOptions.declaration) { - // No '-d' is specified; javascript file is generated with semantic errors - return { program: program, exitStatus: EmitReturnStatus.JSGeneratedWithSemanticErrors }; - } else if (semanticErrors.length > 0 && compilerOptions.declaration) { - // '-d' is specified; javascript file will be emitted with semantic errors but declaration file will be skipped - return { program: program, exitStatus: EmitReturnStatus.DeclarationGenerationSkipped }; - } else if (emitErrors.length > 0 && compilerOptions.declaration) { - return { program: program, exitStatus: EmitReturnStatus.EmitErrorsEncountered }; - } else { - // There is no error message - return { program: program, exitStatus: EmitReturnStatus.Succeeded }; - } - + exitStatus = EmitReturnStatus.AllOutputGenerationSkipped; + } + return { program: program, exitStatus: exitStatus } } function printVersion() { From 94e788c737015eb7bb4f47f42c611d655449cd28 Mon Sep 17 00:00:00 2001 From: Yui T Date: Mon, 22 Sep 2014 09:43:47 -0700 Subject: [PATCH 3/3] Address code review --- src/compiler/tsc.ts | 31 +++++++++++++++++-------------- src/compiler/types.ts | 4 ++-- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 30428568d50..42c0953eecc 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -199,8 +199,9 @@ module ts { export function executeCommandLine(args: string[]): void { var commandLine = parseCommandLine(args); + var compilerOptions = commandLine.options; - if (commandLine.options.locale) { + if (compilerOptions.locale) { validateLocaleAndSetLanguage(commandLine.options.locale, commandLine.errors); } @@ -211,20 +212,26 @@ module ts { return sys.exit(EmitReturnStatus.CompilerOptionsErrors); } - if (commandLine.options.version) { + if (compilerOptions.version) { reportDiagnostic(createCompilerDiagnostic(Diagnostics.Version_0, version)); - return sys.exit(EmitReturnStatus.CompilerOptionsErrors); + return sys.exit(EmitReturnStatus.Succeeded); } - if (commandLine.options.help || commandLine.filenames.length === 0) { + if (compilerOptions.help) { + printVersion(); + printHelp(); + return sys.exit(EmitReturnStatus.Succeeded); + } + + if (commandLine.filenames.length === 0) { printVersion(); printHelp(); return sys.exit(EmitReturnStatus.CompilerOptionsErrors); } - var defaultCompilerHost = createCompilerHost(commandLine.options); + var defaultCompilerHost = createCompilerHost(compilerOptions); - if (commandLine.options.watch) { + if (compilerOptions.watch) { if (!sys.watchFile) { reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--watch")); return sys.exit(EmitReturnStatus.CompilerOptionsErrors); @@ -332,14 +339,14 @@ module ts { var program = createProgram(commandLine.filenames, compilerOptions, compilerHost); var bindStart = new Date().getTime(); - var syntacticErrors = program.getDiagnostics(); - var errors: Diagnostic[]; + var errors: Diagnostic[] = program.getDiagnostics(); var exitStatus: EmitReturnStatus; - if (syntacticErrors.length) { + if (errors.length) { var checkStart = bindStart; var emitStart = bindStart; var reportStart = bindStart; + exitStatus = EmitReturnStatus.AllOutputGenerationSkipped; } else { var checker = program.getTypeChecker(/*fullTypeCheckMode*/ true); @@ -350,7 +357,7 @@ module ts { var emitErrors = emitOutput.errors; exitStatus = emitOutput.emitResultStatus; var reportStart = new Date().getTime(); - errors = concatenate(syntacticErrors, concatenate(semanticErrors, emitErrors)); + errors = concatenate(semanticErrors, emitErrors); } reportDiagnostics(errors); @@ -372,10 +379,6 @@ module ts { reportTimeStatistic("Total time", reportStart - parseStart); } - // Check if there exists syntactic errors - if (syntacticErrors.length > 0) { - exitStatus = EmitReturnStatus.AllOutputGenerationSkipped; - } return { program: program, exitStatus: exitStatus } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index af418551543..8bb1cfa4163 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -603,11 +603,11 @@ module ts { // Return code used by getEmitOutput function to indicate status of the function export enum EmitReturnStatus { Succeeded = 0, // All outputs generated as requested (.js, .map, .d.ts), no errors reported - AllOutputGenerationSkipped = 1, // No .js generated because of syntax errors, or compiler options errors, nothing generated + AllOutputGenerationSkipped = 1, // No .js generated because of syntax errors, nothing generated JSGeneratedWithSemanticErrors = 2, // .js and .map generated with semantic errors DeclarationGenerationSkipped = 3, // .d.ts generation skipped because of semantic errors or declaration emitter specific errors; Output .js with semantic errors EmitErrorsEncountered = 4, // Emitter errors occurred during emitting process - CompilerOptionsErrors = 5, // Errors occurred in parsing compiler options + CompilerOptionsErrors = 5, // Errors occurred in parsing compiler options, nothing generated } export interface EmitResult {