Skip to content

Commit

Permalink
Add :root selector; see estools#2
Browse files Browse the repository at this point in the history
  • Loading branch information
jupenur committed Aug 22, 2017
1 parent c889544 commit 3141c00
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
3 changes: 3 additions & 0 deletions esquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@
node.type === 'ArrowFunctionExpression';
}
throw new Error('Unknown class name: ' + selector.name);

case 'root':
return ancestry.length === 0;
}

throw new Error('Unknown selector type: ' + selector.type);
Expand Down
4 changes: 3 additions & 1 deletion grammar.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ sequence

atom
= wildcard / identifier / attr / field / negation / matches
/ has / firstChild / lastChild / nthChild / nthLastChild / class
/ has / firstChild / lastChild / nthChild / nthLastChild / class / root

wildcard = a:"*" { return { type: 'wildcard', value: a }; }
identifier = "#"? i:identifierName { return { type: 'identifier', value: i }; }
Expand Down Expand Up @@ -99,3 +99,5 @@ nthLastChild = ":nth-last-child(" _ n:[0-9]+ _ ")" { return nthLast(parseInt(n.j
class = ":" c:("statement"i / "expression"i / "declaration"i / "function"i / "pattern"i) {
return { type: 'class', name: c };
}

root = ":root" { return { type: 'root' }; }
41 changes: 40 additions & 1 deletion parser.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3141c00

Please sign in to comment.