Skip to content

Commit a4331fd

Browse files
Merge pull request #4735 from Microsoft/commandLineCrashModuleResolution
Fix command line crash with invalid '--moduleResolution' option
2 parents 2c54889 + 535efd1 commit a4331fd

File tree

4 files changed

+28
-8
lines changed

4 files changed

+28
-8
lines changed

src/compiler/commandLineParser.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,9 @@ namespace ts {
243243
"node": ModuleResolutionKind.NodeJs,
244244
"classic": ModuleResolutionKind.Classic
245245
},
246-
description: Diagnostics.Specifies_module_resolution_strategy_Colon_node_Node_or_classic_TypeScript_pre_1_6
247-
}
246+
description: Diagnostics.Specifies_module_resolution_strategy_Colon_node_Node_js_or_classic_TypeScript_pre_1_6,
247+
error: Diagnostics.Argument_for_moduleResolution_option_must_be_node_or_classic,
248+
}
248249
];
249250

250251
/* @internal */
@@ -327,7 +328,7 @@ namespace ts {
327328
options[opt.name] = map[key];
328329
}
329330
else {
330-
errors.push(createCompilerDiagnostic(opt.error));
331+
errors.push(createCompilerDiagnostic((<CommandLineOptionOfCustomType>opt).error));
331332
}
332333
}
333334
}
@@ -440,7 +441,7 @@ namespace ts {
440441
value = optType[key];
441442
}
442443
else {
443-
errors.push(createCompilerDiagnostic(opt.error));
444+
errors.push(createCompilerDiagnostic((<CommandLineOptionOfCustomType>opt).error));
444445
value = 0;
445446
}
446447
}

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,13 +560,14 @@ namespace ts {
560560
Specifies_the_end_of_line_sequence_to_be_used_when_emitting_files_Colon_CRLF_dos_or_LF_unix: { code: 6060, category: DiagnosticCategory.Message, key: "Specifies the end of line sequence to be used when emitting files: 'CRLF' (dos) or 'LF' (unix)." },
561561
NEWLINE: { code: 6061, category: DiagnosticCategory.Message, key: "NEWLINE" },
562562
Argument_for_newLine_option_must_be_CRLF_or_LF: { code: 6062, category: DiagnosticCategory.Error, key: "Argument for '--newLine' option must be 'CRLF' or 'LF'." },
563+
Argument_for_moduleResolution_option_must_be_node_or_classic: { code: 6063, category: DiagnosticCategory.Error, key: "Argument for '--moduleResolution' option must be 'node' or 'classic'." },
563564
Specify_JSX_code_generation_Colon_preserve_or_react: { code: 6080, category: DiagnosticCategory.Message, key: "Specify JSX code generation: 'preserve' or 'react'" },
564565
Argument_for_jsx_must_be_preserve_or_react: { code: 6081, category: DiagnosticCategory.Message, key: "Argument for '--jsx' must be 'preserve' or 'react'." },
565566
Enables_experimental_support_for_ES7_decorators: { code: 6065, category: DiagnosticCategory.Message, key: "Enables experimental support for ES7 decorators." },
566567
Enables_experimental_support_for_emitting_type_metadata_for_decorators: { code: 6066, category: DiagnosticCategory.Message, key: "Enables experimental support for emitting type metadata for decorators." },
567568
Option_experimentalAsyncFunctions_cannot_be_specified_when_targeting_ES5_or_lower: { code: 6067, category: DiagnosticCategory.Message, key: "Option 'experimentalAsyncFunctions' cannot be specified when targeting ES5 or lower." },
568569
Enables_experimental_support_for_ES7_async_functions: { code: 6068, category: DiagnosticCategory.Message, key: "Enables experimental support for ES7 async functions." },
569-
Specifies_module_resolution_strategy_Colon_node_Node_or_classic_TypeScript_pre_1_6: { code: 6069, category: DiagnosticCategory.Message, key: "Specifies module resolution strategy: 'node' (Node) or 'classic' (TypeScript pre 1.6) ." },
570+
Specifies_module_resolution_strategy_Colon_node_Node_js_or_classic_TypeScript_pre_1_6: { code: 6069, category: DiagnosticCategory.Message, key: "Specifies module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6)." },
570571
Initializes_a_TypeScript_project_and_creates_a_tsconfig_json_file: { code: 6070, category: DiagnosticCategory.Message, key: "Initializes a TypeScript project and creates a tsconfig.json file." },
571572
Successfully_created_a_tsconfig_json_file: { code: 6071, category: DiagnosticCategory.Message, key: "Successfully created a tsconfig.json file." },
572573
Suppress_excess_property_checks_for_object_literals: { code: 6072, category: DiagnosticCategory.Message, key: "Suppress excess property checks for object literals." },

src/compiler/diagnosticMessages.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2230,6 +2230,11 @@
22302230
"category": "Error",
22312231
"code": 6062
22322232
},
2233+
"Argument for '--moduleResolution' option must be 'node' or 'classic'.": {
2234+
"category": "Error",
2235+
"code": 6063
2236+
},
2237+
22332238
"Specify JSX code generation: 'preserve' or 'react'": {
22342239
"category": "Message",
22352240
"code": 6080
@@ -2254,7 +2259,7 @@
22542259
"category": "Message",
22552260
"code": 6068
22562261
},
2257-
"Specifies module resolution strategy: 'node' (Node) or 'classic' (TypeScript pre 1.6) .": {
2262+
"Specifies module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6).": {
22582263
"category": "Message",
22592264
"code": 6069
22602265
},

src/compiler/types.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2112,17 +2112,30 @@ namespace ts {
21122112
}
21132113

21142114
/* @internal */
2115-
export interface CommandLineOption {
2115+
interface CommandLineOptionBase {
21162116
name: string;
21172117
type: string | Map<number>; // "string", "number", "boolean", or an object literal mapping named values to actual values
21182118
isFilePath?: boolean; // True if option value is a path or fileName
21192119
shortName?: string; // A short mnemonic for convenience - for instance, 'h' can be used in place of 'help'
21202120
description?: DiagnosticMessage; // The message describing what the command line switch does
21212121
paramType?: DiagnosticMessage; // The name to be used for a non-boolean option's parameter
2122-
error?: DiagnosticMessage; // The error given when the argument does not fit a customized 'type'
21232122
experimental?: boolean;
21242123
}
21252124

2125+
/* @internal */
2126+
export interface CommandLineOptionOfPrimitiveType extends CommandLineOptionBase {
2127+
type: string; // "string" | "number" | "boolean"
2128+
}
2129+
2130+
/* @internal */
2131+
export interface CommandLineOptionOfCustomType extends CommandLineOptionBase {
2132+
type: Map<number>; // an object literal mapping named values to actual values
2133+
error: DiagnosticMessage; // The error given when the argument does not fit a customized 'type'
2134+
}
2135+
2136+
/* @internal */
2137+
export type CommandLineOption = CommandLineOptionOfCustomType | CommandLineOptionOfPrimitiveType;
2138+
21262139
/* @internal */
21272140
export const enum CharacterCodes {
21282141
nullCharacter = 0,

0 commit comments

Comments
 (0)