Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: plugin-transform-regenerator together with async-to-generator incorrectly shadow function name in local scope #16334

Open
1 task
larabr opened this issue Mar 8, 2024 · 2 comments

Comments

@larabr
Copy link

larabr commented Mar 8, 2024

馃捇

  • Would you like to work on a fix?

How are you using Babel?

@babel/cli

Input code

I have a REPL of the large minified build where we encountered the bug. Unfortunately, while I could track down the incriminated plugins, I haven't managed to single out a smaller portion of code where the bug could be reproduced.

REPL

Configuration file name

No response

Configuration

npx babel --plugins=@babel/plugin-transform-destructuring,@babel/plugin-transform-for-of,@babel/plugin-transform-spread,@babel/plugin-transform-classes,@babel/plugin-transform-regenerator, @babel/plugin-transform-regenerator, @babel/plugin-transform-async-to-generator

Current and expected behavior

Current (line references based on the REPL): the class n declared at L7 and instantiated in the function Rr at L3297 of the original code is shadowed by a var declaration in the transformed code (at L5599). As a result, the instantiation fails due to n being undefined.

Expected: the var declaration uses a different name.

Environment

Babel: 7.23.9 (@babel/core 7.23.9)
OS: macOS 12.7.2
Node: 20.11.0
Yarn: 4.1.0 
npm: 8.15.0

Possible solution

Not really a solution, but excluding either @babel/plugin-transform-async-to-generator or @babel/plugin-transform-regenerator fixes the issue.

Additional context

I noticed that dropping the code after the affected function (Rr) results in a correct transformation, hence something in the rest of the code must be playing a role too.

@babel-bot
Copy link
Collaborator

Hey @larabr! 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.

@OctopusRoe
Copy link

I have encountered a similar issue as well. Whenever I use destructuring assignment within an asynchronous function, like const {a, b} = await request(), I encounter an error related to an undefined type. In my case, I was able to successfully build my project by excluding the @babel/plugin-transform-regenerator plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants