Navigation Menu

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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move the generator body to a gen IIFE when compiling its params #15081

Merged
merged 1 commit into from Oct 28, 2022

Conversation

nicolo-ribaudo
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo commented Oct 26, 2022

Q                       A
Fixed Issues? Fixes #15012
Patch: Bug Fix? Yes
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

The problem is that the generator body starts paused, but params should run before the pause.

@nicolo-ribaudo nicolo-ribaudo added PR: Bug Fix 🐛 A type of pull request used for our changelog categories pkg: preset-env labels Oct 26, 2022
@@ -9,20 +9,6 @@ const es5 = {
"transform-reserved-words": "Miscellaneous / Unreserved words",
};

// https://github.com/babel/babel/issues/11278
// transform-parameters should run before object-rest-spread
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The relevant test (packages/babel-preset-env/test/fixtures/plugins-integration/issue-11278/input.mjs) still passes.

@babel-bot
Copy link
Collaborator

babel-bot commented Oct 26, 2022

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/53262/

JLHwung
JLHwung previously approved these changes Oct 26, 2022
@nicolo-ribaudo
Copy link
Member Author

The CI failure is related: regenerator doesn't support desteuctuting in params, so that needs to be transformed before. I'll try an alternative approach.

@nicolo-ribaudo nicolo-ribaudo changed the title Transform parameters after transforming generators Move the generator body to an IIGE (G = generator) when compiling its parameters Oct 27, 2022
@@ -1,6 +1,6 @@
{
"name": "@babel/compat-data",
"version": "7.19.4",
"version": "7.20.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change should be reverted.

@nicolo-ribaudo nicolo-ribaudo changed the title Move the generator body to an IIGE (G = generator) when compiling its parameters Move the generator body to a gen IIFE when compiling its params Oct 27, 2022
@nicolo-ribaudo
Copy link
Member Author

nicolo-ribaudo commented Oct 27, 2022

The PR now transforms

function* g(a = 1) {
  return a;
}

to

function g() {
  let a = ...;
  return function* () {
    return a;
  }();
}

so that the parameters are executed before pausing.

@@ -0,0 +1,12 @@
function fn(a, _ref) {
Copy link
Contributor

@JLHwung JLHwung Oct 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the wrapper be a generator? So that fn.constructor still work after transpiled.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because a generator would start paused. yield* fn() already works, because fn() returns an instance of GeneratorFunction, which is iterable. fn.constructor is not GeneratorFunction anymore, but there are already many cases where the prototype of a function is not correct and this is just another one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another reason will be that yield expression is not allowed in formal parameters.

@nicolo-ribaudo nicolo-ribaudo merged commit 082caa1 into babel:main Oct 28, 2022
@nicolo-ribaudo nicolo-ribaudo deleted the fix-15012 branch October 28, 2022 17:35
@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 Jan 28, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Bug Fix 🐛 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Generator with array pattern parameter
4 participants