Skip to content

Commit

Permalink
Replace loops with foreach
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkomarychev committed Jun 24, 2020
1 parent edbc93b commit c10e217
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions utils/visit.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,11 @@ exports.default = function visit(node, keys, visitorSpec) {
if (!childFields) {
return
}
for (const fieldName of childFields) {
const field = node[fieldName]
if (Array.isArray(field)) {
for (const item of field) {
visit(item, keys, visitorSpec)
}
} else {
visit(field, keys, visitorSpec)
}
}
childFields.forEach((fieldName) => {
[].concat(node[fieldName]).forEach((item) => {
visit(item, keys, visitorSpec)
})
})
if (typeof visitorSpec[`${type}:Exit`] === 'function') {
visitorSpec[`${type}:Exit`](node)
}
Expand Down

0 comments on commit c10e217

Please sign in to comment.