Skip to content

Commit

Permalink
Replace 'has' rule collector array with a boolean flag
Browse files Browse the repository at this point in the history
  • Loading branch information
jviide authored and michaelficarra committed Feb 16, 2023
1 parent b030861 commit 73ce628
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions esquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,23 +113,23 @@ function createMatcher(selector) {
case 'has': {
const { selectors } = selector;
return (node, ancestry, options) => {
const collector = [];
let result = false;
for (let i = 0; i < selectors.length; i++) {
const sel = selectors[i];
const a = [];
estraverse.traverse(node, {
enter (node, parent) {
if (parent != null) { a.unshift(parent); }
if (matches(node, sel, a, options)) {
collector.push(node);
result = true;
}
},
leave () { a.shift(); },
keys: options && options.visitorKeys,
fallback: options && options.fallback || 'iteration'
});
}
return collector.length !== 0;
return result;
};
}
case 'child':
Expand Down

0 comments on commit 73ce628

Please sign in to comment.