benjamn / ast-types

Esprima-compatible implementation of the Mozilla JS Parser API
MIT License
1.14k stars 198 forks source link

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

Open RoystonS opened 5 years ago

RoystonS commented 5 years ago

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.

0xdevalias commented 11 months ago

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