New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-async-to-plain-generator

Package Overview
Dependencies
Maintainers
2
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

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

0.1.2
latest
Source
npm
Version published
Weekly downloads
1
Maintainers
2
Weekly downloads
 
Created
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

Package last updated on 25 Sep 2016

Did you know?

Socket

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