benjamn / benjamn/ast-types

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

Open
#360 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
1.2k
Forks
194
Avg merge
22h 43m
Merged PRs (30d)
10

Description

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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.