This plugin allows Babel to transform async functions into a Bluebird coroutine.
输入
async function foo() {
await bar();
}
输出
var Bluebird = require("bluebird");
var foo = Bluebird.coroutine(function* () {
yield bar();
});
npm install --save-dev babel-plugin-transform-async-to-module-method
.babelrc
(推荐).babelrc
未包含选项:
{
"plugins": ["transform-async-to-module-method"]
}
包含选项:
{
"plugins": [
["transform-async-to-module-method", {
"module": "bluebird",
"method": "coroutine"
}]
]
}
babel --plugins transform-async-to-module-method script.js
require("babel-core").transform("code", {
plugins: ["transform-async-to-module-method"]
});