benjamn / ast-types

Esprima-compatible implementation of the Mozilla JS Parser API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Variables declared in object destructuring aren't collected as bindings when using babel parser

RoystonS opened this issue · comments

I was just trying out my very first bit of jscodeshift and got immediately stuck with an issue that my object destructuring assignments weren't appearing as bindings. I've tracked it down to an issue here, but it's only an issue when using the babel/babylon parser.

e.g. with this code:

const { a, b } = something;

ast-types correctly reports both a and b as bindings when using the esprima parser, but not when using the babel parser.

I've added a unit test to cover this case, and I've also found a fix for it, which seems to be that the scope code is only looking for Property types when walking across properties, but it should also consider ObjectProperty. I'm not 100% sure that this is the correct fix as I'm new to this codebase...

I'll raise an accompanying PR.

The seemingly related PR is merged, so I assume this issue should be resolved now?