Skip to content

Commit e515151

Browse files
author
Andy
authored
Remove unnecessary MapLikes in commandLineParser (#17324)
* Remove unnecessary `MapLike`s in commandLineParser * Fix typo * Inline knownKeysCount
1 parent c1375d5 commit e515151

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

src/compiler/commandLineParser.ts

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,8 +1225,8 @@ namespace ts {
12251225
});
12261226
}
12271227

1228-
function serializeCompilerOptions(options: CompilerOptions): MapLike<CompilerOptionsValue> {
1229-
const result: ts.MapLike<CompilerOptionsValue> = {};
1228+
function serializeCompilerOptions(options: CompilerOptions): Map<CompilerOptionsValue> {
1229+
const result = createMap<CompilerOptionsValue>();
12301230
const optionsNameMap = getOptionNameMap().optionNameMap;
12311231

12321232
for (const name in options) {
@@ -1243,15 +1243,15 @@ namespace ts {
12431243
if (!customTypeMap) {
12441244
// There is no map associated with this compiler option then use the value as-is
12451245
// This is the case if the value is expect to be string, number, boolean or list of string
1246-
result[name] = value;
1246+
result.set(name, value);
12471247
}
12481248
else {
12491249
if (optionDefinition.type === "list") {
1250-
result[name] = (value as ReadonlyArray<string | number>).map(element => getNameOfCompilerOptionValue(element, customTypeMap));
1250+
result.set(name, (value as ReadonlyArray<string | number>).map(element => getNameOfCompilerOptionValue(element, customTypeMap)));
12511251
}
12521252
else {
12531253
// There is a typeMap associated with this command-line option so use it to map value back to its name
1254-
result[name] = getNameOfCompilerOptionValue(value, customTypeMap);
1254+
result.set(name, getNameOfCompilerOptionValue(value, customTypeMap));
12551255
}
12561256
}
12571257
}
@@ -1283,33 +1283,30 @@ namespace ts {
12831283

12841284
function writeConfigurations() {
12851285
// Filter applicable options to place in the file
1286-
const categorizedOptions = reduceLeft(
1287-
filter(optionDeclarations, o => o.category !== Diagnostics.Command_line_Options && o.category !== Diagnostics.Advanced_Options),
1288-
(memo, value) => {
1289-
if (value.category) {
1290-
const name = getLocaleSpecificMessage(value.category);
1291-
(memo[name] || (memo[name] = [])).push(value);
1292-
}
1293-
return memo;
1294-
}, <MapLike<CommandLineOption[]>>{});
1286+
const categorizedOptions = createMultiMap<CommandLineOption>();
1287+
for (const option of optionDeclarations) {
1288+
const { category } = option;
1289+
if (category !== undefined && category !== Diagnostics.Command_line_Options && category !== Diagnostics.Advanced_Options) {
1290+
categorizedOptions.add(getLocaleSpecificMessage(category), option);
1291+
}
1292+
}
12951293

1296-
// Serialize all options and thier descriptions
1294+
// Serialize all options and their descriptions
12971295
let marginLength = 0;
12981296
let seenKnownKeys = 0;
12991297
const nameColumn: string[] = [];
13001298
const descriptionColumn: string[] = [];
1301-
const knownKeysCount = getOwnKeys(compilerOptionsMap).length;
1302-
for (const category in categorizedOptions) {
1299+
categorizedOptions.forEach((options, category) => {
13031300
if (nameColumn.length !== 0) {
13041301
nameColumn.push("");
13051302
descriptionColumn.push("");
13061303
}
13071304
nameColumn.push(`/* ${category} */`);
13081305
descriptionColumn.push("");
1309-
for (const option of categorizedOptions[category]) {
1306+
for (const option of options) {
13101307
let optionName;
1311-
if (hasProperty(compilerOptionsMap, option.name)) {
1312-
optionName = `"${option.name}": ${JSON.stringify(compilerOptionsMap[option.name])}${(seenKnownKeys += 1) === knownKeysCount ? "" : ","}`;
1308+
if (compilerOptionsMap.has(option.name)) {
1309+
optionName = `"${option.name}": ${JSON.stringify(compilerOptionsMap.get(option.name))}${(seenKnownKeys += 1) === compilerOptionsMap.size ? "" : ","}`;
13131310
}
13141311
else {
13151312
optionName = `// "${option.name}": ${JSON.stringify(getDefaultValueForOption(option))},`;
@@ -1318,7 +1315,7 @@ namespace ts {
13181315
descriptionColumn.push(`/* ${option.description && getLocaleSpecificMessage(option.description) || option.name} */`);
13191316
marginLength = Math.max(optionName.length, marginLength);
13201317
}
1321-
}
1318+
});
13221319

13231320
// Write the output
13241321
const tab = makePadding(2);

0 commit comments

Comments
 (0)