Skip to content

Commit be0592d

Browse files
author
Kanchalai Tanglertsampan
committed
Add correct options for --lib
1 parent eb82824 commit be0592d

File tree

3 files changed

+58
-8
lines changed

3 files changed

+58
-8
lines changed

src/compiler/commandLineParser.ts

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,33 @@ namespace ts {
273273
element: {
274274
name: "lib",
275275
type: {
276-
"node": ModuleResolutionKind.NodeJs,
277-
"classic": ModuleResolutionKind.Classic,
276+
// JavaScript only
277+
"es5": "lib.es5.d.ts",
278+
"es6": "lib.es6.d.ts",
279+
"es7": "lib.es7.d.ts",
280+
// Host only
281+
"dom": "lib.dom.d.ts",
282+
"webworker": "lib.webworker.d.ts",
283+
"scripthost": "lib.scripthost.d.ts",
284+
// ES6 Or ESNext By-feature options
285+
"es6.array": "lib.es6.array.d.ts",
286+
"es6.collection": "lib.es6.collection.d.ts",
287+
"es6.function": "lib.es6.function.d.ts",
288+
"es6.iterable": "lib.es6.iterable.d.ts",
289+
"es6.math": "lib.es6.math.d.ts",
290+
"es6.number": "lib.es6.number.d.ts",
291+
"es6.object": "lib.es6.object.d.ts",
292+
"es6.promise": "lib.es6.promise.d.ts",
293+
"es6.proxy": "lib.es6.proxy.d.ts",
294+
"es6.reflect": "lib.es6.reflect.d.ts",
295+
"es6.regexp": "lib.es6.regexp.d.ts",
296+
"es6.symbol": "lib.es6.symbol.d.ts",
297+
"es6.symbol.wellknown": "lib.es6.symbol.wellknown.d.ts",
298+
"es7.array.include": "lib.es7.array.include.d.ts"
278299
},
279-
error: Diagnostics.Argument_for_moduleResolution_option_must_be_node_or_classic,
300+
error: Diagnostics.Arguments_for_library_option_must_be_Colon_0,
280301
},
281-
description: Diagnostics.Specifies_module_resolution_strategy_Colon_node_Node_js_or_classic_TypeScript_pre_1_6,
302+
description: Diagnostics.Specify_library_to_be_included_in_the_compilation_Colon,
282303
},
283304
{
284305
name: "allowUnusedLabels",
@@ -402,6 +423,27 @@ namespace ts {
402423
return optionNameMapCache;
403424
}
404425

426+
// Cache between the name of commandline which is a custom type and a list of all possible custom types
427+
const namesOfCustomTypeMapCache: Map<string[]> = {};
428+
429+
/* @internal */
430+
export function getNamesOfCustomTypeFromCommandLineOptionsOfCustomType(opt: CommandLineOptionOfCustomType): string[] {
431+
if (hasProperty(namesOfCustomTypeMapCache, opt.name)) {
432+
return namesOfCustomTypeMapCache[opt.name];
433+
}
434+
435+
const type = opt.type;
436+
const namesOfType: string[] = [];
437+
for (const typeName in type) {
438+
if (hasProperty(type, typeName)) {
439+
namesOfType.push(typeName);
440+
}
441+
}
442+
443+
namesOfCustomTypeMapCache[opt.name] = namesOfType;
444+
return namesOfCustomTypeMapCache[opt.name];
445+
}
446+
405447
export function parseCommandLine(commandLine: string[], readFile?: (path: string) => string): ParsedCommandLine {
406448
const options: CompilerOptions = {};
407449
const fileNames: string[] = [];
@@ -482,7 +524,8 @@ namespace ts {
482524
return map[key];
483525
}
484526
else {
485-
errors.push(createCompilerDiagnostic(opt.error));
527+
const suggestedOption = getNamesOfCustomTypeFromCommandLineOptionsOfCustomType(opt);
528+
errors.push(createCompilerDiagnostic(opt.error, suggestedOption ? suggestedOption : undefined));
486529
}
487530
}
488531

src/compiler/diagnosticMessages.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2620,7 +2620,14 @@
26202620
"category": "Message",
26212621
"code": 6112
26222622
},
2623-
2623+
"Specify library to be included in the compilation:": {
2624+
"category": "Message",
2625+
"code": 6113
2626+
},
2627+
"Arguments for library option must be: {0}": {
2628+
"category": "Error",
2629+
"code": 6114
2630+
},
26242631
"Variable '{0}' implicitly has an '{1}' type.": {
26252632
"category": "Error",
26262633
"code": 7005

src/compiler/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2531,7 +2531,7 @@ namespace ts {
25312531
/* @internal */
25322532
export interface CommandLineOptionBase {
25332533
name: string;
2534-
type: "string" | "number" | "boolean" | "object" | "list" | Map<number>; // a value of a primitive type, or an object literal mapping named values to actual values
2534+
type: "string" | "number" | "boolean" | "object" | "list" | Map<number | string>; // a value of a primitive type, or an object literal mapping named values to actual values
25352535
isFilePath?: boolean; // True if option value is a path or fileName
25362536
shortName?: string; // A short mnemonic for convenience - for instance, 'h' can be used in place of 'help'
25372537
description?: DiagnosticMessage; // The message describing what the command line switch does
@@ -2547,7 +2547,7 @@ namespace ts {
25472547

25482548
/* @internal */
25492549
export interface CommandLineOptionOfCustomType extends CommandLineOptionBase {
2550-
type: Map<number>; // an object literal mapping named values to actual values
2550+
type: Map<number | string>; // an object literal mapping named values to actual values
25512551
error: DiagnosticMessage; // The error given when the argument does not fit a customized 'type'
25522552
}
25532553

0 commit comments

Comments
 (0)