From e515151ba4b1a2f7e5a4910eaebe88f91228efc3 Mon Sep 17 00:00:00 2001 From: Andy Date: Tue, 25 Jul 2017 14:19:17 -0700 Subject: [PATCH] Remove unnecessary `MapLike`s in commandLineParser (#17324) * Remove unnecessary `MapLike`s in commandLineParser * Fix typo * Inline knownKeysCount --- src/compiler/commandLineParser.ts | 39 ++++++++++++++----------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 6cc3db8813a..554b46dcdfe 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -1225,8 +1225,8 @@ namespace ts { }); } - function serializeCompilerOptions(options: CompilerOptions): MapLike { - const result: ts.MapLike = {}; + function serializeCompilerOptions(options: CompilerOptions): Map { + const result = createMap(); const optionsNameMap = getOptionNameMap().optionNameMap; for (const name in options) { @@ -1243,15 +1243,15 @@ namespace ts { if (!customTypeMap) { // There is no map associated with this compiler option then use the value as-is // This is the case if the value is expect to be string, number, boolean or list of string - result[name] = value; + result.set(name, value); } else { if (optionDefinition.type === "list") { - result[name] = (value as ReadonlyArray).map(element => getNameOfCompilerOptionValue(element, customTypeMap)); + result.set(name, (value as ReadonlyArray).map(element => getNameOfCompilerOptionValue(element, customTypeMap))); } else { // There is a typeMap associated with this command-line option so use it to map value back to its name - result[name] = getNameOfCompilerOptionValue(value, customTypeMap); + result.set(name, getNameOfCompilerOptionValue(value, customTypeMap)); } } } @@ -1283,33 +1283,30 @@ namespace ts { function writeConfigurations() { // Filter applicable options to place in the file - const categorizedOptions = reduceLeft( - filter(optionDeclarations, o => o.category !== Diagnostics.Command_line_Options && o.category !== Diagnostics.Advanced_Options), - (memo, value) => { - if (value.category) { - const name = getLocaleSpecificMessage(value.category); - (memo[name] || (memo[name] = [])).push(value); - } - return memo; - }, >{}); + const categorizedOptions = createMultiMap(); + for (const option of optionDeclarations) { + const { category } = option; + if (category !== undefined && category !== Diagnostics.Command_line_Options && category !== Diagnostics.Advanced_Options) { + categorizedOptions.add(getLocaleSpecificMessage(category), option); + } + } - // Serialize all options and thier descriptions + // Serialize all options and their descriptions let marginLength = 0; let seenKnownKeys = 0; const nameColumn: string[] = []; const descriptionColumn: string[] = []; - const knownKeysCount = getOwnKeys(compilerOptionsMap).length; - for (const category in categorizedOptions) { + categorizedOptions.forEach((options, category) => { if (nameColumn.length !== 0) { nameColumn.push(""); descriptionColumn.push(""); } nameColumn.push(`/* ${category} */`); descriptionColumn.push(""); - for (const option of categorizedOptions[category]) { + for (const option of options) { let optionName; - if (hasProperty(compilerOptionsMap, option.name)) { - optionName = `"${option.name}": ${JSON.stringify(compilerOptionsMap[option.name])}${(seenKnownKeys += 1) === knownKeysCount ? "" : ","}`; + if (compilerOptionsMap.has(option.name)) { + optionName = `"${option.name}": ${JSON.stringify(compilerOptionsMap.get(option.name))}${(seenKnownKeys += 1) === compilerOptionsMap.size ? "" : ","}`; } else { optionName = `// "${option.name}": ${JSON.stringify(getDefaultValueForOption(option))},`; @@ -1318,7 +1315,7 @@ namespace ts { descriptionColumn.push(`/* ${option.description && getLocaleSpecificMessage(option.description) || option.name} */`); marginLength = Math.max(optionName.length, marginLength); } - } + }); // Write the output const tab = makePadding(2);