Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support the '--help' compiler flag. #351

Merged
merged 9 commits into from
Aug 6, 2014
2 changes: 2 additions & 0 deletions Jakefile
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,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],
Expand Down
29 changes: 16 additions & 13 deletions scripts/processDiagnosticMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function main(): void {
function buildUniqueNameMap(names: string[]): IIndexable<string> {
var nameMap: IIndexable<string> = {};

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];
Expand Down Expand Up @@ -94,17 +94,17 @@ 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[], 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);
Expand All @@ -131,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;
}
Expand All @@ -144,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 = true): number[] {
export function collectMatchingIndices(name: string, proposedNames: string[], isCaseSensitive: boolean): number[] {
var matchingIndices: number[] = [];

for (var i = 0; i < proposedNames.length; i++) {
Expand All @@ -156,8 +159,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): boolean {
if (caseSensitive) {
s1 = s1.toLowerCase();
s2 = s2.toLowerCase();
}
Expand Down
158 changes: 121 additions & 37 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,128 @@
/// <reference path="scanner.ts"/>

module ts {
var shortOptionNames: Map<string> = {
"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<CommandLineOption> = {};
var shortOptionNames: Map<string> = {};
var optionNameMap: Map<CommandLineOption> = {};

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 {
Expand Down Expand Up @@ -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") {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ module ts {
};
}

function compareValues(a: any, b: any): number {
export function compareValues<T>(a: T, b: T): number {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure how the generic is any better.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for compareValues('1',1) => error

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compareValues('1', 1) computes a BCT of {} and succeeds without complaint, see #360

if (a === b) return 0;
if (a === undefined) return -1;
if (b === undefined) return 1;
Expand Down
50 changes: 41 additions & 9 deletions src/compiler/diagnosticInformationMap.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,50 @@ 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_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_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: { 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}" },
options: { code: 6024, category: DiagnosticCategory.Message, key: "options" },
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:" },
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_change_detected_Compiling: { code: 6032, category: DiagnosticCategory.Message, key: "File change detected. 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:" },
Compilation_complete_Watching_for_file_changes: { code: 6042, category: DiagnosticCategory.Message, key: "Compilation complete. Watching for file changes." },
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 <language> or <language>-<territory>. 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." },
Expand Down Expand Up @@ -304,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 <language> or <language>-<territory>. 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." },
};
}
Loading