Skip to content

Commit 3ad6e31

Browse files
Merge pull request #351 from Microsoft/wontYouPleasePleaseHelpMe
Support the '--help' compiler flag.
2 parents 5c4009a + a24b175 commit 3ad6e31

File tree

8 files changed

+480
-129
lines changed

8 files changed

+480
-129
lines changed

Jakefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ var processDiagnosticMessagesTs = path.join(scriptsDirectory, "processDiagnostic
197197
var diagnosticMessagesJson = path.join(compilerDirectory, "diagnosticMessages.json");
198198
var diagnosticInfoMapTs = path.join(compilerDirectory, "diagnosticInformationMap.generated.ts");
199199

200+
file(processDiagnosticMessagesTs)
201+
200202
// processDiagnosticMessages script
201203
compileFile(processDiagnosticMessagesJs,
202204
[processDiagnosticMessagesTs],

scripts/processDiagnosticMessages.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function main(): void {
3939
function buildUniqueNameMap(names: string[]): IIndexable<string> {
4040
var nameMap: IIndexable<string> = {};
4141

42-
var uniqueNames = NameGenerator.ensureUniqueness(names, /*isFixed */ undefined, /* isCaseSensitive */ false);
42+
var uniqueNames = NameGenerator.ensureUniqueness(names, /* isCaseSensitive */ false, /* isFixed */ undefined);
4343

4444
for (var i = 0; i < names.length; i++) {
4545
nameMap[names[i]] = uniqueNames[i];
@@ -94,17 +94,17 @@ function convertPropertyName(origName: string): string {
9494
}
9595

9696
module NameGenerator {
97-
export function ensureUniqueness(
98-
names: string[],
99-
isFixed: boolean[]= names.map(() => false),
100-
isCaseSensitive: boolean = true): string[] {
97+
export function ensureUniqueness(names: string[], isCaseSensitive: boolean, isFixed?: boolean[]): string[]{
98+
if (!isFixed) {
99+
isFixed = names.map(() => false)
100+
}
101101

102-
var names = names.map(x => x);
103-
ensureUniquenessInPlace(names, isFixed, isCaseSensitive);
102+
var names = names.slice();
103+
ensureUniquenessInPlace(names, isCaseSensitive, isFixed);
104104
return names;
105105
}
106106

107-
function ensureUniquenessInPlace(names: string[], isFixed: boolean[], isCaseSensitive: boolean): void {
107+
function ensureUniquenessInPlace(names: string[], isCaseSensitive: boolean, isFixed: boolean[]): void {
108108
for (var i = 0; i < names.length; i++) {
109109
var name = names[i];
110110
var collisionIndices = Utilities.collectMatchingIndices(name, names, isCaseSensitive);
@@ -131,9 +131,12 @@ module NameGenerator {
131131
}
132132

133133
while (true) {
134-
var newName = name + suffix++;
134+
var newName = name + suffix;
135+
suffix++;
135136

136-
if (proposedNames.some((name) => Utilities.stringEquals(name, newName, isCaseSensitive))) {
137+
// Check if we've synthesized a unique name, and if so
138+
// replace the conflicting name with the new one.
139+
if (!proposedNames.some(name => Utilities.stringEquals(name, newName, isCaseSensitive))) {
137140
proposedNames[collisionIndex] = newName;
138141
break;
139142
}
@@ -144,7 +147,7 @@ module NameGenerator {
144147

145148
module Utilities {
146149
/// Return a list of all indices where a string occurs.
147-
export function collectMatchingIndices(name: string, proposedNames: string[], isCaseSensitive: boolean = true): number[] {
150+
export function collectMatchingIndices(name: string, proposedNames: string[], isCaseSensitive: boolean): number[] {
148151
var matchingIndices: number[] = [];
149152

150153
for (var i = 0; i < proposedNames.length; i++) {
@@ -156,8 +159,8 @@ module Utilities {
156159
return matchingIndices;
157160
}
158161

159-
export function stringEquals(s1: string, s2: string, caseSensitive: boolean = true): boolean {
160-
if (!caseSensitive) {
162+
export function stringEquals(s1: string, s2: string, caseSensitive: boolean): boolean {
163+
if (caseSensitive) {
161164
s1 = s1.toLowerCase();
162165
s2 = s2.toLowerCase();
163166
}

src/compiler/commandLineParser.ts

Lines changed: 121 additions & 37 deletions
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ module ts {
259259
};
260260
}
261261

262-
function compareValues(a: any, b: any): number {
262+
export function compareValues<T>(a: T, b: T): number {
263263
if (a === b) return 0;
264264
if (a === undefined) return -1;
265265
if (b === undefined) return 1;

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,50 @@ module ts {
238238
Could_not_write_file_0_Colon_1: { code: 5033, category: DiagnosticCategory.Error, key: "Could not write file '{0}': {1}" },
239239
Option_mapRoot_cannot_be_specified_without_specifying_sourcemap_option: { code: 5038, category: DiagnosticCategory.Error, key: "Option mapRoot cannot be specified without specifying sourcemap option." },
240240
Option_sourceRoot_cannot_be_specified_without_specifying_sourcemap_option: { code: 5039, category: DiagnosticCategory.Error, key: "Option sourceRoot cannot be specified without specifying sourcemap option." },
241+
Concatenate_and_emit_output_to_single_file: { code: 6001, category: DiagnosticCategory.Message, key: "Concatenate and emit output to single file." },
242+
Generates_corresponding_d_ts_file: { code: 6002, category: DiagnosticCategory.Message, key: "Generates corresponding '.d.ts' file." },
243+
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." },
244+
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." },
245+
Watch_input_files: { code: 6005, category: DiagnosticCategory.Message, key: "Watch input files." },
246+
Redirect_output_structure_to_the_directory: { code: 6006, category: DiagnosticCategory.Message, key: "Redirect output structure to the directory." },
247+
Do_not_emit_comments_to_output: { code: 6009, category: DiagnosticCategory.Message, key: "Do not emit comments to output." },
248+
Skip_resolution_and_preprocessing: { code: 6010, category: DiagnosticCategory.Message, key: "Skip resolution and preprocessing." },
249+
Specify_ECMAScript_target_version_Colon_ES3_default_or_ES5: { code: 6015, category: DiagnosticCategory.Message, key: "Specify ECMAScript target version: 'ES3' (default), or 'ES5'" },
250+
Specify_module_code_generation_Colon_commonjs_or_amd: { code: 6016, category: DiagnosticCategory.Message, key: "Specify module code generation: 'commonjs' or 'amd'" },
251+
Print_this_message: { code: 6017, category: DiagnosticCategory.Message, key: "Print this message." },
252+
Print_the_compiler_s_version: { code: 6019, category: DiagnosticCategory.Message, key: "Print the compiler's version." },
253+
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." },
254+
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}'" },
255+
Syntax_Colon_0: { code: 6023, category: DiagnosticCategory.Message, key: "Syntax: {0}" },
256+
options: { code: 6024, category: DiagnosticCategory.Message, key: "options" },
257+
file: { code: 6025, category: DiagnosticCategory.Message, key: "file" },
258+
Examples_Colon_0: { code: 6026, category: DiagnosticCategory.Message, key: "Examples: {0}" },
259+
Options_Colon: { code: 6027, category: DiagnosticCategory.Message, key: "Options:" },
241260
Version_0: { code: 6029, category: DiagnosticCategory.Message, key: "Version {0}" },
261+
Insert_command_line_options_and_files_from_a_file: { code: 6030, category: DiagnosticCategory.Message, key: "Insert command line options and files from a file." },
262+
Use_the_0_flag_to_see_options: { code: 6031, category: DiagnosticCategory.Message, key: "Use the '{0}' flag to see options." },
242263
File_change_detected_Compiling: { code: 6032, category: DiagnosticCategory.Message, key: "File change detected. Compiling..." },
264+
STRING: { code: 6033, category: DiagnosticCategory.Message, key: "STRING" },
265+
KIND: { code: 6034, category: DiagnosticCategory.Message, key: "KIND" },
266+
FILE: { code: 6035, category: DiagnosticCategory.Message, key: "FILE" },
267+
VERSION: { code: 6036, category: DiagnosticCategory.Message, key: "VERSION" },
268+
LOCATION: { code: 6037, category: DiagnosticCategory.Message, key: "LOCATION" },
269+
DIRECTORY: { code: 6038, category: DiagnosticCategory.Message, key: "DIRECTORY" },
270+
NUMBER: { code: 6039, category: DiagnosticCategory.Message, key: "NUMBER" },
271+
Specify_the_codepage_to_use_when_opening_source_files: { code: 6040, category: DiagnosticCategory.Message, key: "Specify the codepage to use when opening source files." },
272+
Additional_locations_Colon: { code: 6041, category: DiagnosticCategory.Message, key: "Additional locations:" },
243273
Compilation_complete_Watching_for_file_changes: { code: 6042, category: DiagnosticCategory.Message, key: "Compilation complete. Watching for file changes." },
274+
Generates_corresponding_map_file: { code: 6043, category: DiagnosticCategory.Message, key: "Generates corresponding '.map' file." },
275+
Compiler_option_0_expects_an_argument: { code: 6044, category: DiagnosticCategory.Error, key: "Compiler option '{0}' expects an argument." },
276+
Unterminated_quoted_string_in_response_file_0: { code: 6045, category: DiagnosticCategory.Error, key: "Unterminated quoted string in response file '{0}'." },
277+
Argument_for_module_option_must_be_commonjs_or_amd: { code: 6045, category: DiagnosticCategory.Error, key: "Argument for '--module' option must be 'commonjs' or 'amd'." },
278+
Argument_for_target_option_must_be_es3_or_es5: { code: 6046, category: DiagnosticCategory.Error, key: "Argument for '--target' option must be 'es3' or 'es5'." },
279+
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}'." },
280+
Unsupported_locale_0: { code: 6048, category: DiagnosticCategory.Error, key: "Unsupported locale '{0}'." },
281+
Unable_to_open_file_0: { code: 6049, category: DiagnosticCategory.Error, key: "Unable to open file '{0}'." },
282+
Corrupted_locale_file_0: { code: 6050, category: DiagnosticCategory.Error, key: "Corrupted locale file {0}." },
283+
No_input_files_specified: { code: 6051, category: DiagnosticCategory.Error, key: "No input files specified." },
284+
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." },
244285
Variable_0_implicitly_has_an_1_type: { code: 7005, category: DiagnosticCategory.Error, key: "Variable '{0}' implicitly has an '{1}' type." },
245286
Parameter_0_implicitly_has_an_1_type: { code: 7006, category: DiagnosticCategory.Error, key: "Parameter '{0}' implicitly has an '{1}' type." },
246287
Member_0_implicitly_has_an_1_type: { code: 7008, category: DiagnosticCategory.Error, key: "Member '{0}' implicitly has an '{1}' type." },
@@ -326,14 +367,5 @@ module ts {
326367
Import_declaration_conflicts_with_local_declaration_of_0: { code: -9999999, category: DiagnosticCategory.Error, key: "Import declaration conflicts with local declaration of '{0}'" },
327368
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" },
328369
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" },
329-
Argument_for_module_option_must_be_commonjs_or_amd: { code: -9999999, category: DiagnosticCategory.Error, key: "Argument for '--module' option must be 'commonjs' or 'amd'." },
330-
Argument_for_target_option_must_be_es3_or_es5: { code: -9999999, category: DiagnosticCategory.Error, key: "Argument for '--target' option must be 'es3' or 'es5'." },
331-
Compiler_option_0_expects_an_argument: { code: -9999999, category: DiagnosticCategory.Error, key: "Compiler option '{0}' expects an argument." },
332-
Unterminated_quoted_string_in_response_file_0: { code: -9999999, category: DiagnosticCategory.Error, key: "Unterminated quoted string in response file '{0}'." },
333-
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}'." },
334-
Unsupported_locale_0: { code: -9999999, category: DiagnosticCategory.Error, key: "Unsupported locale {0}." },
335-
Unable_to_open_file_0: { code: -9999999, category: DiagnosticCategory.Error, key: "Unable to open file {0}." },
336-
Corrupted_locale_file_0: { code: -9999999, category: DiagnosticCategory.Error, key: "Corrupted locale file {0}." },
337-
No_input_files_specified: { code: -9999999, category: DiagnosticCategory.Error, key: "No input files specified." },
338370
};
339371
}

0 commit comments

Comments
 (0)