Socket
Socket
Sign inDemoInstall

babel-plugin-transform-regenerator

Package Overview
Dependencies
9
Maintainers
5
Versions
53
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-transform-regenerator

Explode async and generator functions into a state machine.


Version published
Maintainers
5
Weekly downloads
1,353,395
decreased by-10.39%

Weekly downloads

Package description

What is babel-plugin-transform-regenerator?

The babel-plugin-transform-regenerator npm package is used to transform ES2015+ generator functions into ES5 code. This is particularly useful for writing asynchronous code in a synchronous manner using the `yield` keyword, and for ensuring compatibility with older browsers or environments that do not support generator functions natively.

What are babel-plugin-transform-regenerator's main functionalities?

Transformation of generator functions

This feature allows developers to write generator functions using the `function*` syntax and `yield` keyword. The babel-plugin-transform-regenerator will then transform this into ES5 compatible code, enabling the use of generator functions in environments that do not support them natively.

function* gen() { yield 'Hello'; yield 'World'; }

Async/Await support

Although primarily focused on generator functions, babel-plugin-transform-regenerator also plays a crucial role in enabling the use of async/await syntax in projects that use Babel for transpilation. It transforms async functions into generator functions and then into ES5 code.

async function foo() { await bar(); }

Other packages similar to babel-plugin-transform-regenerator

Readme

Source

babel-plugin-transform-regenerator

Transform async/generator functions with regenerator

Example

In

function* a() {
  yield 1;
}

Out

var _marked = [a].map(regeneratorRuntime.mark);

function a() {
  return regeneratorRuntime.wrap(function a$(_context) {
    while (1) {
      switch (_context.prev = _context.next) {
        case 0:
          _context.next = 2;
          return 1;

        case 2:
        case "end":
          return _context.stop();
      }
    }
  }, _marked[0], this);
}

Installation

npm install --save-dev babel-plugin-transform-regenerator

Usage

Without options:

{
  "plugins": ["transform-regenerator"]
}

With options:

namedefault value
asyncGeneratorstrue
generatorstrue
asynctrue
{
  "plugins": [
    ["transform-regenerator", {
      "asyncGenerators": false,
      "generators": false,
      "async": false
    }]
  ]
}

Via CLI

babel --plugins transform-regenerator script.js

Via Node API

require("babel-core").transform("code", {
  plugins: ["transform-regenerator"]
});

FAQs

Last updated on 16 Aug 2017

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