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

Describe defaults of more options #46498

Merged
merged 3 commits into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
178 changes: 94 additions & 84 deletions src/compiler/commandLineParser.ts

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6335,7 +6335,7 @@ namespace ts {
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.
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.
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.
paramType?: DiagnosticMessage; // The name to be used for a non-boolean option's parameter
isTSConfigOnly?: boolean; // True if option can only be specified via tsconfig.json file
isCommandLineOnly?: boolean;
Expand All @@ -6355,23 +6355,25 @@ namespace ts {
/* @internal */
export interface CommandLineOptionOfStringType extends CommandLineOptionBase {
type: "string";
defaultValueDescription?: string | undefined | DiagnosticMessage;
}

/* @internal */
export interface CommandLineOptionOfNumberType extends CommandLineOptionBase {
type: "number";
defaultValueDescription: `${number | undefined}` | DiagnosticMessage;
defaultValueDescription: number | undefined | DiagnosticMessage;
}

/* @internal */
export interface CommandLineOptionOfBooleanType extends CommandLineOptionBase {
type: "boolean";
defaultValueDescription: `${boolean | undefined}` | DiagnosticMessage;
defaultValueDescription: boolean | undefined | DiagnosticMessage;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

and likewise number/boolean literals vs. strings.

}

/* @internal */
export interface CommandLineOptionOfCustomType extends CommandLineOptionBase {
type: ESMap<string, number | string>; // an object literal mapping named values to actual values
defaultValueDescription: number | string | undefined | DiagnosticMessage;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've now added a commit to accommodate enum members vs. strings in defaultValueDescription, e.g.

defaultValueDescription: ImportsNotUsedAsValues.Remove,

}

/* @internal */
Expand Down
31 changes: 28 additions & 3 deletions src/executeCommandLine/executeCommandLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,13 @@ namespace ts {

// value type and possible value
const valueCandidates = getValueCandidate(option);
const defaultValueDescription = typeof option.defaultValueDescription === "object" ? getDiagnosticText(option.defaultValueDescription) : option.defaultValueDescription;
const defaultValueDescription =
typeof option.defaultValueDescription === "object"
? getDiagnosticText(option.defaultValueDescription)
: formatDefaultValue(
option.defaultValueDescription,
option.type === "list" ? option.element.type : option.type
);
const terminalWidth = sys.getWidthOfTerminal?.() ?? 0;

// Note: child_process might return `terminalWidth` as undefined.
Expand Down Expand Up @@ -203,6 +209,19 @@ namespace ts {
}
return text;

function formatDefaultValue(
defaultValue: CommandLineOption["defaultValueDescription"],
type: CommandLineOption["type"]
) {
return defaultValue !== undefined && typeof type === "object"
// e.g. ScriptTarget.ES2015 -> "es6/es2015"
? arrayFrom(type.entries())
.filter(([, value]) => value === defaultValue)
.map(([name]) => name)
.join("/")
: String(defaultValue);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated --help to stringify enum members and number/boolean literals, e.g. ImportsNotUsedAsValues.Remove -> remove.

}

function showAdditionalInfoOutput(valueCandidates: ValueCandidate | undefined, option: CommandLineOption): boolean {
const ignoreValues = ["string"];
const ignoredDescriptions = [undefined, "false", "n/a"];
Expand Down Expand Up @@ -286,8 +305,14 @@ namespace ts {
break;
default:
// ESMap<string, number | string>
const keys = arrayFrom(option.type.keys());
possibleValues = keys.join(", ");
// Group synonyms: es6/es2015
const inverted: { [value: string]: string[] } = {};
option.type.forEach((value, name) => {
(inverted[value] ||= []).push(name);
});
return getEntries(inverted)
.map(([, synonyms]) => synonyms.join("/"))
.join(", ");
Copy link
Contributor Author

@jablko jablko Oct 24, 2021

Choose a reason for hiding this comment

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

Because this prints all of an enum member's synonyms, I correspondingly updated the way --help formats possible values. Not that any current default has synonyms.

}
return possibleValues;
}
Expand Down
14 changes: 7 additions & 7 deletions src/harness/harnessIO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,21 +304,21 @@ namespace Harness {

// Additional options not already in ts.optionDeclarations
const harnessOptionDeclarations: ts.CommandLineOption[] = [
{ name: "allowNonTsExtensions", type: "boolean", defaultValueDescription: "false" },
{ name: "useCaseSensitiveFileNames", type: "boolean", defaultValueDescription: "false" },
{ name: "allowNonTsExtensions", type: "boolean", defaultValueDescription: false },
{ name: "useCaseSensitiveFileNames", type: "boolean", defaultValueDescription: false },
{ name: "baselineFile", type: "string" },
{ name: "includeBuiltFile", type: "string" },
{ name: "fileName", type: "string" },
{ name: "libFiles", type: "string" },
{ name: "noErrorTruncation", type: "boolean", defaultValueDescription: "false" },
{ name: "suppressOutputPathCheck", type: "boolean", defaultValueDescription: "false" },
{ name: "noImplicitReferences", type: "boolean", defaultValueDescription: "false" },
{ name: "noErrorTruncation", type: "boolean", defaultValueDescription: false },
{ name: "suppressOutputPathCheck", type: "boolean", defaultValueDescription: false },
{ name: "noImplicitReferences", type: "boolean", defaultValueDescription: false },
{ name: "currentDirectory", type: "string" },
{ name: "symlink", type: "string" },
{ name: "link", type: "string" },
{ name: "noTypesAndSymbols", type: "boolean", defaultValueDescription: "false" },
{ name: "noTypesAndSymbols", type: "boolean", defaultValueDescription: false },
// Emitted js baseline will print full paths for every output file
{ name: "fullEmitPaths", type: "boolean", defaultValueDescription: "false" }
{ name: "fullEmitPaths", type: "boolean", defaultValueDescription: false },
];

let optionsIndex: ts.ESMap<string, ts.CommandLineOption>;
Expand Down
2 changes: 1 addition & 1 deletion src/testRunner/unittests/config/commandLineParsing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ namespace ts {
isTSConfigOnly: true,
category: Diagnostics.Backwards_Compatibility,
description: Diagnostics.Enable_project_compilation,
defaultValueDescription: "undefined",
defaultValueDescription: undefined,
}
];
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,18 @@ default: true

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

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

--lib
Specify a set of bundled library declaration files that describe the target runtime environment.
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
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
default: undefined

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

--jsx
Specify what JSX code is generated.
one of: preserve, react-native, react, react-jsx, react-jsxdev
one of: preserve, react, react-native, react-jsx, react-jsxdev
default: undefined

--declaration, -d
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,18 @@ default: true

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

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

--lib
Specify a set of bundled library declaration files that describe the target runtime environment.
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
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
default: undefined

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

--jsx
Specify what JSX code is generated.
one of: preserve, react-native, react, react-jsx, react-jsxdev
one of: preserve, react, react-native, react-jsx, react-jsxdev
default: undefined

--declaration, -d
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,18 @@ default: true

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

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

--lib
Specify a set of bundled library declaration files that describe the target runtime environment.
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
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
default: undefined

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

--jsx
Specify what JSX code is generated.
one of: preserve, react-native, react, react-jsx, react-jsxdev
one of: preserve, react, react-native, react-jsx, react-jsxdev
default: undefined

--declaration, -d
Expand Down