1 | 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:
|
---|
2 |
|
---|
3 | [demo](https://estools.github.io/esquery/)
|
---|
4 |
|
---|
5 | The following selectors are supported:
|
---|
6 | * AST node type: `ForStatement`
|
---|
7 | * [wildcard](http://dev.w3.org/csswg/selectors4/#universal-selector): `*`
|
---|
8 | * [attribute existence](http://dev.w3.org/csswg/selectors4/#attribute-selectors): `[attr]`
|
---|
9 | * [attribute value](http://dev.w3.org/csswg/selectors4/#attribute-selectors): `[attr="foo"]` or `[attr=123]`
|
---|
10 | * attribute regex: `[attr=/foo.*/]` or (with flags) `[attr=/foo.*/is]`
|
---|
11 | * attribute conditions: `[attr!="foo"]`, `[attr>2]`, `[attr<3]`, `[attr>=2]`, or `[attr<=3]`
|
---|
12 | * nested attribute: `[attr.level2="foo"]`
|
---|
13 | * field: `FunctionDeclaration > Identifier.id`
|
---|
14 | * [First](http://dev.w3.org/csswg/selectors4/#the-first-child-pseudo) or [last](http://dev.w3.org/csswg/selectors4/#the-last-child-pseudo) child: `:first-child` or `:last-child`
|
---|
15 | * [nth-child](http://dev.w3.org/csswg/selectors4/#the-nth-child-pseudo) (no ax+b support): `:nth-child(2)`
|
---|
16 | * [nth-last-child](http://dev.w3.org/csswg/selectors4/#the-nth-last-child-pseudo) (no ax+b support): `:nth-last-child(1)`
|
---|
17 | * [descendant](http://dev.w3.org/csswg/selectors4/#descendant-combinators): `ancestor descendant`
|
---|
18 | * [child](http://dev.w3.org/csswg/selectors4/#child-combinators): `parent > child`
|
---|
19 | * [following sibling](http://dev.w3.org/csswg/selectors4/#general-sibling-combinators): `node ~ sibling`
|
---|
20 | * [adjacent sibling](http://dev.w3.org/csswg/selectors4/#adjacent-sibling-combinators): `node + adjacent`
|
---|
21 | * [negation](http://dev.w3.org/csswg/selectors4/#negation-pseudo): `:not(ForStatement)`
|
---|
22 | * [has](https://drafts.csswg.org/selectors-4/#has-pseudo): `:has(ForStatement)`, `:has(> ForStatement)`
|
---|
23 | * [matches-any](http://dev.w3.org/csswg/selectors4/#matches): `:matches([attr] > :first-child, :last-child)`
|
---|
24 | * [subject indicator](http://dev.w3.org/csswg/selectors4/#subject): `!IfStatement > [name="foo"]`
|
---|
25 | * class of AST node: `:statement`, `:expression`, `:declaration`, `:function`, or `:pattern`
|
---|
26 |
|
---|
27 | [![Build Status](https://travis-ci.org/estools/esquery.png?branch=master)](https://travis-ci.org/estools/esquery)
|
---|