babel-plugin-transform-async-to-module-method
Version:
Turn async functions into a module method
71 lines (50 loc) • 916 B
Markdown
> Turn async functions into a Bluebird coroutine
**In**
```javascript
async function foo() {
await bar();
}
```
**Out**
```javascript
var Bluebird = require("bluebird");
var foo = Bluebird.coroutine(function* () {
yield bar();
});
```
```sh
npm install --save-dev babel-plugin-transform-async-to-module-method
```
**.babelrc**
Without options:
```json
{
"plugins": ["transform-async-to-module-method"]
}
```
With options:
```json
{
"plugins": [
["transform-async-to-module-method", {
"module": "bluebird",
"method": "coroutine"
}]
]
}
```
```sh
babel --plugins transform-async-to-module-method script.js
```
```javascript
require("babel-core").transform("code", {
plugins: ["transform-async-to-module-method"]
});
```