Use Object.{entries,values} if possible (#10131)
This commit is contained in:
1 parent
ce26805e84
commit
89e5751b46
9 files changed
+32
-31
No files matched your search
@@ -55,9 +55,9 @@ function* expandPatternsInternal(context) {
|
||||
|
||||
const globOptions = {
|
||||
dot: true,
|
||||
ignore: Object.keys(silentlyIgnoredDirs)
|
||||
.filter((dir) => silentlyIgnoredDirs[dir])
|
||||
.map((dir) => "**/" + dir),
|
||||
ignore: Object.entries(silentlyIgnoredDirs)
|
||||
.filter(([, ignored]) => ignored)
|
||||
.map(([dir]) => "**/" + dir),
|
||||
};
|
||||
|
||||
let supportedFilesGlob;
|
||||
|
||||
+7
-6
@@ -20,13 +20,14 @@ function getOptions(argv, detailedOptions) {
|
||||
}
|
||||
|
||||
function cliifyOptions(object, apiDetailedOptionMap) {
|
||||
return Object.keys(object || {}).reduce((output, key) => {
|
||||
const apiOption = apiDetailedOptionMap[key];
|
||||
const cliKey = apiOption ? apiOption.name : key;
|
||||
return fromPairs(
|
||||
Object.entries(object || {}).map(([key, value]) => {
|
||||
const apiOption = apiDetailedOptionMap[key];
|
||||
const cliKey = apiOption ? apiOption.name : key;
|
||||
|
||||
output[dashify(cliKey)] = object[key];
|
||||
return output;
|
||||
}, {});
|
||||
return [dashify(cliKey), value];
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
function createApiDetailedOptionMap(detailedOptions) {
|
||||
|
||||
+2
-5
@@ -176,11 +176,8 @@ function createDetailedUsage(context, flag) {
|
||||
|
||||
const pluginDefaults =
|
||||
option.pluginDefaults && Object.keys(option.pluginDefaults).length > 0
|
||||
? `\nPlugin defaults:${Object.keys(option.pluginDefaults).map(
|
||||
(key) =>
|
||||
`\n* ${key}: ${createDefaultValueDisplay(
|
||||
option.pluginDefaults[key]
|
||||
)}`
|
||||
? `\nPlugin defaults:${Object.entries(option.pluginDefaults).map(
|
||||
([key, value]) => `\n* ${key}: ${createDefaultValueDisplay(value)}`
|
||||
)}`
|
||||
: "";
|
||||
return `${header}${description}${choices}${defaults}${pluginDefaults}`;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
const fromPairs = require("lodash/fromPairs");
|
||||
const { isNonEmptyArray } = require("../common/util");
|
||||
const NODES_KEYS = {
|
||||
attrs: true,
|
||||
@@ -8,8 +9,7 @@ const NODES_KEYS = {
|
||||
|
||||
class Node {
|
||||
constructor(props = {}) {
|
||||
for (const key of Object.keys(props)) {
|
||||
const value = props[key];
|
||||
for (const [key, value] of Object.entries(props)) {
|
||||
if (key in NODES_KEYS) {
|
||||
this._setNodes(key, value);
|
||||
} else {
|
||||
@@ -123,10 +123,13 @@ function cloneAndUpdateNodes(nodes, parent) {
|
||||
}
|
||||
|
||||
function setNonEnumerableProperties(obj, props) {
|
||||
const descriptors = Object.keys(props).reduce((reduced, key) => {
|
||||
reduced[key] = { value: props[key], enumerable: false };
|
||||
return reduced;
|
||||
}, {});
|
||||
const descriptors = fromPairs(
|
||||
Object.entries(props).map(([key, value]) => [
|
||||
key,
|
||||
{ value, enumerable: false },
|
||||
])
|
||||
);
|
||||
|
||||
Object.defineProperties(obj, descriptors);
|
||||
}
|
||||
|
||||
|
||||
@@ -46,8 +46,8 @@ function arrayToMap(array) {
|
||||
|
||||
function mapObject(object, fn) {
|
||||
const newObject = Object.create(null);
|
||||
for (const key of Object.keys(object)) {
|
||||
newObject[key] = fn(object[key], key);
|
||||
for (const [key, value] of Object.entries(object)) {
|
||||
newObject[key] = fn(value, key);
|
||||
}
|
||||
return newObject;
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ function hasNode(node, fn) {
|
||||
const result = fn(node);
|
||||
return typeof result === "boolean"
|
||||
? result
|
||||
: Object.keys(node).some((key) => hasNode(node[key], fn));
|
||||
: Object.values(node).some((value) => hasNode(value, fn));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -50,16 +50,16 @@ function getSortedChildNodes(node, options, resultArray) {
|
||||
(printer.getCommentChildNodes &&
|
||||
printer.getCommentChildNodes(node, options)) ||
|
||||
(typeof node === "object" &&
|
||||
Object.keys(node)
|
||||
Object.entries(node)
|
||||
.filter(
|
||||
(n) =>
|
||||
([n]) =>
|
||||
n !== "enclosingNode" &&
|
||||
n !== "precedingNode" &&
|
||||
n !== "followingNode" &&
|
||||
n !== "tokens" &&
|
||||
n !== "comments"
|
||||
)
|
||||
.map((n) => node[n]));
|
||||
.map(([, value]) => value));
|
||||
|
||||
if (!childNodes) {
|
||||
return;
|
||||
|
||||
@@ -18,9 +18,9 @@ function massageAST(ast, options, parent) {
|
||||
}
|
||||
|
||||
const newObj = {};
|
||||
for (const key of Object.keys(ast)) {
|
||||
if (!ignoredProperties.has(key) && typeof ast[key] !== "function") {
|
||||
newObj[key] = massageAST(ast[key], options, ast);
|
||||
for (const [key, value] of Object.entries(ast)) {
|
||||
if (!ignoredProperties.has(key) && typeof value !== "function") {
|
||||
newObj[key] = massageAST(value, options, ast);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -86,9 +86,9 @@ function normalize(options, opts) {
|
||||
|
||||
const mixedDefaults = { ...defaults, ...pluginDefaults };
|
||||
|
||||
for (const k of Object.keys(mixedDefaults)) {
|
||||
for (const [k, value] of Object.entries(mixedDefaults)) {
|
||||
if (rawOptions[k] == null) {
|
||||
rawOptions[k] = mixedDefaults[k];
|
||||
rawOptions[k] = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user