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]: Async generators with default parameters compile to invalid code #15145

Closed
1 task
codebutler opened this issue Nov 5, 2022 · 1 comment 路 Fixed by #15146
Closed
1 task

[Bug]: Async generators with default parameters compile to invalid code #15145

codebutler opened this issue Nov 5, 2022 · 1 comment 路 Fixed by #15146
Assignees
Labels
i: bug i: regression outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@codebutler
Copy link

codebutler commented Nov 5, 2022

馃捇

  • Would you like to work on a fix?

How are you using Babel?

babel-loader (webpack)

Input code

export async function * foo (p = 1) {
  yield "hello";
}
for await (const x of foo()) {
  console.log(x);
}

Configuration file name

No response

Configuration

No response

Current and expected behavior

With babel v7.17.12, the above code is compiled to:

async function* foo(p) {
  if (p === void 0) {
    p = 1;
  }

  yield "hello";
}

for await (const x of foo()) {
  console.log(x);
}

When run with node, this prints hello as expected.

With v7.20.2, the compiled code is:

async function foo(p) {
  if (p === void 0) {
    p = 1;
  }
  return async function* () {
    yield "hello";
  }();
}
for await (const x of foo()) {
  console.log(x);
}

This throws an exception:

Uncaught TypeError: foo(...) is not a function or its return value is not async iterable

Environment

Turn "Bug Fixes" OFF in REPL to reproduce.

Possible solution

Possible regression caused by #15081 ?

Additional context

No response

@babel-bot
Copy link
Collaborator

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

@nicolo-ribaudo nicolo-ribaudo self-assigned this Nov 5, 2022
@nicolo-ribaudo nicolo-ribaudo changed the title [Bug]: Generators with default parameters compile to invalid code [Bug]: Async generators with default parameters compile to invalid code Nov 5, 2022
@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 Feb 7, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 7, 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.

4 participants