New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Variables used in computed method key are not scoped correctly #12790
Comments
Hey @overlookmotel! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly. If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite." |
Yes I can confirm, I'm seeing this in multiple projects I work on. Babel no longer works on code like described in description of this issue. |
@char0n So a previous version of Babel used to work correctly? |
@nicolo-ribaudo, yep @babel/preset-env@7.12.11 works like a charm. Anything with higher semver breaks. |
@char0n I think your bug is a different (but closely related) one, because the code in the OP also shows the bug with Babel 7.10.0. EDIT: Probably some unrelated change made this exact bug appear when compiling your code. |
@overlookmotel It seems that there are two different bugs in Babel:
We can probably fix (1) by adding a list of "nodes whose keys should refer to the grandparent scope", and start from
We can fix (2) by modifying
skipAllButComputedKey to continue visiting the method key.
|
@nicolo-ribaudo Thanks for the diagnosis and hints. I'll make a stab at a fix in next couple of weeks. |
I've submitted PR #12812 to fix bug (1). It was more complicated than I expected, so I'm not sure now when I'll get time to attack bug (2). |
Fixed by #12812, now merged. |
Thanks @overlookmotel, we completely forgot to close this 😅 |
Bug Report
Current behavior
Where an object/class method has a computed key containing a variable, and the method includes a variable with same name in its body or parameters, the scope of the variable in method key is incorrectly identified.
Babel determines the scope of the var in the method key to be inside the method's body, not outside as it actually is.
Input Code
https://codesandbox.io/s/babel-issue-12790-b9y6b
Input code:
Plugin:
Expected behavior
Expected output to be:
but instead get:
Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)
None.
Environment
Additional context
I am very happy to work on a fix. But I'm unfamiliar with how/where Babel calculates scope of identifiers, so if someone could point me in the right direction, that would be a big help.
The text was updated successfully, but these errors were encountered: