From 616dae20f0894eb47cd957130e0eb47daa796374 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 31 Jul 2014 17:20:57 -0700 Subject: [PATCH 1/8] Fixed diagnostic generator; added messages. --- Jakefile | 2 + scripts/processDiagnosticMessages.ts | 13 +- .../diagnosticInformationMap.generated.ts | 30 ++++ src/compiler/diagnosticMessages.json | 128 +++++++++++++++++- 4 files changed, 163 insertions(+), 10 deletions(-) diff --git a/Jakefile b/Jakefile index 7a8ee59d532dd..bf5201b696b44 100644 --- a/Jakefile +++ b/Jakefile @@ -199,6 +199,8 @@ var processDiagnosticMessagesTs = path.join(scriptsDirectory, "processDiagnostic var diagnosticMessagesJson = path.join(compilerDirectory, "diagnosticMessages.json"); var diagnosticInfoMapTs = path.join(compilerDirectory, "diagnosticInformationMap.generated.ts"); +file(processDiagnosticMessagesTs) + // processDiagnosticMessages script compileFile(processDiagnosticMessagesJs, [processDiagnosticMessagesTs], diff --git a/scripts/processDiagnosticMessages.ts b/scripts/processDiagnosticMessages.ts index e1a198a212457..31449c88e3a32 100644 --- a/scripts/processDiagnosticMessages.ts +++ b/scripts/processDiagnosticMessages.ts @@ -94,10 +94,7 @@ function convertPropertyName(origName: string): string { } module NameGenerator { - export function ensureUniqueness( - names: string[], - isFixed: boolean[]= names.map(() => false), - isCaseSensitive: boolean = true): string[] { + export function ensureUniqueness(names: string[], isFixed: boolean[] = names.map(() => false), isCaseSensitive: boolean = false): string[] { var names = names.map(x => x); ensureUniquenessInPlace(names, isFixed, isCaseSensitive); @@ -133,7 +130,7 @@ module NameGenerator { while (true) { var newName = name + suffix++; - if (proposedNames.some((name) => Utilities.stringEquals(name, newName, isCaseSensitive))) { + if (!proposedNames.some((name) => Utilities.stringEquals(name, newName, isCaseSensitive))) { proposedNames[collisionIndex] = newName; break; } @@ -144,7 +141,7 @@ module NameGenerator { module Utilities { /// Return a list of all indices where a string occurs. - export function collectMatchingIndices(name: string, proposedNames: string[], isCaseSensitive: boolean = true): number[] { + export function collectMatchingIndices(name: string, proposedNames: string[], isCaseSensitive: boolean = false): number[] { var matchingIndices: number[] = []; for (var i = 0; i < proposedNames.length; i++) { @@ -156,8 +153,8 @@ module Utilities { return matchingIndices; } - export function stringEquals(s1: string, s2: string, caseSensitive: boolean = true): boolean { - if (!caseSensitive) { + export function stringEquals(s1: string, s2: string, caseSensitive: boolean = false): boolean { + if (caseSensitive) { s1 = s1.toLowerCase(); s2 = s2.toLowerCase(); } diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index a3b85cfb01387..b97e3974f7b66 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -216,8 +216,38 @@ 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." }, + Concatenate_and_emit_output_to_single_file: { code: 6001, category: DiagnosticCategory.Message, key: "Concatenate and emit output to single file." }, + Generates_corresponding_0_file: { code: 6002, category: DiagnosticCategory.Message, key: "Generates corresponding {0} file." }, + Specifies_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations: { code: 6003, category: DiagnosticCategory.Message, key: "Specifies the location where debugger should locate map files instead of generated locations." }, + Specifies_the_location_where_debugger_should_locate_TypeScript_files_instead_of_source_locations: { code: 6004, category: DiagnosticCategory.Message, key: "Specifies the location where debugger should locate TypeScript files instead of source locations." }, + Watch_input_files: { code: 6005, category: DiagnosticCategory.Message, key: "Watch input files." }, + Redirect_output_structure_to_the_directory: { code: 6006, category: DiagnosticCategory.Message, key: "Redirect output structure to the directory." }, + Do_not_emit_comments_to_output: { code: 6009, category: DiagnosticCategory.Message, key: "Do not emit comments to output." }, + Skip_resolution_and_preprocessing: { code: 6010, category: DiagnosticCategory.Message, key: "Skip resolution and preprocessing." }, + Specify_ECMAScript_target_version_Colon_0_default_or_1: { code: 6015, category: DiagnosticCategory.Message, key: "Specify ECMAScript target version: '{0}' (default), or '{1}'" }, + Specify_module_code_generation_Colon_0_or_1: { code: 6016, category: DiagnosticCategory.Message, key: "Specify module code generation: '{0}' or '{1}'" }, + Print_this_message: { code: 6017, category: DiagnosticCategory.Message, key: "Print this message." }, + Print_the_compiler_s_version_Colon_0: { code: 6019, category: DiagnosticCategory.Message, key: "Print the compiler's version: {0}" }, + Allow_use_of_deprecated_0_keyword_when_referencing_an_external_module: { code: 6021, category: DiagnosticCategory.Message, key: "Allow use of deprecated '{0}' keyword when referencing an external module." }, + Specify_locale_for_errors_and_messages_For_example_0_or_1: { code: 6022, category: DiagnosticCategory.Message, key: "Specify locale for errors and messages. For example '{0}' or '{1}'" }, + Syntax_Colon_0: { code: 6023, category: DiagnosticCategory.Message, key: "Syntax: {0}" }, + options: { code: 6024, category: DiagnosticCategory.Message, key: "options" }, + file: { code: 6025, category: DiagnosticCategory.Message, key: "file" }, + Examples_Colon: { code: 6026, category: DiagnosticCategory.Message, key: "Examples:" }, + Options_Colon: { code: 6027, category: DiagnosticCategory.Message, key: "Options:" }, + Insert_command_line_options_and_files_from_a_file: { code: 6030, category: DiagnosticCategory.Message, key: "Insert command line options and files from a file." }, Version_0: { code: 6029, category: DiagnosticCategory.Message, key: "Version {0}" }, + Use_the_0_flag_to_see_options: { code: 6031, category: DiagnosticCategory.Message, key: "Use the '{0}' flag to see options." }, File_Changed_Compiling: { code: 6032, category: DiagnosticCategory.Message, key: "File Changed. Compiling." }, + STRING: { code: 6033, category: DiagnosticCategory.Message, key: "STRING" }, + KIND: { code: 6034, category: DiagnosticCategory.Message, key: "KIND" }, + FILE: { code: 6035, category: DiagnosticCategory.Message, key: "FILE" }, + VERSION: { code: 6036, category: DiagnosticCategory.Message, key: "VERSION" }, + LOCATION: { code: 6037, category: DiagnosticCategory.Message, key: "LOCATION" }, + DIRECTORY: { code: 6038, category: DiagnosticCategory.Message, key: "DIRECTORY" }, + NUMBER: { code: 6039, category: DiagnosticCategory.Message, key: "NUMBER" }, + Specify_the_codepage_to_use_when_opening_source_files: { code: 6040, category: DiagnosticCategory.Message, key: "Specify the codepage to use when opening source files." }, + Additional_locations_Colon: { code: 6041, category: DiagnosticCategory.Message, key: "Additional locations:" }, Compile_complete_Listening_for_changed_files: { code: 6042, category: DiagnosticCategory.Message, key: "Compile complete. Listening for changed files." }, 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." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 9ace46f420216..d4ae58e870544 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -858,14 +858,138 @@ "category": "Error", "code": 5039 }, + "Concatenate and emit output to single file.": { + "category": "Message", + "code": 6001 + }, + "Generates corresponding {0} file.": { + "category": "Message", + "code": 6002 + }, + "Specifies the location where debugger should locate map files instead of generated locations.": { + "category": "Message", + "code": 6003 + }, + "Specifies the location where debugger should locate TypeScript files instead of source locations.": { + "category": "Message", + "code": 6004 + }, + "Watch input files.": { + "category": "Message", + "code": 6005 + }, + "Redirect output structure to the directory.": { + "category": "Message", + "code": 6006 + }, + "Do not emit comments to output.": { + "category": "Message", + "code": 6009 + }, + "Skip resolution and preprocessing.": { + "category": "Message", + "code": 6010 + }, + "Specify ECMAScript target version: '{0}' (default), or '{1}'": { + "category": "Message", + "code": 6015 + }, + "Specify module code generation: '{0}' or '{1}'": { + "category": "Message", + "code": 6016 + }, + "Print this message.": { + "category": "Message", + "code": 6017 + }, + "Print the compiler's version: {0}": { + "category": "Message", + "code": 6019 + }, + "Allow use of deprecated '{0}' keyword when referencing an external module.": { + "category": "Message", + "code": 6021 + }, + "Specify locale for errors and messages. For example '{0}' or '{1}'": { + "category": "Message", + "code": 6022 + }, + "Syntax: {0}": { + "category": "Message", + "code": 6023 + }, + "options": { + "category": "Message", + "code": 6024 + }, + "file": { + "category": "Message", + "code": 6025 + }, + "Examples:": { + "category": "Message", + "code": 6026 + }, + "Options:": { + "category": "Message", + "code": 6027 + }, + "Insert command line options and files from a file.": { + "category": "Message", + "code": 6028 + }, "Version {0}": { - "category": "Message", - "code": 6029 + "category": "Message", + "code": 6029 + }, + "Insert command line options and files from a file.": { + "category": "Message", + "code": 6030 + }, + "Use the '{0}' flag to see options.": { + "category": "Message", + "code": 6031 }, "File Changed. Compiling.": { "category": "Message", "code": 6032 }, + "STRING": { + "category": "Message", + "code": 6033 + }, + "KIND": { + "category": "Message", + "code": 6034 + }, + "FILE": { + "category": "Message", + "code": 6035 + }, + "VERSION": { + "category": "Message", + "code": 6036 + }, + "LOCATION": { + "category": "Message", + "code": 6037 + }, + "DIRECTORY": { + "category": "Message", + "code": 6038 + }, + "NUMBER": { + "category": "Message", + "code": 6039 + }, + "Specify the codepage to use when opening source files.": { + "category": "Message", + "code": 6040 + }, + "Additional locations:": { + "category": "Message", + "code": 6041 + }, "Compile complete. Listening for changed files.": { "category": "Message", "code": 6042 From 2dd9763badc9075eb3f27a6041338f63cbaa1776 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 1 Aug 2014 17:12:29 -0700 Subject: [PATCH 2/8] Implemented --help. --- src/compiler/commandLineParser.ts | 158 ++++++++++++++---- src/compiler/core.ts | 2 +- .../diagnosticInformationMap.generated.ts | 32 ++-- src/compiler/diagnosticMessages.json | 93 ++++++----- src/compiler/tc.ts | 146 +++++++++++++--- src/compiler/types.ts | 5 +- 6 files changed, 320 insertions(+), 116 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 7a3e27b8a0231..8d0f977dddb11 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -4,44 +4,128 @@ /// module ts { - var shortOptionNames: Map = { - "d": "declaration", - "h": "help", - "m": "module", - "o": "out", - "t": "target", - "v": "version", - "w": "watch", - }; - - var optionDeclarations: CommandLineOption[] = [ - { name: "charset", type: "string" }, - { name: "codepage", type: "number" }, - { name: "declaration", type: "boolean" }, - { name: "diagnostics", type: "boolean" }, - { name: "help", type: "boolean" }, - { name: "locale", type: "string" }, - { name: "mapRoot", type: "string" }, - { name: "module", type: { "commonjs": ModuleKind.CommonJS, "amd": ModuleKind.AMD }, error: Diagnostics.Argument_for_module_option_must_be_commonjs_or_amd }, - { name: "noImplicitAny", type: "boolean" }, - { name: "noLib", type: "boolean" }, - { name: "noLibCheck", type: "boolean" }, - { name: "noResolve", type: "boolean" }, - { name: "out", type: "string" }, - { name: "outDir", type: "string" }, - { name: "removeComments", type: "boolean" }, - { name: "sourceMap", type: "boolean" }, - { name: "sourceRoot", type: "string" }, - { name: "target", type: { "es3": ScriptTarget.ES3, "es5": ScriptTarget.ES5 }, error: Diagnostics.Argument_for_target_option_must_be_es3_or_es5 }, - { name: "version", type: "boolean" }, - { name: "watch", type: "boolean" }, + export var optionDeclarations: CommandLineOption[] = [ + { + name: "charset", + type: "string", + }, + { + name: "codepage", + type: "number", + }, + { + name: "declaration", + shortName: "d", + type: "boolean", + description: Diagnostics.Generates_corresponding_d_ts_file, + }, + { + name: "diagnostics", + type: "boolean", + }, + { + name: "help", + shortName: "h", + type: "boolean", + description: Diagnostics.Print_this_message, + }, + { + name: "locale", + type: "string", + }, + { + name: "mapRoot", + type: "string", + description: Diagnostics.Specifies_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations, + paramType: Diagnostics.LOCATION, + }, + { + name: "module", + shortName: "m", + type: { + "commonjs": ModuleKind.CommonJS, + "amd": ModuleKind.AMD + }, + description: Diagnostics.Specify_module_code_generation_Colon_commonjs_or_amd, + paramType: Diagnostics.KIND, + error: Diagnostics.Argument_for_module_option_must_be_commonjs_or_amd + }, + { + name: "noImplicitAny", + type: "boolean", + description: Diagnostics.Warn_on_expressions_and_declarations_with_an_implied_any_type, + }, + { + name: "noLib", + type: "boolean", + }, + { + name: "noLibCheck", + type: "boolean", + }, + { + name: "noResolve", + type: "boolean", + }, + { + name: "out", + type: "string", + description: Diagnostics.Concatenate_and_emit_output_to_single_file, + paramType: Diagnostics.FILE, + }, + { + name: "outDir", + type: "string", + description: Diagnostics.Redirect_output_structure_to_the_directory, + paramType: Diagnostics.DIRECTORY, + }, + { + name: "removeComments", + type: "boolean", + description: Diagnostics.Do_not_emit_comments_to_output, + }, + { + name: "sourcemap", + type: "boolean", + description: Diagnostics.Generates_corresponding_map_file, + }, + { + name: "sourceRoot", + type: "string", + description: Diagnostics.Specifies_the_location_where_debugger_should_locate_TypeScript_files_instead_of_source_locations, + paramType: Diagnostics.LOCATION, + }, + { + name: "target", + shortName: "t", + type: { "es3": ScriptTarget.ES3, "es5": ScriptTarget.ES5 }, + description: Diagnostics.Specify_ECMAScript_target_version_Colon_ES3_default_or_ES5, + paramType: Diagnostics.VERSION, + error: Diagnostics.Argument_for_target_option_must_be_es3_or_es5 + }, + { + name: "version", + shortName: "v", + type: "boolean", + description: Diagnostics.Print_the_compiler_s_version, + }, + { + name: "watch", + shortName: "w", + type: "boolean", + description: Diagnostics.Watch_input_files, + }, ]; - // Map command line switches to compiler options' property descriptors. Keys must be lower case spellings of command line switches. - // The 'name' property specifies the property name in the CompilerOptions type. The 'type' property specifies the type of the option. - var optionMap: Map = {}; + var shortOptionNames: Map = {}; + var optionNameMap: Map = {}; + forEach(optionDeclarations, option => { - optionMap[option.name.toLowerCase()] = option; + optionNameMap[option.name.toLowerCase()] = option; + + if (option.shortName) { + shortOptionNames[option.shortName] = option.name; + } }); export function parseCommandLine(commandLine: string[]): ParsedCommandLine { @@ -75,8 +159,8 @@ module ts { s = shortOptionNames[s]; } - if (hasProperty(optionMap, s)) { - var opt = optionMap[s]; + if (hasProperty(optionNameMap, s)) { + var opt = optionNameMap[s]; // Check to see if no argument was provided (e.g. "--locale" is the last command-line argument). if (!args[i] && opt.type !== "boolean") { diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 1171191f8dc7a..537b60cd4ea31 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -247,7 +247,7 @@ module ts { }; } - function compareValues(a: any, b: any): number { + export function compareValues(a: T, b: T): number { if (a === b) return 0; if (a === undefined) return -1; if (b === undefined) return 1; diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index b97e3974f7b66..0299cbe846d46 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -217,23 +217,23 @@ module ts { 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." }, Concatenate_and_emit_output_to_single_file: { code: 6001, category: DiagnosticCategory.Message, key: "Concatenate and emit output to single file." }, - Generates_corresponding_0_file: { code: 6002, category: DiagnosticCategory.Message, key: "Generates corresponding {0} file." }, + Generates_corresponding_d_ts_file: { code: 6002, category: DiagnosticCategory.Message, key: "Generates corresponding '.d.ts' file." }, Specifies_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations: { code: 6003, category: DiagnosticCategory.Message, key: "Specifies the location where debugger should locate map files instead of generated locations." }, Specifies_the_location_where_debugger_should_locate_TypeScript_files_instead_of_source_locations: { code: 6004, category: DiagnosticCategory.Message, key: "Specifies the location where debugger should locate TypeScript files instead of source locations." }, Watch_input_files: { code: 6005, category: DiagnosticCategory.Message, key: "Watch input files." }, Redirect_output_structure_to_the_directory: { code: 6006, category: DiagnosticCategory.Message, key: "Redirect output structure to the directory." }, Do_not_emit_comments_to_output: { code: 6009, category: DiagnosticCategory.Message, key: "Do not emit comments to output." }, Skip_resolution_and_preprocessing: { code: 6010, category: DiagnosticCategory.Message, key: "Skip resolution and preprocessing." }, - Specify_ECMAScript_target_version_Colon_0_default_or_1: { code: 6015, category: DiagnosticCategory.Message, key: "Specify ECMAScript target version: '{0}' (default), or '{1}'" }, - Specify_module_code_generation_Colon_0_or_1: { code: 6016, category: DiagnosticCategory.Message, key: "Specify module code generation: '{0}' or '{1}'" }, + Specify_ECMAScript_target_version_Colon_ES3_default_or_ES5: { code: 6015, category: DiagnosticCategory.Message, key: "Specify ECMAScript target version: 'ES3' (default), or 'ES5'" }, + Specify_module_code_generation_Colon_commonjs_or_amd: { code: 6016, category: DiagnosticCategory.Message, key: "Specify module code generation: 'commonjs' or 'amd'" }, Print_this_message: { code: 6017, category: DiagnosticCategory.Message, key: "Print this message." }, - Print_the_compiler_s_version_Colon_0: { code: 6019, category: DiagnosticCategory.Message, key: "Print the compiler's version: {0}" }, + Print_the_compiler_s_version: { code: 6019, category: DiagnosticCategory.Message, key: "Print the compiler's version." }, Allow_use_of_deprecated_0_keyword_when_referencing_an_external_module: { code: 6021, category: DiagnosticCategory.Message, key: "Allow use of deprecated '{0}' keyword when referencing an external module." }, Specify_locale_for_errors_and_messages_For_example_0_or_1: { code: 6022, category: DiagnosticCategory.Message, key: "Specify locale for errors and messages. For example '{0}' or '{1}'" }, - Syntax_Colon_0: { code: 6023, category: DiagnosticCategory.Message, key: "Syntax: {0}" }, + Syntax_Colon_0: { code: 6023, category: DiagnosticCategory.Message, key: "Syntax: {0}" }, options: { code: 6024, category: DiagnosticCategory.Message, key: "options" }, file: { code: 6025, category: DiagnosticCategory.Message, key: "file" }, - Examples_Colon: { code: 6026, category: DiagnosticCategory.Message, key: "Examples:" }, + Examples_Colon_0: { code: 6026, category: DiagnosticCategory.Message, key: "Examples: {0}" }, Options_Colon: { code: 6027, category: DiagnosticCategory.Message, key: "Options:" }, Insert_command_line_options_and_files_from_a_file: { code: 6030, category: DiagnosticCategory.Message, key: "Insert command line options and files from a file." }, Version_0: { code: 6029, category: DiagnosticCategory.Message, key: "Version {0}" }, @@ -249,6 +249,17 @@ module ts { Specify_the_codepage_to_use_when_opening_source_files: { code: 6040, category: DiagnosticCategory.Message, key: "Specify the codepage to use when opening source files." }, Additional_locations_Colon: { code: 6041, category: DiagnosticCategory.Message, key: "Additional locations:" }, Compile_complete_Listening_for_changed_files: { code: 6042, category: DiagnosticCategory.Message, key: "Compile complete. Listening for changed files." }, + Generates_corresponding_map_file: { code: 6043, category: DiagnosticCategory.Message, key: "Generates corresponding '.map' file." }, + Compiler_option_0_expects_an_argument: { code: 6044, category: DiagnosticCategory.Error, key: "Compiler option '{0}' expects an argument." }, + Unterminated_quoted_string_in_response_file_0: { code: 6045, category: DiagnosticCategory.Error, key: "Unterminated quoted string in response file '{0}'." }, + Argument_for_module_option_must_be_commonjs_or_amd: { code: 6045, category: DiagnosticCategory.Error, key: "Argument for '--module' option must be 'commonjs' or 'amd'." }, + Argument_for_target_option_must_be_es3_or_es5: { code: 6046, category: DiagnosticCategory.Error, key: "Argument for '--target' option must be 'es3' or 'es5'." }, + Locale_must_be_of_the_form_language_or_language_territory_For_example_0_or_1: { code: 6047, category: DiagnosticCategory.Error, key: "Locale must be of the form or -. For example '{0}' or '{1}'." }, + Unsupported_locale_0: { code: 6048, category: DiagnosticCategory.Error, key: "Unsupported locale '{0}'." }, + Unable_to_open_file_0: { code: 6049, category: DiagnosticCategory.Error, key: "Unable to open file '{0}'." }, + Corrupted_locale_file_0: { code: 6050, category: DiagnosticCategory.Error, key: "Corrupted locale file {0}." }, + No_input_files_specified: { code: 6051, category: DiagnosticCategory.Error, key: "No input files specified." }, + Warn_on_expressions_and_declarations_with_an_implied_any_type: { code: 7004, category: DiagnosticCategory.Message, key: "Warn on expressions and declarations with an implied 'any' type." }, 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." }, @@ -334,14 +345,5 @@ module ts { Import_declaration_conflicts_with_local_declaration_of_0: { code: -9999999, category: DiagnosticCategory.Error, key: "Import declaration conflicts with local declaration of '{0}'" }, Module_0_is_hidden_by_a_local_declaration_with_the_same_name: { code: -9999999, category: DiagnosticCategory.Error, key: "Module '{0}' is hidden by a local declaration with the same name" }, Filename_0_differs_from_already_included_filename_1_only_in_casing: { code: -9999999, category: DiagnosticCategory.Error, key: "Filename '{0}' differs from already included filename '{1}' only in casing" }, - Argument_for_module_option_must_be_commonjs_or_amd: { code: -9999999, category: DiagnosticCategory.Error, key: "Argument for '--module' option must be 'commonjs' or 'amd'." }, - Argument_for_target_option_must_be_es3_or_es5: { code: -9999999, category: DiagnosticCategory.Error, key: "Argument for '--target' option must be 'es3' or 'es5'." }, - Compiler_option_0_expects_an_argument: { code: -9999999, category: DiagnosticCategory.Error, key: "Compiler option '{0}' expects an argument." }, - Unterminated_quoted_string_in_response_file_0: { code: -9999999, category: DiagnosticCategory.Error, key: "Unterminated quoted string in response file '{0}'." }, - Locale_must_be_of_the_form_language_or_language_territory_For_example_0_or_1: { code: -9999999, category: DiagnosticCategory.Error, key: "Locale must be of the form or -. For example '{0}' or '{1}'." }, - Unsupported_locale_0: { code: -9999999, category: DiagnosticCategory.Error, key: "Unsupported locale {0}." }, - Unable_to_open_file_0: { code: -9999999, category: DiagnosticCategory.Error, key: "Unable to open file {0}." }, - Corrupted_locale_file_0: { code: -9999999, category: DiagnosticCategory.Error, key: "Corrupted locale file {0}." }, - No_input_files_specified: { code: -9999999, category: DiagnosticCategory.Error, key: "No input files specified." }, }; } \ No newline at end of file diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index d4ae58e870544..30bd7d0a1edc4 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -862,7 +862,7 @@ "category": "Message", "code": 6001 }, - "Generates corresponding {0} file.": { + "Generates corresponding '.d.ts' file.": { "category": "Message", "code": 6002 }, @@ -890,11 +890,11 @@ "category": "Message", "code": 6010 }, - "Specify ECMAScript target version: '{0}' (default), or '{1}'": { + "Specify ECMAScript target version: 'ES3' (default), or 'ES5'": { "category": "Message", "code": 6015 }, - "Specify module code generation: '{0}' or '{1}'": { + "Specify module code generation: 'commonjs' or 'amd'": { "category": "Message", "code": 6016 }, @@ -902,7 +902,7 @@ "category": "Message", "code": 6017 }, - "Print the compiler's version: {0}": { + "Print the compiler's version.": { "category": "Message", "code": 6019 }, @@ -914,7 +914,7 @@ "category": "Message", "code": 6022 }, - "Syntax: {0}": { + "Syntax: {0}": { "category": "Message", "code": 6023 }, @@ -926,7 +926,7 @@ "category": "Message", "code": 6025 }, - "Examples:": { + "Examples: {0}": { "category": "Message", "code": 6026 }, @@ -994,11 +994,54 @@ "category": "Message", "code": 6042 }, + "Generates corresponding '.map' file.": { + "category": "Message", + "code": 6043 + }, + "Compiler option '{0}' expects an argument.": { + "category": "Error", + "code": 6044 + }, + "Unterminated quoted string in response file '{0}'.": { + "category": "Error", + "code": 6045 + }, + "Argument for '--module' option must be 'commonjs' or 'amd'.": { + "category": "Error", + "code": 6045 + }, + "Argument for '--target' option must be 'es3' or 'es5'.": { + "category": "Error", + "code": 6046 + }, + "Locale must be of the form or -. For example '{0}' or '{1}'.": { + "category": "Error", + "code": 6047 + }, + "Unsupported locale '{0}'.": { + "category": "Error", + "code": 6048 + }, + "Unable to open file '{0}'.": { + "category": "Error", + "code": 6049 + }, + "Corrupted locale file {0}.": { + "category": "Error", + "code": 6050 + }, + "No input files specified.": { + "category": "Error", + "code": 6051 + }, + "Warn on expressions and declarations with an implied 'any' type.": { + "category": "Message", + "code": 7004 + }, "Variable '{0}' implicitly has an '{1}' type.": { "category": "Error", "code": 7005 }, - "Parameter '{0}' implicitly has an '{1}' type.": { "category": "Error", "code": 7006 @@ -1358,41 +1401,5 @@ "Filename '{0}' differs from already included filename '{1}' only in casing": { "category": "Error", "code": -9999999 - }, - "Argument for '--module' option must be 'commonjs' or 'amd'.": { - "category": "Error", - "code": -9999999 - }, - "Argument for '--target' option must be 'es3' or 'es5'.": { - "category": "Error", - "code": -9999999 - }, - "Compiler option '{0}' expects an argument.": { - "category": "Error", - "code": -9999999 - }, - "Unterminated quoted string in response file '{0}'.": { - "category": "Error", - "code": -9999999 - }, - "Locale must be of the form or -. For example '{0}' or '{1}'.": { - "category": "Error", - "code": -9999999 - }, - "Unsupported locale {0}.": { - "category": "Error", - "code": -9999999 - }, - "Unable to open file {0}.": { - "category": "Error", - "code": -9999999 - }, - "Corrupted locale file {0}.": { - "category": "Error", - "code": -9999999 - }, - "No input files specified.": { - "category": "Error", - "code": -9999999 } } \ No newline at end of file diff --git a/src/compiler/tc.ts b/src/compiler/tc.ts index fc508ed459ced..3baefd00ad03e 100644 --- a/src/compiler/tc.ts +++ b/src/compiler/tc.ts @@ -78,19 +78,24 @@ module ts { return count; } - function reportDiagnostic(error: Diagnostic) { - if (error.file) { - var loc = error.file.getLineAndCharacterFromPosition(error.start); - sys.write(error.file.filename + "(" + loc.line + "," + loc.character + "): " + error.messageText + sys.newLine); + function getDiagnosticText(message: DiagnosticMessage, ...args: any[]): string { + var diagnostic: Diagnostic = createCompilerDiagnostic.apply(undefined, arguments); + return diagnostic.messageText; + } + + function reportDiagnostic(diagnostic: Diagnostic) { + if (diagnostic.file) { + var loc = diagnostic.file.getLineAndCharacterFromPosition(diagnostic.start); + sys.write(diagnostic.file.filename + "(" + loc.line + "," + loc.character + "): " + diagnostic.messageText + sys.newLine); } else { - sys.write(error.messageText + sys.newLine); + sys.write(diagnostic.messageText + sys.newLine); } } - function reportDiagnostics(errors: Diagnostic[]) { - for (var i = 0; i < errors.length; i++) { - reportDiagnostic(errors[i]); + function reportDiagnostics(diagnostics: Diagnostic[]) { + for (var i = 0; i < diagnostics.length; i++) { + reportDiagnostic(diagnostics[i]); } } @@ -179,29 +184,33 @@ module ts { } export function executeCommandLine(args: string[]): void { + var exitCode = 0; var commandLine = parseCommandLine(args); if (commandLine.options.locale) { validateLocaleAndSetLanguage(commandLine.options.locale, commandLine.errors); } - if (commandLine.options.version) { - reportDiagnostic(createCompilerDiagnostic(Diagnostics.Version_0, version)); - sys.exit(0); + // Report all errors at this point, even if there are none. + if (commandLine.errors.length > 0) { + reportDiagnostics(commandLine.errors); + exitCode = 1; } - if (commandLine.options.help) { - // TODO (drosen): Usage. - sys.exit(0); + if (commandLine.options.version) { + reportDiagnostic(createCompilerDiagnostic(Diagnostics.Version_0, version)); + sys.exit(exitCode); } - if (commandLine.filenames.length === 0) { - commandLine.errors.push(createCompilerDiagnostic(Diagnostics.No_input_files_specified)); + if (commandLine.options.help || commandLine.filenames.length === 0) { + printVersion(); + printHelp(); + sys.exit(exitCode); } - if (commandLine.errors.length) { - reportDiagnostics(commandLine.errors); - sys.exit(1); + // If we encountered an error before we even started compiling, just bail out. + if (exitCode !== 0) { + sys.exit(exitCode); } var defaultCompilerHost = createCompilerHost(commandLine.options); @@ -338,6 +347,105 @@ module ts { return { program: program, errors: errors }; } + + function printVersion() { + sys.write(getDiagnosticText(Diagnostics.Version_0, version) + sys.newLine); + } + + function printHelp() { + var output = ""; + + // We want to align our "syntax" and "examples" commands to a certain margin. + var syntaxLength = getDiagnosticText(Diagnostics.Syntax_Colon_0, "").length + var examplesLength = getDiagnosticText(Diagnostics.Examples_Colon_0, "").length + var marginLength = Math.max(syntaxLength, examplesLength); + + // Build up the syntactic skeleton. + var syntax = makePadding(marginLength - syntaxLength); + syntax += "tsc [" + getDiagnosticText(Diagnostics.options) + "] [" + getDiagnosticText(Diagnostics.file) + " ...]"; + + output += getDiagnosticText(Diagnostics.Syntax_Colon_0, syntax); + output += sys.newLine + sys.newLine; + + // Build up the examples. + var padding = makePadding(marginLength); + output += getDiagnosticText(Diagnostics.Examples_Colon_0, makePadding(marginLength - examplesLength) + "tsc hello.ts") + sys.newLine; + output += padding + "tsc --out foo.js foo.ts" + sys.newLine; + output += padding + "tsc @args.txt" + sys.newLine; + output += sys.newLine; + + // Sort our options by their command names, (e.g. "--noImplicitAny" comes before "--watch") + output += getDiagnosticText(Diagnostics.Options_Colon) + sys.newLine; + + var optsList = optionDeclarations.slice().sort((a, b) => { + var aName = a.name.toLowerCase(); + var bName = b.name.toLowerCase(); + return compareValues(aName, bName); + }); + + // We want our descriptions to align at the same column in our output, + // so we keep track of the longest option usage string. + var marginLength = 0; + var usageColumn: string[] = []; // Things like "-d, --declaration" go in here. + var descriptionColumn: string[] = []; + + for (var i = 0; i < optsList.length; i++) { + var option = optsList[i]; + + // If an option lacks a description, + // it is not officially supported. + if (!option.description) { + continue; + } + + var usageText = " "; + if (option.shortName) { + usageText += "-" + option.shortName; + usageText += getParamName(option); + usageText += ", "; + } + + usageText += "--" + option.name; + usageText += getParamName(option); + + usageColumn.push(usageText); + descriptionColumn.push(getDiagnosticText(option.description)); + + // Set the new margin for the description column if necessary. + if (usageText.length > marginLength) { + marginLength = usageText.length; + } + } + + // Special case that can't fit in the loop. + var usageText = " @<" + getDiagnosticText(Diagnostics.file) + ">"; + usageColumn.push(usageText); + descriptionColumn.push(getDiagnosticText(Diagnostics.Insert_command_line_options_and_files_from_a_file)); + if (usageText.length > marginLength) { + marginLength = usageText.length; + } + + // Print out each row, aligning all the descriptions on the same column. + for (var i = 0; i < usageColumn.length; i++) { + var usage = usageColumn[i]; + var description = descriptionColumn[i]; + output += usage + makePadding(marginLength - usage.length + 2) + description + sys.newLine; + } + + sys.write(output); + return; + + function getParamName(option: CommandLineOption) { + if (option.paramName !== undefined) { + return " " + getDiagnosticText(option.paramName); + } + return ""; + } + + function makePadding(paddingLength: number): string { + return Array(paddingLength + 1).join(" "); + } + } } ts.executeCommandLine(sys.args); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 316ae5410c048..3d5c176d27257 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -953,7 +953,10 @@ module ts { export interface CommandLineOption { name: string; type: any; - error?: DiagnosticMessage; + shortName?: string; + description?: DiagnosticMessage; + paramName?: DiagnosticMessage; // The name to be used for a non-boolean option's parameter. + error?: DiagnosticMessage; // The error given when the argument does not fit a customized 'type'. } export enum CharacterCodes { From e05e7836e3fd97398c4ad66514d3494506e048cd Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 4 Aug 2014 12:01:27 -0700 Subject: [PATCH 3/8] Style and comments. --- src/compiler/tc.ts | 19 +++++++++---------- src/compiler/types.ts | 10 +++++----- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/compiler/tc.ts b/src/compiler/tc.ts index 3baefd00ad03e..d38aca5a055de 100644 --- a/src/compiler/tc.ts +++ b/src/compiler/tc.ts @@ -9,10 +9,12 @@ /// module ts { - export var version = "1.1.0.0"; + 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. + /** + * Checks to see if the locale is in the appropriate format, + * and if it is, attempts to set the appropriate language. + */ function validateLocaleAndSetLanguage(locale: string, errors: Diagnostic[]): boolean { var matchResult = /^([a-z]+)([_\-]([a-z]+))?$/.exec(locale.toLowerCase()); @@ -367,21 +369,18 @@ module ts { output += getDiagnosticText(Diagnostics.Syntax_Colon_0, syntax); output += sys.newLine + sys.newLine; - // Build up the examples. + // Build up the list of examples. var padding = makePadding(marginLength); output += getDiagnosticText(Diagnostics.Examples_Colon_0, makePadding(marginLength - examplesLength) + "tsc hello.ts") + sys.newLine; output += padding + "tsc --out foo.js foo.ts" + sys.newLine; output += padding + "tsc @args.txt" + sys.newLine; output += sys.newLine; - // Sort our options by their command names, (e.g. "--noImplicitAny" comes before "--watch") output += getDiagnosticText(Diagnostics.Options_Colon) + sys.newLine; - var optsList = optionDeclarations.slice().sort((a, b) => { - var aName = a.name.toLowerCase(); - var bName = b.name.toLowerCase(); - return compareValues(aName, bName); - }); + // Sort our options by their names, (e.g. "--noImplicitAny" comes before "--watch") + var optsList = optionDeclarations.slice(); + optsList.sort((a, b) => compareValues(a.name.toLowerCase(), b.name.toLowerCase())); // We want our descriptions to align at the same column in our output, // so we keep track of the longest option usage string. diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 3d5c176d27257..6ff7bfc358616 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -952,11 +952,11 @@ module ts { export interface CommandLineOption { name: string; - type: any; - shortName?: string; - description?: DiagnosticMessage; - paramName?: DiagnosticMessage; // The name to be used for a non-boolean option's parameter. - error?: DiagnosticMessage; // The error given when the argument does not fit a customized 'type'. + type: any; // "string", "number", "boolean", or an object literal mapping named values to actual values + shortName?: string; // A short pneumonic for convenience - for instance, 'h' can be used in place of 'help'. + description?: DiagnosticMessage; // The message describing what the command line switch does + paramName?: DiagnosticMessage; // The name to be used for a non-boolean option's parameter. + error?: DiagnosticMessage; // The error given when the argument does not fit a customized 'type'. } export enum CharacterCodes { From a64db42337afc44f9893ef22ff326cee19a905bf Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 4 Aug 2014 12:28:46 -0700 Subject: [PATCH 4/8] Got rid of that cscript-breaking comma. --- src/compiler/commandLineParser.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 8d0f977dddb11..25d304bda7f3f 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -114,7 +114,7 @@ module ts { shortName: "w", type: "boolean", description: Diagnostics.Watch_input_files, - }, + } ]; var shortOptionNames: Map = {}; From 348d0fca21cb8832ebdcb3f45cd4f3a596777f94 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 4 Aug 2014 17:52:58 -0700 Subject: [PATCH 5/8] Addressed code review feedback. --- scripts/processDiagnosticMessages.ts | 24 +++++++++++++++--------- src/compiler/tc.ts | 23 +++++++---------------- 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/scripts/processDiagnosticMessages.ts b/scripts/processDiagnosticMessages.ts index 31449c88e3a32..6a4aaad9f93ee 100644 --- a/scripts/processDiagnosticMessages.ts +++ b/scripts/processDiagnosticMessages.ts @@ -39,7 +39,7 @@ function main(): void { function buildUniqueNameMap(names: string[]): IIndexable { var nameMap: IIndexable = {}; - var uniqueNames = NameGenerator.ensureUniqueness(names, /*isFixed */ undefined, /* isCaseSensitive */ false); + var uniqueNames = NameGenerator.ensureUniqueness(names, /* isCaseSensitive */ false, /* isFixed */ undefined); for (var i = 0; i < names.length; i++) { nameMap[names[i]] = uniqueNames[i]; @@ -94,14 +94,17 @@ function convertPropertyName(origName: string): string { } module NameGenerator { - export function ensureUniqueness(names: string[], isFixed: boolean[] = names.map(() => false), isCaseSensitive: boolean = false): string[] { + export function ensureUniqueness(names: string[], isCaseSensitive: boolean, isFixed?: boolean[]): string[]{ + if (!isFixed) { + isFixed = names.map(() => false) + } - var names = names.map(x => x); - ensureUniquenessInPlace(names, isFixed, isCaseSensitive); + var names = names.slice(); + ensureUniquenessInPlace(names, isCaseSensitive, isFixed); return names; } - function ensureUniquenessInPlace(names: string[], isFixed: boolean[], isCaseSensitive: boolean): void { + function ensureUniquenessInPlace(names: string[], isCaseSensitive: boolean, isFixed: boolean[]): void { for (var i = 0; i < names.length; i++) { var name = names[i]; var collisionIndices = Utilities.collectMatchingIndices(name, names, isCaseSensitive); @@ -128,9 +131,12 @@ module NameGenerator { } while (true) { - var newName = name + suffix++; + var newName = name + suffix; + suffix++; - if (!proposedNames.some((name) => Utilities.stringEquals(name, newName, isCaseSensitive))) { + // Check if we've synthesized a unique name, and if so + // replace the conflicting name with the new one. + if (!proposedNames.some(name => Utilities.stringEquals(name, newName, isCaseSensitive))) { proposedNames[collisionIndex] = newName; break; } @@ -141,7 +147,7 @@ module NameGenerator { module Utilities { /// Return a list of all indices where a string occurs. - export function collectMatchingIndices(name: string, proposedNames: string[], isCaseSensitive: boolean = false): number[] { + export function collectMatchingIndices(name: string, proposedNames: string[], isCaseSensitive: boolean): number[] { var matchingIndices: number[] = []; for (var i = 0; i < proposedNames.length; i++) { @@ -153,7 +159,7 @@ module Utilities { return matchingIndices; } - export function stringEquals(s1: string, s2: string, caseSensitive: boolean = false): boolean { + export function stringEquals(s1: string, s2: string, caseSensitive: boolean): boolean { if (caseSensitive) { s1 = s1.toLowerCase(); s2 = s2.toLowerCase(); diff --git a/src/compiler/tc.ts b/src/compiler/tc.ts index d38aca5a055de..614a20aa21a4d 100644 --- a/src/compiler/tc.ts +++ b/src/compiler/tc.ts @@ -186,33 +186,28 @@ module ts { } export function executeCommandLine(args: string[]): void { - var exitCode = 0; var commandLine = parseCommandLine(args); if (commandLine.options.locale) { validateLocaleAndSetLanguage(commandLine.options.locale, commandLine.errors); } - // Report all errors at this point, even if there are none. + // If there are any errors due to command line parsing and/or + // setting up localization, report them and quit. if (commandLine.errors.length > 0) { reportDiagnostics(commandLine.errors); - exitCode = 1; + sys.exit(1); } if (commandLine.options.version) { reportDiagnostic(createCompilerDiagnostic(Diagnostics.Version_0, version)); - sys.exit(exitCode); + sys.exit(0); } if (commandLine.options.help || commandLine.filenames.length === 0) { printVersion(); printHelp(); - sys.exit(exitCode); - } - - // If we encountered an error before we even started compiling, just bail out. - if (exitCode !== 0) { - sys.exit(exitCode); + sys.exit(0); } var defaultCompilerHost = createCompilerHost(commandLine.options); @@ -411,18 +406,14 @@ module ts { descriptionColumn.push(getDiagnosticText(option.description)); // Set the new margin for the description column if necessary. - if (usageText.length > marginLength) { - marginLength = usageText.length; - } + marginLength = Math.max(usageText.length, marginLength); } // Special case that can't fit in the loop. var usageText = " @<" + getDiagnosticText(Diagnostics.file) + ">"; usageColumn.push(usageText); descriptionColumn.push(getDiagnosticText(Diagnostics.Insert_command_line_options_and_files_from_a_file)); - if (usageText.length > marginLength) { - marginLength = usageText.length; - } + marginLength = Math.max(usageText.length, marginLength); // Print out each row, aligning all the descriptions on the same column. for (var i = 0; i < usageColumn.length; i++) { From a1a1ea3f96188eb4ad63a1a0cffb626af1720ee6 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 4 Aug 2014 18:00:33 -0700 Subject: [PATCH 6/8] Fixed up duplicate diagnostic. --- src/compiler/diagnosticInformationMap.generated.ts | 2 +- src/compiler/diagnosticMessages.json | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 0299cbe846d46..b29bbf7f3b243 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -235,8 +235,8 @@ module ts { file: { code: 6025, category: DiagnosticCategory.Message, key: "file" }, Examples_Colon_0: { code: 6026, category: DiagnosticCategory.Message, key: "Examples: {0}" }, Options_Colon: { code: 6027, category: DiagnosticCategory.Message, key: "Options:" }, - Insert_command_line_options_and_files_from_a_file: { code: 6030, category: DiagnosticCategory.Message, key: "Insert command line options and files from a file." }, Version_0: { code: 6029, category: DiagnosticCategory.Message, key: "Version {0}" }, + Insert_command_line_options_and_files_from_a_file: { code: 6030, category: DiagnosticCategory.Message, key: "Insert command line options and files from a file." }, Use_the_0_flag_to_see_options: { code: 6031, category: DiagnosticCategory.Message, key: "Use the '{0}' flag to see options." }, File_Changed_Compiling: { code: 6032, category: DiagnosticCategory.Message, key: "File Changed. Compiling." }, STRING: { code: 6033, category: DiagnosticCategory.Message, key: "STRING" }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 30bd7d0a1edc4..6ce94b1440416 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -934,10 +934,7 @@ "category": "Message", "code": 6027 }, - "Insert command line options and files from a file.": { - "category": "Message", - "code": 6028 - }, + "Version {0}": { "category": "Message", "code": 6029 From 078e49dd8bed70b2d02cd0f96b6f56f0d8503987 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 4 Aug 2014 18:29:58 -0700 Subject: [PATCH 7/8] Explicitly supply generic argument for 'compareValues'. --- src/compiler/tc.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/tc.ts b/src/compiler/tc.ts index 614a20aa21a4d..ee1089f7c6c34 100644 --- a/src/compiler/tc.ts +++ b/src/compiler/tc.ts @@ -375,7 +375,7 @@ module ts { // Sort our options by their names, (e.g. "--noImplicitAny" comes before "--watch") var optsList = optionDeclarations.slice(); - optsList.sort((a, b) => compareValues(a.name.toLowerCase(), b.name.toLowerCase())); + optsList.sort((a, b) => compareValues(a.name.toLowerCase(), b.name.toLowerCase())); // We want our descriptions to align at the same column in our output, // so we keep track of the longest option usage string. From a24b175586c841b25a8ea195c572ad347f8f027d Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 5 Aug 2014 12:51:17 -0700 Subject: [PATCH 8/8] Perform an explicit return just in case sys.exit fails. --- src/compiler/tc.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/compiler/tc.ts b/src/compiler/tc.ts index 77caacbe1495e..5009e4c7a97d4 100644 --- a/src/compiler/tc.ts +++ b/src/compiler/tc.ts @@ -197,32 +197,33 @@ module ts { // setting up localization, report them and quit. if (commandLine.errors.length > 0) { reportDiagnostics(commandLine.errors); - sys.exit(1); + return sys.exit(1); } if (commandLine.options.version) { reportDiagnostic(createCompilerDiagnostic(Diagnostics.Version_0, version)); - sys.exit(0); + return sys.exit(0); } if (commandLine.options.help || commandLine.filenames.length === 0) { printVersion(); printHelp(); - sys.exit(0); + return sys.exit(0); } var defaultCompilerHost = createCompilerHost(commandLine.options); - + if (commandLine.options.watch) { if (!sys.watchFile) { reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--watch")); - sys.exit(1); + return sys.exit(1); } watchProgram(commandLine, defaultCompilerHost); } else { - sys.exit(compile(commandLine, defaultCompilerHost).errors.length > 0 ? 1 : 0); + var result = compile(commandLine, defaultCompilerHost).errors.length > 0 ? 1 : 0; + return sys.exit(result); } }