Socket
Socket
Sign inDemoInstall

babel-plugin-async-to-plain-generator

Package Overview
Dependencies
28
Maintainers
2
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    babel-plugin-async-to-plain-generator

Transform async functions into non-wrapped ES2015 generators


Version published
Weekly downloads
5
increased by66.67%
Maintainers
2
Install size
4.36 MB
Created
Weekly downloads
 

Readme

Source

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

.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"]
});

FAQs

Last updated on 25 Sep 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc