diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index cf55f030c33..c0912394491 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -267,6 +267,16 @@ namespace ts { description: Diagnostics.Specifies_module_resolution_strategy_Colon_node_Node_js_or_classic_TypeScript_pre_1_6, error: Diagnostics.Argument_for_moduleResolution_option_must_be_node_or_classic, }, + { + name: "list", + elementType: { + "node": ModuleResolutionKind.NodeJs, + "classic": ModuleResolutionKind.Classic, + }, + type: "list", + description: Diagnostics.Specifies_module_resolution_strategy_Colon_node_Node_js_or_classic_TypeScript_pre_1_6, + error: Diagnostics.Argument_for_moduleResolution_option_must_be_node_or_classic, + }, { name: "allowUnusedLabels", type: "boolean", @@ -391,42 +401,7 @@ namespace ts { } if (hasProperty(optionNameMap, s)) { - const opt = optionNameMap[s]; - - if (opt.isTSConfigOnly) { - errors.push(createCompilerDiagnostic(Diagnostics.Option_0_can_only_be_specified_in_tsconfig_json_file, opt.name)); - } - else { - // Check to see if no argument was provided (e.g. "--locale" is the last command-line argument). - if (!args[i] && opt.type !== "boolean") { - errors.push(createCompilerDiagnostic(Diagnostics.Compiler_option_0_expects_an_argument, opt.name)); - } - - switch (opt.type) { - case "number": - options[opt.name] = parseInt(args[i]); - i++; - break; - case "boolean": - options[opt.name] = true; - break; - case "string": - options[opt.name] = args[i] || ""; - i++; - break; - // If not a primitive, the possible types are specified in what is effectively a map of options. - default: - let map = >opt.type; - let key = (args[i] || "").toLowerCase(); - i++; - if (hasProperty(map, key)) { - options[opt.name] = map[key]; - } - else { - errors.push(createCompilerDiagnostic((opt).error)); - } - } - } + parseString(optionNameMap[s], args[i]); } else { errors.push(createCompilerDiagnostic(Diagnostics.Unknown_compiler_option_0, s)); @@ -436,6 +411,41 @@ namespace ts { fileNames.push(s); } } + + function parseString(opt: CommandLineOption, value: string) { + // Check to see if no argument was provided (e.g. "--locale" is the last command-line argument). + if (!value && opt.type !== "boolean") { + errors.push(createCompilerDiagnostic(Diagnostics.Compiler_option_0_expects_an_argument, opt.name)); + } + + switch (opt.type) { + case "number": + options[opt.name] = parseInt(value); + i++; + break; + case "boolean": + options[opt.name] = true; + break; + case "string": + options[opt.name] = value || ""; + i++; + break; + case "list": + forEach((value || "").split(","), s => parseString(opt.name, opti ); + break; + // If not a primitive, the possible types are specified in what is effectively a map of options. + default: + let map = >opt.type; + let key = (value || "").toLowerCase(); + i++; + if (hasProperty(map, key)) { + options[opt.name] = map[key]; + } + else { + errors.push(createCompilerDiagnostic((opt).error)); + } + } + } } function parseResponseFile(fileName: string) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 155f5c1a77f..6273ea990df 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2529,7 +2529,7 @@ namespace ts { /* @internal */ export interface CommandLineOptionBase { name: string; - type: "string" | "number" | "boolean" | "object" | Map; // a value of a primitive type, or an object literal mapping named values to actual values + type: "string" | "number" | "boolean" | "object" | "list" | Map; // a value of a primitive type, or an object literal mapping named values to actual values isFilePath?: boolean; // True if option value is a path or fileName shortName?: string; // A short mnemonic for convenience - for instance, 'h' can be used in place of 'help' description?: DiagnosticMessage; // The message describing what the command line switch does @@ -2554,8 +2554,13 @@ namespace ts { type: "object"; } + export interface CommandlineOptionOfListType extends CommandLineOptionBase { + type: "list", + elementType: Map | "string" | "number"; + } + /* @internal */ - export type CommandLineOption = CommandLineOptionOfCustomType | CommandLineOptionOfPrimitiveType | TsConfigOnlyOption; + export type CommandLineOption = CommandLineOptionOfCustomType | CommandLineOptionOfPrimitiveType | TsConfigOnlyOption | CommandlineOptionOfListType; /* @internal */ export const enum CharacterCodes {