Skip to content

Commit

Permalink
Merge pull request #87 from Rondinelly/has-selector-pseudo-class
Browse files Browse the repository at this point in the history
Add `:has()` selector pseudo-class
  • Loading branch information
dperini committed May 10, 2023
2 parents e60b058 + 8ae6f88 commit b8654a4
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/nwsapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
GROUPS = {
// pseudo-classes requiring parameters
linguistic: '(dir|lang)(?:\\x28\\s?([-\\w]{2,})\\s?\\x29)',
logicalsel: '(is|where|matches|not)(?:\\x28\\s?((?:[.:#*]?[-\\w]+)|(?:\\[([^\\[\\]]*)\\])|.*)\\s?\\x29)',
logicalsel: '(is|where|matches|not|has)(?:\\x28\\s?((?:[.:#*]?[-\\w]+)|(?:\\[([^\\[\\]]*)\\])|.*)\\s?\\x29)',
treestruct: '(nth(?:-last)?(?:-child|-of-type))(?:\\x28\\s?(even|odd|(?:[-+]?\\d*)(?:n\\s?[-+]?\\s?\\d*)?)\\s?\\x29)',
// pseudo-classes not requiring parameters
locationpc: '(any-link|link|visited|target)\\b',
Expand Down Expand Up @@ -1003,6 +1003,11 @@
expr = match[2].replace(REX.CommaGroup, ',').replace(REX.TrimSpaces, '');
source = 'if(!s.match("' + expr.replace(/\x22/g, '\\"') + '",e)){' + source + '}';
break;
case 'has':
let referenceElement = selector_string.split(':')[0]
expr = match[2].replace(REX.CommaGroup, ',').replace(REX.TrimSpaces, '');
source = 'if(s.match("' + expr.replace(/\x22/g, '\\"') + ',' + referenceElement + '",e)){' + source + '}';
break;
default:
emit('\'' + selector_string + '\'' + qsInvalid);
break;
Expand Down

0 comments on commit b8654a4

Please sign in to comment.