Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 4 additions & 16 deletions esquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ function inPath(node, ancestor, path) {
const field = ancestor[path[0]];
const remainingPath = path.slice(1);
if (Array.isArray(field)) {
for (const component of field) {
if (inPath(node, component, remainingPath)) { return true; }
}
return false;
return field.some((component) => inPath(node, component, remainingPath));
} else {
return inPath(node, field, remainingPath);
}
Expand Down Expand Up @@ -105,22 +102,13 @@ function matches(node, selector, ancestry, options) {

}
case 'matches':
for (const sel of selector.selectors) {
if (matches(node, sel, ancestry, options)) { return true; }
}
return false;
return selector.selectors.some(sel => matches(node, sel, ancestry, options));

case 'compound':
for (const sel of selector.selectors) {
if (!matches(node, sel, ancestry, options)) { return false; }
}
return true;
return selector.selectors.every(sel => matches(node, sel, ancestry, options));

case 'not':
for (const sel of selector.selectors) {
if (matches(node, sel, ancestry, options)) { return false; }
}
return true;
return selector.selectors.every(sel => !matches(node, sel, ancestry, options));

case 'has': {
const collector = [];
Expand Down