npm’s 2019 JavaScript ecosystem survey analysis is now available!Get your copy here »

babel-plugin-async-to-plain-generator

0.1.2 • Public • Published

babel-plugin-async-to-plain-generator

While working with KoaJS v1 we found that the resulting output from 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:

// in
 
[].forEach(async (a) => {
  await a;
});
 
async function foo (bar) {
  await bar;
};
 
// out
 
[].forEach(function* (a) {
  yield a;
});
 
function* foo (bar) {
  yield bar;
}

Installation

$ npm install babel-plugin-async-to-plain-generator

Usage

Via .babelrc (Recommended)

.babelrc

{
  "plugins": ["async-to-plain-generator"]
}

Via CLI

$ babel --plugins async-to-plain-generator script.js

Via Node API

require("babel-core").transform("code", {
  plugins: ["async-to-plain-generator"]
});

Keywords

none

Install

npm i babel-plugin-async-to-plain-generator

DownloadsWeekly Downloads

4

Version

0.1.2

License

MIT

Last publish

Collaborators

  • avatar
  • avatar