estools / esquery

ECMAScript AST query library.

Home Page:http://estools.github.io/esquery/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Help with array null child selector

mariaines opened this issue · comments

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] = ...

You mean something like this?

VariableDeclaration[kind=const] > VariableDeclarator[id.type=ArrayPattern] > ArrayPattern[elements.0=null]

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

No worries, happy I could help.