Skip to content

Commit

Permalink
replace for of with forEach
Browse files Browse the repository at this point in the history
  • Loading branch information
golopot committed May 16, 2022
1 parent 1db241c commit 4bc7669
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions lib/util/Components.js
Expand Up @@ -256,27 +256,26 @@ function getWrapperFunctions(context, pragma) {
function mergeRules(rules) {
/** @type {Map<string, Function[]>} */
const handlersByKey = new Map();
for (const rule of rules) {
for (const key of Object.keys(rule)) {
rules.forEach((rule) => {
Object.keys(rule).forEach((key) => {
const fns = handlersByKey.get(key);
if (!fns) {
handlersByKey.set(key, [rule[key]]);
} else {
fns.push(rule[key]);
}
}
}
});
});

/** @type {{[key: string]: Function}} */
const rule = {};
for (const key of handlersByKey.keys()) {
const fns = handlersByKey.get(key);
handlersByKey.forEach((fns, key) => {
rule[key] = function mergedHandler(node) {
for (const fn of fns) {
fns.forEach((fn) => {
fn(node);
}
});
};
}
});

return rule;
}
Expand Down

0 comments on commit 4bc7669

Please sign in to comment.