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-async-to-generator incorrectly captures outer variable in a loop #15978

Closed
1 task
jjonescz opened this issue Sep 16, 2023 · 1 comment 路 Fixed by #15979
Closed
1 task
Assignees
Labels
i: bug i: regression outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@jjonescz
Copy link
Contributor

jjonescz commented Sep 16, 2023

馃捇

  • Would you like to work on a fix?

How are you using Babel?

Other (Next.js, Gatsby, vue-cli, ...)

Input code

(async function () {
  let items = [1, 2, 3, 4];
  for (const item of items) {
    await f(async (x) => {
      console.log(item);
    });
  }
})();

async function f(lambda) {
  await lambda();
}

Configuration file name

No response

Configuration

{
  "plugins": [
    "@babel/plugin-transform-async-to-generator"
  ]
}

Current and expected behavior

With @babel/helper-remap-async-to-generator@7.22.9 the output is 1 2 3 4 (correct, expected).
With @babel/helper-remap-async-to-generator@7.22.17 the output is 1 1 1 1 (incorrect, current).

Also if the inner lambda has no arguments (the x argument is removed), the output changes to the correct 1 2 3 4 in current version.

I think this PR caused the regression: #15922

Environment

  • Babel version: 7.22.19
  • Node: 18.10.0
  • npm version: 9.7.2
  • OS: Windows 11
  • Monorepo: no

Possible solution

No response

Additional context

No response

@babel-bot
Copy link
Collaborator

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

@liuxingbaoyu liuxingbaoyu self-assigned this Sep 16, 2023
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Dec 17, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: bug i: regression outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants