estools / esquery

ECMAScript AST query library.
http://estools.github.io/esquery/
Other
825 stars 91 forks source link

Question: How can I match a specific child of a parent? #115

Closed captbaritone closed 4 years ago

captbaritone commented 4 years ago

Firstly, sorry for using the issue tracker as a Q/A. Feel free to close if this is not the right place to ask.

How could I (for example) construct a matcher that returns the left-hand-side of all LogicalExpressions?

My first instinct is that I could write LogicalExpression.left but that does not seem to work.

For context, I would like to be able to further refine my query to, for example, LogicalExpressions where the left hand side is an ObjectExpression, but I think the bit in bold above is the primitive I am missing.

captbaritone commented 4 years ago

Of course as soon as I open the issue I figure it out:

This will match LogicalExpressions which have a left property that is an ObjectExpression

LogicalExpression > ObjectExpression.left