Skip to content

Commit

Permalink
Revert naked binaryOp at the start of a selector within :has() (estoo…
Browse files Browse the repository at this point in the history
…ls#145)

This reverts most of commit 00448e0.
  • Loading branch information
lukaw3d committed Aug 6, 2024
1 parent 766f9ec commit ca5b737
Show file tree
Hide file tree
Showing 3 changed files with 275 additions and 435 deletions.
5 changes: 0 additions & 5 deletions esquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,6 @@ function generateMatcher(selector) {
};
}

case 'exactNode':
return (node, ancestry) => {
return ancestry.length === 0;
};

case 'field': {
const path = selector.name.split('.');
return (node, ancestry) => {
Expand Down
13 changes: 1 addition & 12 deletions grammar.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,10 @@ binaryOp
/ _ "+" _ { return 'adjacent'; }
/ " " _ { return 'descendant'; }

hasSelectors = s:hasSelector ss:(_ "," _ hasSelector)* {
return [s].concat(ss.map(function (s) { return s[3]; }));
}

selectors = s:selector ss:(_ "," _ selector)* {
return [s].concat(ss.map(function (s) { return s[3]; }));
}


hasSelector
= op:binaryOp? s:selector {
if (!op) return s;
return { type: op, left: { type: 'exactNode' }, right: s };
}

selector
= a:sequence ops:(binaryOp sequence)* {
return ops.reduce(function (memo, rhs) {
Expand Down Expand Up @@ -107,7 +96,7 @@ field = "." i:identifierName is:("." identifierName)* {

negation = ":not(" _ ss:selectors _ ")" { return { type: 'not', selectors: ss }; }
matches = ":matches(" _ ss:selectors _ ")" { return { type: 'matches', selectors: ss }; }
has = ":has(" _ ss:hasSelectors _ ")" { return { type: 'has', selectors: ss }; }
has = ":has(" _ ss:selectors _ ")" { return { type: 'has', selectors: ss }; }

firstChild = ":first-child" { return nth(1); }
lastChild = ":last-child" { return nthLast(1); }
Expand Down
Loading

0 comments on commit ca5b737

Please sign in to comment.