@babel/plugin-transform-async-to-generator
In
var _asyncToGenerator = function (fn) {
...
};
var foo = _asyncToGenerator(function* () {
});
Out with options
var Bluebird = require("bluebird");
var foo = Bluebird.coroutine(function*() {
});
Without options:
{
"plugins": ["@babel/plugin-transform-async-to-generator"]
}
{
"plugins": [
[
"@babel/plugin-transform-async-to-generator",
"module": "bluebird",
}
]
]
}
require("@babel/core").transformSync("code", {
plugins: ["@babel/plugin-transform-async-to-generator"],
});
When using await
with non-promise values, Bluebird will throw “Error: A value was yielded that could not be treated as a promise”. Since Babel cannot automatically handle this runtime error, you should manually transform it to a promise.
async function foo() {
- await 42;
}