Refactor: Use fromPairs instead of Array#reduce (#10262)
* Refactor: Use `fromPairs` instead of `Array#reduce` * Restore unrelated change
This commit is contained in:
1 parent
cc1f0543e6
commit
bf3cabd2bb
3 files changed
+25
-27
No files matched your search
@@ -23,10 +23,9 @@ class Node {
|
||||
this[key] = cloneAndUpdateNodes(nodes, this);
|
||||
if (key === "attrs") {
|
||||
setNonEnumerableProperties(this, {
|
||||
attrMap: this[key].reduce((reduced, attr) => {
|
||||
reduced[attr.fullName] = attr.value;
|
||||
return reduced;
|
||||
}, Object.create(null)),
|
||||
attrMap: fromPairs(
|
||||
this[key].map((attr) => [attr.fullName, attr.value])
|
||||
),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
+12
-13
@@ -68,19 +68,18 @@ function normalize(options, opts = {}) {
|
||||
const plugin = getPlugin(rawOptions);
|
||||
rawOptions.printer = plugin.printers[rawOptions.astFormat];
|
||||
|
||||
const pluginDefaults = supportOptions
|
||||
.filter(
|
||||
(optionInfo) =>
|
||||
optionInfo.pluginDefaults &&
|
||||
optionInfo.pluginDefaults[plugin.name] !== undefined
|
||||
)
|
||||
.reduce(
|
||||
(reduced, optionInfo) =>
|
||||
Object.assign(reduced, {
|
||||
[optionInfo.name]: optionInfo.pluginDefaults[plugin.name],
|
||||
}),
|
||||
{}
|
||||
);
|
||||
const pluginDefaults = fromPairs(
|
||||
supportOptions
|
||||
.filter(
|
||||
(optionInfo) =>
|
||||
optionInfo.pluginDefaults &&
|
||||
optionInfo.pluginDefaults[plugin.name] !== undefined
|
||||
)
|
||||
.map((optionInfo) => [
|
||||
optionInfo.name,
|
||||
optionInfo.pluginDefaults[plugin.name],
|
||||
])
|
||||
);
|
||||
|
||||
const mixedDefaults = { ...defaults, ...pluginDefaults };
|
||||
|
||||
|
||||
+10
-10
@@ -1,5 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
const fromPairs = require("lodash/fromPairs");
|
||||
const semver = {
|
||||
compare: require("semver/functions/compare"),
|
||||
lt: require("semver/functions/lt"),
|
||||
@@ -64,16 +65,15 @@ function getSupportInfo({
|
||||
}
|
||||
}
|
||||
|
||||
const pluginDefaults = plugins
|
||||
.filter(
|
||||
(plugin) =>
|
||||
plugin.defaultOptions &&
|
||||
plugin.defaultOptions[option.name] !== undefined
|
||||
)
|
||||
.reduce((reduced, plugin) => {
|
||||
reduced[plugin.name] = plugin.defaultOptions[option.name];
|
||||
return reduced;
|
||||
}, {});
|
||||
const pluginDefaults = fromPairs(
|
||||
plugins
|
||||
.filter(
|
||||
(plugin) =>
|
||||
plugin.defaultOptions &&
|
||||
plugin.defaultOptions[option.name] !== undefined
|
||||
)
|
||||
.map((plugin) => [plugin.name, plugin.defaultOptions[option.name]])
|
||||
);
|
||||
|
||||
return { ...option, pluginDefaults };
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user