esquery
ESQuery is a library for querying the AST output by Esprima for patterns of syntax using a CSS style selector system. Check out the demo:
The following selectors are supported:
AST node type:
ForStatementwildcard:
*attribute existence:
[attr]attribute value:
[attr="foo"]or[attr=123]attribute regex:
[attr=/foo.*/]or (with flags)[attr=/foo.*/is]attribute conditions:
[attr!="foo"],[attr>2],[attr<3],[attr>=2], or[attr<=3]nested attribute:
[attr.level2="foo"]field:
FunctionDeclaration > Identifier.idnth-child (no ax+b support):
:nth-child(2)nth-last-child (no ax+b support):
:nth-last-child(1)descendant:
ancestor descendantchild:
parent > childfollowing sibling:
node ~ siblingadjacent sibling:
node + adjacentnegation:
:not(ForStatement)has:
:has(ForStatement)matches-any:
:matches([attr] > :first-child, :last-child)subject indicator:
!IfStatement > [name="foo"]class of AST node:
:statement,:expression,:declaration,:function, or:pattern
Last updated
Was this helpful?