Skip to content

Commit 670ad45

Browse files
Describe defaults of more options (#46498)
* Describe defaults of more options * Use enum members/values vs. strings * Update Baselines and/or Applied Lint Fixes Co-authored-by: TypeScript Bot <[email protected]>
1 parent b8ec791 commit 670ad45

8 files changed

+156
-113
lines changed

src/compiler/commandLineParser.ts

Lines changed: 94 additions & 84 deletions
Large diffs are not rendered by default.

src/compiler/types.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6335,7 +6335,7 @@ namespace ts {
63356335
isFilePath?: boolean; // True if option value is a path or fileName
63366336
shortName?: string; // A short mnemonic for convenience - for instance, 'h' can be used in place of 'help'
63376337
description?: DiagnosticMessage; // The message describing what the command line switch does.
6338-
defaultValueDescription?: string | DiagnosticMessage; // The message describing what the dafault value is. string type is prepared for fixed chosen like "false" which do not need I18n.
6338+
defaultValueDescription?: string | number | boolean | DiagnosticMessage; // The message describing what the dafault value is. string type is prepared for fixed chosen like "false" which do not need I18n.
63396339
paramType?: DiagnosticMessage; // The name to be used for a non-boolean option's parameter
63406340
isTSConfigOnly?: boolean; // True if option can only be specified via tsconfig.json file
63416341
isCommandLineOnly?: boolean;
@@ -6355,23 +6355,25 @@ namespace ts {
63556355
/* @internal */
63566356
export interface CommandLineOptionOfStringType extends CommandLineOptionBase {
63576357
type: "string";
6358+
defaultValueDescription?: string | undefined | DiagnosticMessage;
63586359
}
63596360

63606361
/* @internal */
63616362
export interface CommandLineOptionOfNumberType extends CommandLineOptionBase {
63626363
type: "number";
6363-
defaultValueDescription: `${number | undefined}` | DiagnosticMessage;
6364+
defaultValueDescription: number | undefined | DiagnosticMessage;
63646365
}
63656366

63666367
/* @internal */
63676368
export interface CommandLineOptionOfBooleanType extends CommandLineOptionBase {
63686369
type: "boolean";
6369-
defaultValueDescription: `${boolean | undefined}` | DiagnosticMessage;
6370+
defaultValueDescription: boolean | undefined | DiagnosticMessage;
63706371
}
63716372

63726373
/* @internal */
63736374
export interface CommandLineOptionOfCustomType extends CommandLineOptionBase {
63746375
type: ESMap<string, number | string>; // an object literal mapping named values to actual values
6376+
defaultValueDescription: number | string | undefined | DiagnosticMessage;
63756377
}
63766378

63776379
/* @internal */

src/executeCommandLine/executeCommandLine.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,13 @@ namespace ts {
160160

161161
// value type and possible value
162162
const valueCandidates = getValueCandidate(option);
163-
const defaultValueDescription = typeof option.defaultValueDescription === "object" ? getDiagnosticText(option.defaultValueDescription) : option.defaultValueDescription;
163+
const defaultValueDescription =
164+
typeof option.defaultValueDescription === "object"
165+
? getDiagnosticText(option.defaultValueDescription)
166+
: formatDefaultValue(
167+
option.defaultValueDescription,
168+
option.type === "list" ? option.element.type : option.type
169+
);
164170
const terminalWidth = sys.getWidthOfTerminal?.() ?? 0;
165171

166172
// Note: child_process might return `terminalWidth` as undefined.
@@ -203,6 +209,19 @@ namespace ts {
203209
}
204210
return text;
205211

212+
function formatDefaultValue(
213+
defaultValue: CommandLineOption["defaultValueDescription"],
214+
type: CommandLineOption["type"]
215+
) {
216+
return defaultValue !== undefined && typeof type === "object"
217+
// e.g. ScriptTarget.ES2015 -> "es6/es2015"
218+
? arrayFrom(type.entries())
219+
.filter(([, value]) => value === defaultValue)
220+
.map(([name]) => name)
221+
.join("/")
222+
: String(defaultValue);
223+
}
224+
206225
function showAdditionalInfoOutput(valueCandidates: ValueCandidate | undefined, option: CommandLineOption): boolean {
207226
const ignoreValues = ["string"];
208227
const ignoredDescriptions = [undefined, "false", "n/a"];
@@ -286,8 +305,14 @@ namespace ts {
286305
break;
287306
default:
288307
// ESMap<string, number | string>
289-
const keys = arrayFrom(option.type.keys());
290-
possibleValues = keys.join(", ");
308+
// Group synonyms: es6/es2015
309+
const inverted: { [value: string]: string[] } = {};
310+
option.type.forEach((value, name) => {
311+
(inverted[value] ||= []).push(name);
312+
});
313+
return getEntries(inverted)
314+
.map(([, synonyms]) => synonyms.join("/"))
315+
.join(", ");
291316
}
292317
return possibleValues;
293318
}

src/harness/harnessIO.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -304,21 +304,21 @@ namespace Harness {
304304

305305
// Additional options not already in ts.optionDeclarations
306306
const harnessOptionDeclarations: ts.CommandLineOption[] = [
307-
{ name: "allowNonTsExtensions", type: "boolean", defaultValueDescription: "false" },
308-
{ name: "useCaseSensitiveFileNames", type: "boolean", defaultValueDescription: "false" },
307+
{ name: "allowNonTsExtensions", type: "boolean", defaultValueDescription: false },
308+
{ name: "useCaseSensitiveFileNames", type: "boolean", defaultValueDescription: false },
309309
{ name: "baselineFile", type: "string" },
310310
{ name: "includeBuiltFile", type: "string" },
311311
{ name: "fileName", type: "string" },
312312
{ name: "libFiles", type: "string" },
313-
{ name: "noErrorTruncation", type: "boolean", defaultValueDescription: "false" },
314-
{ name: "suppressOutputPathCheck", type: "boolean", defaultValueDescription: "false" },
315-
{ name: "noImplicitReferences", type: "boolean", defaultValueDescription: "false" },
313+
{ name: "noErrorTruncation", type: "boolean", defaultValueDescription: false },
314+
{ name: "suppressOutputPathCheck", type: "boolean", defaultValueDescription: false },
315+
{ name: "noImplicitReferences", type: "boolean", defaultValueDescription: false },
316316
{ name: "currentDirectory", type: "string" },
317317
{ name: "symlink", type: "string" },
318318
{ name: "link", type: "string" },
319-
{ name: "noTypesAndSymbols", type: "boolean", defaultValueDescription: "false" },
319+
{ name: "noTypesAndSymbols", type: "boolean", defaultValueDescription: false },
320320
// Emitted js baseline will print full paths for every output file
321-
{ name: "fullEmitPaths", type: "boolean", defaultValueDescription: "false" }
321+
{ name: "fullEmitPaths", type: "boolean", defaultValueDescription: false },
322322
];
323323

324324
let optionsIndex: ts.ESMap<string, ts.CommandLineOption>;

src/testRunner/unittests/config/commandLineParsing.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ namespace ts {
534534
isTSConfigOnly: true,
535535
category: Diagnostics.Backwards_Compatibility,
536536
description: Diagnostics.Enable_project_compilation,
537-
defaultValueDescription: "undefined",
537+
defaultValueDescription: undefined,
538538
}
539539
];
540540
return {

tests/baselines/reference/tsc/runWithoutArgs/initial-build/does-not-add-color-when-NO_COLOR-is-set.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,18 @@ default: true
6868

6969
--target, -t
7070
Set the JavaScript language version for emitted JavaScript and include compatible library declarations.
71-
one of: es3, es5, es6, es2015, es2016, es2017, es2018, es2019, es2020, es2021, es2022, esnext
72-
default: ES3
71+
one of: es3, es5, es6/es2015, es2016, es2017, es2018, es2019, es2020, es2021, es2022, esnext
72+
default: es3
7373

7474
--module, -m
7575
Specify what module code is generated.
76-
one of: none, commonjs, amd, system, umd, es6, es2015, es2020, es2022, esnext, node12, nodenext
76+
one of: none, commonjs, amd, umd, system, es6/es2015, es2020, es2022, esnext, node12, nodenext
77+
default: undefined
7778

7879
--lib
7980
Specify a set of bundled library declaration files that describe the target runtime environment.
80-
one or more: es5, es6, es2015, es7, es2016, es2017, es2018, es2019, es2020, es2021, es2022, esnext, dom, dom.iterable, webworker, webworker.importscripts, webworker.iterable, scripthost, es2015.core, es2015.collection, es2015.generator, es2015.iterable, es2015.promise, es2015.proxy, es2015.reflect, es2015.symbol, es2015.symbol.wellknown, es2016.array.include, es2017.object, es2017.sharedmemory, es2017.string, es2017.intl, es2017.typedarrays, es2018.asyncgenerator, es2018.asynciterable, es2018.intl, es2018.promise, es2018.regexp, es2019.array, es2019.object, es2019.string, es2019.symbol, es2020.bigint, es2020.promise, es2020.sharedmemory, es2020.string, es2020.symbol.wellknown, es2020.intl, es2021.promise, es2021.string, es2021.weakref, es2021.intl, es2022.array, es2022.error, es2022.object, es2022.string, esnext.array, esnext.symbol, esnext.asynciterable, esnext.intl, esnext.bigint, esnext.string, esnext.promise, esnext.weakref
81+
one or more: es5, es6/es2015, es7/es2016, es2017, es2018, es2019, es2020, es2021, es2022, esnext, dom, dom.iterable, webworker, webworker.importscripts, webworker.iterable, scripthost, es2015.core, es2015.collection, es2015.generator, es2015.iterable, es2015.promise, es2015.proxy, es2015.reflect, es2015.symbol, es2015.symbol.wellknown, es2016.array.include, es2017.object, es2017.sharedmemory, es2017.string, es2017.intl, es2017.typedarrays, es2018.asyncgenerator, es2018.asynciterable/esnext.asynciterable, es2018.intl, es2018.promise, es2018.regexp, es2019.array, es2019.object, es2019.string, es2019.symbol/esnext.symbol, es2020.bigint/esnext.bigint, es2020.promise, es2020.sharedmemory, es2020.string, es2020.symbol.wellknown, es2020.intl, es2021.promise/esnext.promise, es2021.string, es2021.weakref/esnext.weakref, es2021.intl, es2022.array/esnext.array, es2022.error, es2022.object, es2022.string/esnext.string, esnext.intl
82+
default: undefined
8183

8284
--allowJs
8385
Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files.
@@ -91,7 +93,7 @@ default: false
9193

9294
--jsx
9395
Specify what JSX code is generated.
94-
one of: preserve, react-native, react, react-jsx, react-jsxdev
96+
one of: preserve, react, react-native, react-jsx, react-jsxdev
9597
default: undefined
9698

9799
--declaration, -d

tests/baselines/reference/tsc/runWithoutArgs/initial-build/show-help-with-ExitStatus.DiagnosticsPresent_OutputsSkipped-when-host-can't-provide-terminal-width.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,18 @@ default: true
6868

6969
--target, -t
7070
Set the JavaScript language version for emitted JavaScript and include compatible library declarations.
71-
one of: es3, es5, es6, es2015, es2016, es2017, es2018, es2019, es2020, es2021, es2022, esnext
72-
default: ES3
71+
one of: es3, es5, es6/es2015, es2016, es2017, es2018, es2019, es2020, es2021, es2022, esnext
72+
default: es3
7373

7474
--module, -m
7575
Specify what module code is generated.
76-
one of: none, commonjs, amd, system, umd, es6, es2015, es2020, es2022, esnext, node12, nodenext
76+
one of: none, commonjs, amd, umd, system, es6/es2015, es2020, es2022, esnext, node12, nodenext
77+
default: undefined
7778

7879
--lib
7980
Specify a set of bundled library declaration files that describe the target runtime environment.
80-
one or more: es5, es6, es2015, es7, es2016, es2017, es2018, es2019, es2020, es2021, es2022, esnext, dom, dom.iterable, webworker, webworker.importscripts, webworker.iterable, scripthost, es2015.core, es2015.collection, es2015.generator, es2015.iterable, es2015.promise, es2015.proxy, es2015.reflect, es2015.symbol, es2015.symbol.wellknown, es2016.array.include, es2017.object, es2017.sharedmemory, es2017.string, es2017.intl, es2017.typedarrays, es2018.asyncgenerator, es2018.asynciterable, es2018.intl, es2018.promise, es2018.regexp, es2019.array, es2019.object, es2019.string, es2019.symbol, es2020.bigint, es2020.promise, es2020.sharedmemory, es2020.string, es2020.symbol.wellknown, es2020.intl, es2021.promise, es2021.string, es2021.weakref, es2021.intl, es2022.array, es2022.error, es2022.object, es2022.string, esnext.array, esnext.symbol, esnext.asynciterable, esnext.intl, esnext.bigint, esnext.string, esnext.promise, esnext.weakref
81+
one or more: es5, es6/es2015, es7/es2016, es2017, es2018, es2019, es2020, es2021, es2022, esnext, dom, dom.iterable, webworker, webworker.importscripts, webworker.iterable, scripthost, es2015.core, es2015.collection, es2015.generator, es2015.iterable, es2015.promise, es2015.proxy, es2015.reflect, es2015.symbol, es2015.symbol.wellknown, es2016.array.include, es2017.object, es2017.sharedmemory, es2017.string, es2017.intl, es2017.typedarrays, es2018.asyncgenerator, es2018.asynciterable/esnext.asynciterable, es2018.intl, es2018.promise, es2018.regexp, es2019.array, es2019.object, es2019.string, es2019.symbol/esnext.symbol, es2020.bigint/esnext.bigint, es2020.promise, es2020.sharedmemory, es2020.string, es2020.symbol.wellknown, es2020.intl, es2021.promise/esnext.promise, es2021.string, es2021.weakref/esnext.weakref, es2021.intl, es2022.array/esnext.array, es2022.error, es2022.object, es2022.string/esnext.string, esnext.intl
82+
default: undefined
8183

8284
--allowJs
8385
Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files.
@@ -91,7 +93,7 @@ default: false
9193

9294
--jsx
9395
Specify what JSX code is generated.
94-
one of: preserve, react-native, react, react-jsx, react-jsxdev
96+
one of: preserve, react, react-native, react-jsx, react-jsxdev
9597
default: undefined
9698

9799
--declaration, -d

tests/baselines/reference/tsc/runWithoutArgs/initial-build/show-help-with-ExitStatus.DiagnosticsPresent_OutputsSkipped.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,18 @@ default: true
6868

6969
--target, -t
7070
Set the JavaScript language version for emitted JavaScript and include compatible library declarations.
71-
one of: es3, es5, es6, es2015, es2016, es2017, es2018, es2019, es2020, es2021, es2022, esnext
72-
default: ES3
71+
one of: es3, es5, es6/es2015, es2016, es2017, es2018, es2019, es2020, es2021, es2022, esnext
72+
default: es3
7373

7474
--module, -m
7575
Specify what module code is generated.
76-
one of: none, commonjs, amd, system, umd, es6, es2015, es2020, es2022, esnext, node12, nodenext
76+
one of: none, commonjs, amd, umd, system, es6/es2015, es2020, es2022, esnext, node12, nodenext
77+
default: undefined
7778

7879
--lib
7980
Specify a set of bundled library declaration files that describe the target runtime environment.
80-
one or more: es5, es6, es2015, es7, es2016, es2017, es2018, es2019, es2020, es2021, es2022, esnext, dom, dom.iterable, webworker, webworker.importscripts, webworker.iterable, scripthost, es2015.core, es2015.collection, es2015.generator, es2015.iterable, es2015.promise, es2015.proxy, es2015.reflect, es2015.symbol, es2015.symbol.wellknown, es2016.array.include, es2017.object, es2017.sharedmemory, es2017.string, es2017.intl, es2017.typedarrays, es2018.asyncgenerator, es2018.asynciterable, es2018.intl, es2018.promise, es2018.regexp, es2019.array, es2019.object, es2019.string, es2019.symbol, es2020.bigint, es2020.promise, es2020.sharedmemory, es2020.string, es2020.symbol.wellknown, es2020.intl, es2021.promise, es2021.string, es2021.weakref, es2021.intl, es2022.array, es2022.error, es2022.object, es2022.string, esnext.array, esnext.symbol, esnext.asynciterable, esnext.intl, esnext.bigint, esnext.string, esnext.promise, esnext.weakref
81+
one or more: es5, es6/es2015, es7/es2016, es2017, es2018, es2019, es2020, es2021, es2022, esnext, dom, dom.iterable, webworker, webworker.importscripts, webworker.iterable, scripthost, es2015.core, es2015.collection, es2015.generator, es2015.iterable, es2015.promise, es2015.proxy, es2015.reflect, es2015.symbol, es2015.symbol.wellknown, es2016.array.include, es2017.object, es2017.sharedmemory, es2017.string, es2017.intl, es2017.typedarrays, es2018.asyncgenerator, es2018.asynciterable/esnext.asynciterable, es2018.intl, es2018.promise, es2018.regexp, es2019.array, es2019.object, es2019.string, es2019.symbol/esnext.symbol, es2020.bigint/esnext.bigint, es2020.promise, es2020.sharedmemory, es2020.string, es2020.symbol.wellknown, es2020.intl, es2021.promise/esnext.promise, es2021.string, es2021.weakref/esnext.weakref, es2021.intl, es2022.array/esnext.array, es2022.error, es2022.object, es2022.string/esnext.string, esnext.intl
82+
default: undefined
8183

8284
--allowJs
8385
Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files.
@@ -91,7 +93,7 @@ default: false
9193

9294
--jsx
9395
Specify what JSX code is generated.
94-
one of: preserve, react-native, react, react-jsx, react-jsxdev
96+
one of: preserve, react, react-native, react-jsx, react-jsxdev
9597
default: undefined
9698

9799
--declaration, -d

0 commit comments

Comments
 (0)