Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shellscape/babel-plugin-async-to-plain-generator
Transform async functions into non-wrapped ES2015 generators
https://github.com/shellscape/babel-plugin-async-to-plain-generator
async babel babel-plugin babeljs generator module nodejs npm transformations
Last synced: 21 days ago
JSON representation
Transform async functions into non-wrapped ES2015 generators
- Host: GitHub
- URL: https://github.com/shellscape/babel-plugin-async-to-plain-generator
- Owner: shellscape
- License: mit
- Created: 2016-06-12T13:21:09.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-05-04T00:43:08.000Z (over 4 years ago)
- Last Synced: 2024-10-12T23:04:22.613Z (25 days ago)
- Topics: async, babel, babel-plugin, babeljs, generator, module, nodejs, npm, transformations
- Language: JavaScript
- Size: 10.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# babel-plugin-async-to-plain-generator
Babel plugin to transform async functions into plain, unwrapped generator functions.
##
:rocket: Are you ready to tackle ES6 and hone your JavaScript Skills? :rocket:
Check out these outstanding ES6 courses by @wesbos
---While working with [KoaJS v1](https://github.com/koajs/koa) we found that the resulting output from [transform-async-to-generator](https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-async-to-generator) was incompatible with Koa's requirements - that `app.use` must be passed a generator function.
This plugin was created by modifying the transform-async-to-generator plugin. While that plugin works well in most situations, it curiously (and extraneously?) wraps async functions and results in a generator function wrapped in a regular function of the same name. This plugin was created so that babel would produce plain old vanilla generator functions from async function declarations.
## Transformations:
```js
// in[].forEach(async (a) => {
await a;
});async function foo (bar) {
await bar;
};// out
[].forEach(function* (a) {
yield a;
});function* foo (bar) {
yield bar;
}
```## Installation
```sh
$ npm install babel-plugin-async-to-plain-generator
```## Usage
### Via `.babelrc` (Recommended)
**.babelrc**
```json
{
"plugins": ["async-to-plain-generator"]
}
```### Via CLI
```sh
$ babel --plugins async-to-plain-generator script.js
```### Via Node API
```javascript
require("babel-core").transform("code", {
plugins: ["async-to-plain-generator"]
});
```