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 <typescriptbot@microsoft.com>
This commit is contained in:
Jack Bates
2021-12-01 08:45:00 -07:00
committed by GitHub
parent b8ec791ca1
commit 670ad45bda
8 changed files with 156 additions and 113 deletions

View File

@@ -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);
}
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(", ");
}
return possibleValues;
}