Skip to content

Commit 2dd9763

Browse files
Implemented --help.
1 parent 616dae2 commit 2dd9763

File tree

6 files changed

+320
-116
lines changed

6 files changed

+320
-116
lines changed

src/compiler/commandLineParser.ts

+121-37
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,128 @@
44
/// <reference path="scanner.ts"/>
55

66
module ts {
7-
var shortOptionNames: Map<string> = {
8-
"d": "declaration",
9-
"h": "help",
10-
"m": "module",
11-
"o": "out",
12-
"t": "target",
13-
"v": "version",
14-
"w": "watch",
15-
};
16-
17-
var optionDeclarations: CommandLineOption[] = [
18-
{ name: "charset", type: "string" },
19-
{ name: "codepage", type: "number" },
20-
{ name: "declaration", type: "boolean" },
21-
{ name: "diagnostics", type: "boolean" },
22-
{ name: "help", type: "boolean" },
23-
{ name: "locale", type: "string" },
24-
{ name: "mapRoot", type: "string" },
25-
{ name: "module", type: { "commonjs": ModuleKind.CommonJS, "amd": ModuleKind.AMD }, error: Diagnostics.Argument_for_module_option_must_be_commonjs_or_amd },
26-
{ name: "noImplicitAny", type: "boolean" },
27-
{ name: "noLib", type: "boolean" },
28-
{ name: "noLibCheck", type: "boolean" },
29-
{ name: "noResolve", type: "boolean" },
30-
{ name: "out", type: "string" },
31-
{ name: "outDir", type: "string" },
32-
{ name: "removeComments", type: "boolean" },
33-
{ name: "sourceMap", type: "boolean" },
34-
{ name: "sourceRoot", type: "string" },
35-
{ name: "target", type: { "es3": ScriptTarget.ES3, "es5": ScriptTarget.ES5 }, error: Diagnostics.Argument_for_target_option_must_be_es3_or_es5 },
36-
{ name: "version", type: "boolean" },
37-
{ name: "watch", type: "boolean" },
7+
export var optionDeclarations: CommandLineOption[] = [
8+
{
9+
name: "charset",
10+
type: "string",
11+
},
12+
{
13+
name: "codepage",
14+
type: "number",
15+
},
16+
{
17+
name: "declaration",
18+
shortName: "d",
19+
type: "boolean",
20+
description: Diagnostics.Generates_corresponding_d_ts_file,
21+
},
22+
{
23+
name: "diagnostics",
24+
type: "boolean",
25+
},
26+
{
27+
name: "help",
28+
shortName: "h",
29+
type: "boolean",
30+
description: Diagnostics.Print_this_message,
31+
},
32+
{
33+
name: "locale",
34+
type: "string",
35+
},
36+
{
37+
name: "mapRoot",
38+
type: "string",
39+
description: Diagnostics.Specifies_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations,
40+
paramType: Diagnostics.LOCATION,
41+
},
42+
{
43+
name: "module",
44+
shortName: "m",
45+
type: {
46+
"commonjs": ModuleKind.CommonJS,
47+
"amd": ModuleKind.AMD
48+
},
49+
description: Diagnostics.Specify_module_code_generation_Colon_commonjs_or_amd,
50+
paramType: Diagnostics.KIND,
51+
error: Diagnostics.Argument_for_module_option_must_be_commonjs_or_amd
52+
},
53+
{
54+
name: "noImplicitAny",
55+
type: "boolean",
56+
description: Diagnostics.Warn_on_expressions_and_declarations_with_an_implied_any_type,
57+
},
58+
{
59+
name: "noLib",
60+
type: "boolean",
61+
},
62+
{
63+
name: "noLibCheck",
64+
type: "boolean",
65+
},
66+
{
67+
name: "noResolve",
68+
type: "boolean",
69+
},
70+
{
71+
name: "out",
72+
type: "string",
73+
description: Diagnostics.Concatenate_and_emit_output_to_single_file,
74+
paramType: Diagnostics.FILE,
75+
},
76+
{
77+
name: "outDir",
78+
type: "string",
79+
description: Diagnostics.Redirect_output_structure_to_the_directory,
80+
paramType: Diagnostics.DIRECTORY,
81+
},
82+
{
83+
name: "removeComments",
84+
type: "boolean",
85+
description: Diagnostics.Do_not_emit_comments_to_output,
86+
},
87+
{
88+
name: "sourcemap",
89+
type: "boolean",
90+
description: Diagnostics.Generates_corresponding_map_file,
91+
},
92+
{
93+
name: "sourceRoot",
94+
type: "string",
95+
description: Diagnostics.Specifies_the_location_where_debugger_should_locate_TypeScript_files_instead_of_source_locations,
96+
paramType: Diagnostics.LOCATION,
97+
},
98+
{
99+
name: "target",
100+
shortName: "t",
101+
type: { "es3": ScriptTarget.ES3, "es5": ScriptTarget.ES5 },
102+
description: Diagnostics.Specify_ECMAScript_target_version_Colon_ES3_default_or_ES5,
103+
paramType: Diagnostics.VERSION,
104+
error: Diagnostics.Argument_for_target_option_must_be_es3_or_es5
105+
},
106+
{
107+
name: "version",
108+
shortName: "v",
109+
type: "boolean",
110+
description: Diagnostics.Print_the_compiler_s_version,
111+
},
112+
{
113+
name: "watch",
114+
shortName: "w",
115+
type: "boolean",
116+
description: Diagnostics.Watch_input_files,
117+
},
38118
];
39119

40-
// Map command line switches to compiler options' property descriptors. Keys must be lower case spellings of command line switches.
41-
// The 'name' property specifies the property name in the CompilerOptions type. The 'type' property specifies the type of the option.
42-
var optionMap: Map<CommandLineOption> = {};
120+
var shortOptionNames: Map<string> = {};
121+
var optionNameMap: Map<CommandLineOption> = {};
122+
43123
forEach(optionDeclarations, option => {
44-
optionMap[option.name.toLowerCase()] = option;
124+
optionNameMap[option.name.toLowerCase()] = option;
125+
126+
if (option.shortName) {
127+
shortOptionNames[option.shortName] = option.name;
128+
}
45129
});
46130

47131
export function parseCommandLine(commandLine: string[]): ParsedCommandLine {
@@ -75,8 +159,8 @@ module ts {
75159
s = shortOptionNames[s];
76160
}
77161

78-
if (hasProperty(optionMap, s)) {
79-
var opt = optionMap[s];
162+
if (hasProperty(optionNameMap, s)) {
163+
var opt = optionNameMap[s];
80164

81165
// Check to see if no argument was provided (e.g. "--locale" is the last command-line argument).
82166
if (!args[i] && opt.type !== "boolean") {

src/compiler/core.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ module ts {
247247
};
248248
}
249249

250-
function compareValues(a: any, b: any): number {
250+
export function compareValues<T>(a: T, b: T): number {
251251
if (a === b) return 0;
252252
if (a === undefined) return -1;
253253
if (b === undefined) return 1;

src/compiler/diagnosticInformationMap.generated.ts

+17-15
Original file line numberDiff line numberDiff line change
@@ -217,23 +217,23 @@ module ts {
217217
Option_mapRoot_cannot_be_specified_without_specifying_sourcemap_option: { code: 5038, category: DiagnosticCategory.Error, key: "Option mapRoot cannot be specified without specifying sourcemap option." },
218218
Option_sourceRoot_cannot_be_specified_without_specifying_sourcemap_option: { code: 5039, category: DiagnosticCategory.Error, key: "Option sourceRoot cannot be specified without specifying sourcemap option." },
219219
Concatenate_and_emit_output_to_single_file: { code: 6001, category: DiagnosticCategory.Message, key: "Concatenate and emit output to single file." },
220-
Generates_corresponding_0_file: { code: 6002, category: DiagnosticCategory.Message, key: "Generates corresponding {0} file." },
220+
Generates_corresponding_d_ts_file: { code: 6002, category: DiagnosticCategory.Message, key: "Generates corresponding '.d.ts' file." },
221221
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." },
222222
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." },
223223
Watch_input_files: { code: 6005, category: DiagnosticCategory.Message, key: "Watch input files." },
224224
Redirect_output_structure_to_the_directory: { code: 6006, category: DiagnosticCategory.Message, key: "Redirect output structure to the directory." },
225225
Do_not_emit_comments_to_output: { code: 6009, category: DiagnosticCategory.Message, key: "Do not emit comments to output." },
226226
Skip_resolution_and_preprocessing: { code: 6010, category: DiagnosticCategory.Message, key: "Skip resolution and preprocessing." },
227-
Specify_ECMAScript_target_version_Colon_0_default_or_1: { code: 6015, category: DiagnosticCategory.Message, key: "Specify ECMAScript target version: '{0}' (default), or '{1}'" },
228-
Specify_module_code_generation_Colon_0_or_1: { code: 6016, category: DiagnosticCategory.Message, key: "Specify module code generation: '{0}' or '{1}'" },
227+
Specify_ECMAScript_target_version_Colon_ES3_default_or_ES5: { code: 6015, category: DiagnosticCategory.Message, key: "Specify ECMAScript target version: 'ES3' (default), or 'ES5'" },
228+
Specify_module_code_generation_Colon_commonjs_or_amd: { code: 6016, category: DiagnosticCategory.Message, key: "Specify module code generation: 'commonjs' or 'amd'" },
229229
Print_this_message: { code: 6017, category: DiagnosticCategory.Message, key: "Print this message." },
230-
Print_the_compiler_s_version_Colon_0: { code: 6019, category: DiagnosticCategory.Message, key: "Print the compiler's version: {0}" },
230+
Print_the_compiler_s_version: { code: 6019, category: DiagnosticCategory.Message, key: "Print the compiler's version." },
231231
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." },
232232
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}'" },
233-
Syntax_Colon_0: { code: 6023, category: DiagnosticCategory.Message, key: "Syntax: {0}" },
233+
Syntax_Colon_0: { code: 6023, category: DiagnosticCategory.Message, key: "Syntax: {0}" },
234234
options: { code: 6024, category: DiagnosticCategory.Message, key: "options" },
235235
file: { code: 6025, category: DiagnosticCategory.Message, key: "file" },
236-
Examples_Colon: { code: 6026, category: DiagnosticCategory.Message, key: "Examples:" },
236+
Examples_Colon_0: { code: 6026, category: DiagnosticCategory.Message, key: "Examples: {0}" },
237237
Options_Colon: { code: 6027, category: DiagnosticCategory.Message, key: "Options:" },
238238
Insert_command_line_options_and_files_from_a_file: { code: 6030, category: DiagnosticCategory.Message, key: "Insert command line options and files from a file." },
239239
Version_0: { code: 6029, category: DiagnosticCategory.Message, key: "Version {0}" },
@@ -249,6 +249,17 @@ module ts {
249249
Specify_the_codepage_to_use_when_opening_source_files: { code: 6040, category: DiagnosticCategory.Message, key: "Specify the codepage to use when opening source files." },
250250
Additional_locations_Colon: { code: 6041, category: DiagnosticCategory.Message, key: "Additional locations:" },
251251
Compile_complete_Listening_for_changed_files: { code: 6042, category: DiagnosticCategory.Message, key: "Compile complete. Listening for changed files." },
252+
Generates_corresponding_map_file: { code: 6043, category: DiagnosticCategory.Message, key: "Generates corresponding '.map' file." },
253+
Compiler_option_0_expects_an_argument: { code: 6044, category: DiagnosticCategory.Error, key: "Compiler option '{0}' expects an argument." },
254+
Unterminated_quoted_string_in_response_file_0: { code: 6045, category: DiagnosticCategory.Error, key: "Unterminated quoted string in response file '{0}'." },
255+
Argument_for_module_option_must_be_commonjs_or_amd: { code: 6045, category: DiagnosticCategory.Error, key: "Argument for '--module' option must be 'commonjs' or 'amd'." },
256+
Argument_for_target_option_must_be_es3_or_es5: { code: 6046, category: DiagnosticCategory.Error, key: "Argument for '--target' option must be 'es3' or 'es5'." },
257+
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 <language> or <language>-<territory>. For example '{0}' or '{1}'." },
258+
Unsupported_locale_0: { code: 6048, category: DiagnosticCategory.Error, key: "Unsupported locale '{0}'." },
259+
Unable_to_open_file_0: { code: 6049, category: DiagnosticCategory.Error, key: "Unable to open file '{0}'." },
260+
Corrupted_locale_file_0: { code: 6050, category: DiagnosticCategory.Error, key: "Corrupted locale file {0}." },
261+
No_input_files_specified: { code: 6051, category: DiagnosticCategory.Error, key: "No input files specified." },
262+
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." },
252263
Variable_0_implicitly_has_an_1_type: { code: 7005, category: DiagnosticCategory.Error, key: "Variable '{0}' implicitly has an '{1}' type." },
253264
Parameter_0_implicitly_has_an_1_type: { code: 7006, category: DiagnosticCategory.Error, key: "Parameter '{0}' implicitly has an '{1}' type." },
254265
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 {
334345
Import_declaration_conflicts_with_local_declaration_of_0: { code: -9999999, category: DiagnosticCategory.Error, key: "Import declaration conflicts with local declaration of '{0}'" },
335346
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" },
336347
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" },
337-
Argument_for_module_option_must_be_commonjs_or_amd: { code: -9999999, category: DiagnosticCategory.Error, key: "Argument for '--module' option must be 'commonjs' or 'amd'." },
338-
Argument_for_target_option_must_be_es3_or_es5: { code: -9999999, category: DiagnosticCategory.Error, key: "Argument for '--target' option must be 'es3' or 'es5'." },
339-
Compiler_option_0_expects_an_argument: { code: -9999999, category: DiagnosticCategory.Error, key: "Compiler option '{0}' expects an argument." },
340-
Unterminated_quoted_string_in_response_file_0: { code: -9999999, category: DiagnosticCategory.Error, key: "Unterminated quoted string in response file '{0}'." },
341-
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 <language> or <language>-<territory>. For example '{0}' or '{1}'." },
342-
Unsupported_locale_0: { code: -9999999, category: DiagnosticCategory.Error, key: "Unsupported locale {0}." },
343-
Unable_to_open_file_0: { code: -9999999, category: DiagnosticCategory.Error, key: "Unable to open file {0}." },
344-
Corrupted_locale_file_0: { code: -9999999, category: DiagnosticCategory.Error, key: "Corrupted locale file {0}." },
345-
No_input_files_specified: { code: -9999999, category: DiagnosticCategory.Error, key: "No input files specified." },
346348
};
347349
}

src/compiler/diagnosticMessages.json

+50-43
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@
862862
"category": "Message",
863863
"code": 6001
864864
},
865-
"Generates corresponding {0} file.": {
865+
"Generates corresponding '.d.ts' file.": {
866866
"category": "Message",
867867
"code": 6002
868868
},
@@ -890,19 +890,19 @@
890890
"category": "Message",
891891
"code": 6010
892892
},
893-
"Specify ECMAScript target version: '{0}' (default), or '{1}'": {
893+
"Specify ECMAScript target version: 'ES3' (default), or 'ES5'": {
894894
"category": "Message",
895895
"code": 6015
896896
},
897-
"Specify module code generation: '{0}' or '{1}'": {
897+
"Specify module code generation: 'commonjs' or 'amd'": {
898898
"category": "Message",
899899
"code": 6016
900900
},
901901
"Print this message.": {
902902
"category": "Message",
903903
"code": 6017
904904
},
905-
"Print the compiler's version: {0}": {
905+
"Print the compiler's version.": {
906906
"category": "Message",
907907
"code": 6019
908908
},
@@ -914,7 +914,7 @@
914914
"category": "Message",
915915
"code": 6022
916916
},
917-
"Syntax: {0}": {
917+
"Syntax: {0}": {
918918
"category": "Message",
919919
"code": 6023
920920
},
@@ -926,7 +926,7 @@
926926
"category": "Message",
927927
"code": 6025
928928
},
929-
"Examples:": {
929+
"Examples: {0}": {
930930
"category": "Message",
931931
"code": 6026
932932
},
@@ -994,11 +994,54 @@
994994
"category": "Message",
995995
"code": 6042
996996
},
997+
"Generates corresponding '.map' file.": {
998+
"category": "Message",
999+
"code": 6043
1000+
},
1001+
"Compiler option '{0}' expects an argument.": {
1002+
"category": "Error",
1003+
"code": 6044
1004+
},
1005+
"Unterminated quoted string in response file '{0}'.": {
1006+
"category": "Error",
1007+
"code": 6045
1008+
},
1009+
"Argument for '--module' option must be 'commonjs' or 'amd'.": {
1010+
"category": "Error",
1011+
"code": 6045
1012+
},
1013+
"Argument for '--target' option must be 'es3' or 'es5'.": {
1014+
"category": "Error",
1015+
"code": 6046
1016+
},
1017+
"Locale must be of the form <language> or <language>-<territory>. For example '{0}' or '{1}'.": {
1018+
"category": "Error",
1019+
"code": 6047
1020+
},
1021+
"Unsupported locale '{0}'.": {
1022+
"category": "Error",
1023+
"code": 6048
1024+
},
1025+
"Unable to open file '{0}'.": {
1026+
"category": "Error",
1027+
"code": 6049
1028+
},
1029+
"Corrupted locale file {0}.": {
1030+
"category": "Error",
1031+
"code": 6050
1032+
},
1033+
"No input files specified.": {
1034+
"category": "Error",
1035+
"code": 6051
1036+
},
1037+
"Warn on expressions and declarations with an implied 'any' type.": {
1038+
"category": "Message",
1039+
"code": 7004
1040+
},
9971041
"Variable '{0}' implicitly has an '{1}' type.": {
9981042
"category": "Error",
9991043
"code": 7005
10001044
},
1001-
10021045
"Parameter '{0}' implicitly has an '{1}' type.": {
10031046
"category": "Error",
10041047
"code": 7006
@@ -1358,41 +1401,5 @@
13581401
"Filename '{0}' differs from already included filename '{1}' only in casing": {
13591402
"category": "Error",
13601403
"code": -9999999
1361-
},
1362-
"Argument for '--module' option must be 'commonjs' or 'amd'.": {
1363-
"category": "Error",
1364-
"code": -9999999
1365-
},
1366-
"Argument for '--target' option must be 'es3' or 'es5'.": {
1367-
"category": "Error",
1368-
"code": -9999999
1369-
},
1370-
"Compiler option '{0}' expects an argument.": {
1371-
"category": "Error",
1372-
"code": -9999999
1373-
},
1374-
"Unterminated quoted string in response file '{0}'.": {
1375-
"category": "Error",
1376-
"code": -9999999
1377-
},
1378-
"Locale must be of the form <language> or <language>-<territory>. For example '{0}' or '{1}'.": {
1379-
"category": "Error",
1380-
"code": -9999999
1381-
},
1382-
"Unsupported locale {0}.": {
1383-
"category": "Error",
1384-
"code": -9999999
1385-
},
1386-
"Unable to open file {0}.": {
1387-
"category": "Error",
1388-
"code": -9999999
1389-
},
1390-
"Corrupted locale file {0}.": {
1391-
"category": "Error",
1392-
"code": -9999999
1393-
},
1394-
"No input files specified.": {
1395-
"category": "Error",
1396-
"code": -9999999
13971404
}
13981405
}

0 commit comments

Comments
 (0)