From 570d2bda3349f6eaf5f40160e49f70963db51258 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 29 Jul 2014 13:56:22 -0700 Subject: [PATCH 1/2] Print version number for --version. --- .../diagnosticInformationMap.generated.ts | 1 + src/compiler/diagnosticMessages.json | 5 + src/compiler/tc.ts | 97 +++++++++++-------- 3 files changed, 61 insertions(+), 42 deletions(-) diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 431a9053d38..19d511f664e 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -211,6 +211,7 @@ module ts { Could_not_write_file_0_Colon_1: { code: 5033, category: DiagnosticCategory.Error, key: "Could not write file '{0}': {1}" }, Option_mapRoot_cannot_be_specified_without_specifying_sourcemap_option: { code: 5038, category: DiagnosticCategory.Error, key: "Option mapRoot cannot be specified without specifying sourcemap option." }, Option_sourceRoot_cannot_be_specified_without_specifying_sourcemap_option: { code: 5039, category: DiagnosticCategory.Error, key: "Option sourceRoot cannot be specified without specifying sourcemap option." }, + Version_0: { code: 6029, category: DiagnosticCategory.Message, key: "Version {0}" }, Variable_0_implicitly_has_an_1_type: { code: 7005, category: DiagnosticCategory.Error, key: "Variable '{0}' implicitly has an '{1}' type." }, Parameter_0_implicitly_has_an_1_type: { code: 7006, category: DiagnosticCategory.Error, key: "Parameter '{0}' implicitly has an '{1}' type." }, Member_0_implicitly_has_an_1_type: { code: 7008, category: DiagnosticCategory.Error, key: "Member '{0}' implicitly has an '{1}' type." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 322f1ac994c..3e40d82e751 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -839,6 +839,11 @@ "code": 5039 }, + "Version {0}": { + "category": "Message", + "code": 6029 + }, + "Variable '{0}' implicitly has an '{1}' type.": { "category": "Error", "code": 7005 diff --git a/src/compiler/tc.ts b/src/compiler/tc.ts index d44d1b9724c..f81bce68e1a 100644 --- a/src/compiler/tc.ts +++ b/src/compiler/tc.ts @@ -9,6 +9,8 @@ /// module ts { + export var version = "1.1.0.0"; + /// Checks to see if the locale is in the appropriate format, /// and if it is, attempt to set the appropriate language. function validateLocaleAndSetLanguage(locale: string, errors: Diagnostic[]): boolean { @@ -76,39 +78,47 @@ module ts { return count; } - function reportErrors(errors: Diagnostic[]) { + function reportDiagnostic(error: Diagnostic) { + if (error.file) { + var loc = error.file.getLineAndCharacterFromPosition(error.start); + sys.writeErr(error.file.filename + "(" + loc.line + "," + loc.character + "): " + error.messageText + sys.newLine); + } + else { + sys.writeErr(error.messageText + sys.newLine); + } + } + + function reportDiagnostics(errors: Diagnostic[]) { for (var i = 0; i < errors.length; i++) { - var error = errors[i]; - if (error.file) { - var loc = error.file.getLineAndCharacterFromPosition(error.start); - sys.writeErr(error.file.filename + "(" + loc.line + "," + loc.character + "): " + error.messageText + sys.newLine); - } - else { - sys.writeErr(error.messageText + sys.newLine); - } + reportDiagnostic(errors[i]); } } function padLeft(s: string, length: number) { - while (s.length < length) s = " " + s; + while (s.length < length) { + s = " " + s; + } return s; } function padRight(s: string, length: number) { - while (s.length < length) s = s + " "; + while (s.length < length) { + s = s + " "; + } + return s; } - function reportDiagnostic(name: string, value: string) { + function reportStatisticalValue(name: string, value: string) { sys.writeErr(padRight(name + ":", 12) + padLeft(value.toString(), 10) + sys.newLine); } - function reportDiagnosticCount(name: string, count: number) { - reportDiagnostic(name, "" + count); + function reportCountStatistic(name: string, count: number) { + reportStatisticalValue(name, "" + count); } - function reportDiagnosticTime(name: string, time: number) { - reportDiagnostic(name, (time / 1000).toFixed(2) + "s"); + function reportTimeStatistic(name: string, time: number) { + reportStatisticalValue(name, (time / 1000).toFixed(2) + "s"); } function createCompilerHost(options: CompilerOptions): CompilerHost { @@ -120,7 +130,9 @@ module ts { var text = sys.readFile(filename, options.charset); } catch (e) { - if (onError) onError(e.message); + if (onError) { + onError(e.message); + } text = ""; } return text !== undefined ? createSourceFile(filename, text, languageVersion) : undefined; @@ -168,28 +180,29 @@ module ts { export function executeCommandLine(args: string[]): number { var cmds = parseCommandLine(args); - if (cmds.filenames.length === 0 && !(cmds.options.help || cmds.options.version)) { - cmds.errors.push(createCompilerDiagnostic(Diagnostics.No_input_files_specified)); - } - if (cmds.options.version) { - } - - if (cmds.filenames.length === 0 || cmds.options.help) { - // TODO (drosen): Usage. - } - - // If a locale has been set but fails to load, act as if it was never specified, - // but collect the errors to report along the way. if (cmds.options.locale) { validateLocaleAndSetLanguage(cmds.options.locale, cmds.errors); } + if (cmds.filenames.length === 0 && !(cmds.options.help || cmds.options.version)) { + cmds.errors.push(createCompilerDiagnostic(Diagnostics.No_input_files_specified)); + } + if (cmds.errors.length) { - reportErrors(cmds.errors); + reportDiagnostics(cmds.errors); return 1; } + if (cmds.options.version) { + reportDiagnostic(createCompilerDiagnostic(Diagnostics.Version_0, version)); + return 0; + } + + if (cmds.filenames.length === 0 || cmds.options.help) { + // TODO (drosen): Usage. + } + var parseStart = new Date().getTime(); var program = createProgram(cmds.filenames, cmds.options, createCompilerHost(cmds.options)); var bindStart = new Date().getTime(); @@ -209,19 +222,19 @@ module ts { errors = concatenate(semanticErrors, emitErrors); } - reportErrors(errors); + reportDiagnostics(errors); if (cmds.options.diagnostics) { - reportDiagnosticCount("Files", program.getSourceFiles().length); - reportDiagnosticCount("Lines", countLines(program)); - reportDiagnosticCount("Nodes", checker ? checker.getNodeCount() : 0); - reportDiagnosticCount("Identifiers", checker ? checker.getIdentifierCount() : 0); - reportDiagnosticCount("Symbols", checker ? checker.getSymbolCount() : 0); - reportDiagnosticCount("Types", checker ? checker.getTypeCount() : 0); - reportDiagnosticTime("Parse time", bindStart - parseStart); - reportDiagnosticTime("Bind time", checkStart - bindStart); - reportDiagnosticTime("Check time", emitStart - checkStart); - reportDiagnosticTime("Emit time", reportStart - emitStart); - reportDiagnosticTime("Total time", reportStart - parseStart); + reportCountStatistic("Files", program.getSourceFiles().length); + reportCountStatistic("Lines", countLines(program)); + reportCountStatistic("Nodes", checker ? checker.getNodeCount() : 0); + reportCountStatistic("Identifiers", checker ? checker.getIdentifierCount() : 0); + reportCountStatistic("Symbols", checker ? checker.getSymbolCount() : 0); + reportCountStatistic("Types", checker ? checker.getTypeCount() : 0); + reportTimeStatistic("Parse time", bindStart - parseStart); + reportTimeStatistic("Bind time", checkStart - bindStart); + reportTimeStatistic("Check time", emitStart - checkStart); + reportTimeStatistic("Emit time", reportStart - emitStart); + reportTimeStatistic("Total time", reportStart - parseStart); } return errors.length ? 1 : 0; } From c171c79464667e3c3c1bbbcff2e808a45fa7cb7c Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 29 Jul 2014 16:36:47 -0700 Subject: [PATCH 2/2] Moved error checking for command line options around. --- src/compiler/tc.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/compiler/tc.ts b/src/compiler/tc.ts index f81bce68e1a..b363ab4d39f 100644 --- a/src/compiler/tc.ts +++ b/src/compiler/tc.ts @@ -189,11 +189,6 @@ module ts { cmds.errors.push(createCompilerDiagnostic(Diagnostics.No_input_files_specified)); } - if (cmds.errors.length) { - reportDiagnostics(cmds.errors); - return 1; - } - if (cmds.options.version) { reportDiagnostic(createCompilerDiagnostic(Diagnostics.Version_0, version)); return 0; @@ -203,6 +198,11 @@ module ts { // TODO (drosen): Usage. } + if (cmds.errors.length) { + reportDiagnostics(cmds.errors); + return 1; + } + var parseStart = new Date().getTime(); var program = createProgram(cmds.filenames, cmds.options, createCompilerHost(cmds.options)); var bindStart = new Date().getTime();