-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -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; | ||||
|
@@ -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; | ||||
} | ||||
|
||||
/* @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; | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 TypeScript/src/compiler/commandLineParser.ts Line 596 in d31ac53
|
||||
} | ||||
|
||||
/* @internal */ | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
} | ||
|
||
function showAdditionalInfoOutput(valueCandidates: ValueCandidate | undefined, option: CommandLineOption): boolean { | ||
const ignoreValues = ["string"]; | ||
const ignoredDescriptions = [undefined, "false", "n/a"]; | ||
|
@@ -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(", "); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
|
There was a problem hiding this comment.
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.