estools / esquery

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

Help with array null child selector #143

Closed mariaines closed 1 year ago

mariaines commented 1 year ago

Hi there,

I'm trying to write a selector to match an array where the first child is null. This issue showed me how to select the first child, but how do I match against a null element when there are no fields to check? I hope this is possible 🤞🏽

Specifically I'm trying to match against:

const [, actions] = ...

I can get this to work: "VariableDeclaration[kind=const] > VariableDeclarator[id.type=ArrayPattern] > ArrayPattern[elements.length=2] >.elements:nth-child(1)[name=someName]" against:

const [someName, actions] = ...
michaelficarra commented 1 year ago

You mean something like this?

VariableDeclaration[kind=const] > VariableDeclarator[id.type=ArrayPattern] > ArrayPattern[elements.0=null]
mariaines commented 1 year ago

Yes, that does it! Please forgive the noob question 🙂 Thank you so much @michaelficarra !

michaelficarra commented 1 year ago

No worries, happy I could help.