-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Transform async functions with regenerator #332
Conversation
Remove `transform-async-to-generator`, which to my understanding is meant to be used in environments that support generators natively. Because we're compiling generators to ES5 anyway, we can simply use `regenerator` to transform async functions too, which results in slightly simpler output and only uses the regenerator runtime instead regenerator runtime + _asyncToGenerator Babel helper.
require.resolve('babel-plugin-transform-class-properties'), | ||
require.resolve('babel-plugin-transform-object-rest-spread'), | ||
require.resolve('babel-plugin-transform-regenerator'), |
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.
Isn’t -regenerator
already a part of es2015
?
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.
It is, but in preset-es2015
it's passed different options, { async: false, asyncGenerators: false }
. The default options (used here) are:
{
asyncGenerators: true,
generators: true,
async: true
}
(Note that asyncGenerators
is true
by default, but since we don't enable the async generator syntax plugin, this doesn't matter.)
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.
Ah, so that’s how it works.
@@ -33,11 +33,12 @@ | |||
"babel-eslint": "6.1.2", | |||
"babel-jest": "14.1.0", | |||
"babel-loader": "6.2.4", | |||
"babel-plugin-syntax-async-functions": "^6.8.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.
Please remove carets from deps
Thanks. |
Remove
transform-async-to-generator
, which to my understanding is meantto be used in environments that support generators natively.
Because we're compiling generators to ES5 anyway, we can simply use
regenerator
to transform async functions too, which results inslightly simpler output and only uses the regenerator runtime instead
regenerator runtime + _asyncToGenerator Babel helper.
Tested with the example code from #327.
Output (without minification) before:
After the change: