Package Exports
- @babel/plugin-transform-async-to-generator
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@babel/plugin-transform-async-to-generator) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@babel/plugin-transform-async-to-generator
Turn async functions into ES2015 generators
In Babel 7,
transform-async-to-module-method
was merged into this plugin
Example
In
async function foo() {
await bar();
}
Out
var _asyncToGenerator = function (fn) {
...
};
var foo = _asyncToGenerator(function* () {
yield bar();
});
Out with options
Turn async functions into a Bluebird coroutine
var Bluebird = require("bluebird");
var foo = Bluebird.coroutine(function* () {
yield bar();
});
Installation
npm install --save-dev @babel/plugin-transform-async-to-generator
Usage
Via .babelrc
(Recommended)
.babelrc
Without options:
{
"plugins": ["@babel/transform-async-to-generator"]
}
With options:
{
"plugins": [
["@babel/transform-async-to-generator", {
"module": "bluebird",
"method": "coroutine"
}]
]
}
Via CLI
babel --plugins @babel/transform-async-to-generator script.js
Via Node API
require("@babel/core").transform("code", {
plugins: ["@babel/transform-async-to-generator"]
});