-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
Conversation
@@ -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 |
There was a problem hiding this comment.
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.
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/53262/ |
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. |
a19c301
to
d575f2d
Compare
@@ -1,6 +1,6 @@ | |||
{ | |||
"name": "@babel/compat-data", | |||
"version": "7.19.4", | |||
"version": "7.20.0", |
There was a problem hiding this comment.
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.
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. |
d575f2d
to
b3bcc18
Compare
@@ -0,0 +1,12 @@ | |||
function fn(a, _ref) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
The problem is that the generator body starts paused, but params should run before the pause.