Socket
Socket
Sign inDemoInstall

@babel/plugin-transform-regenerator

Package Overview
Dependencies
6
Maintainers
1
Versions
83
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
1
Created

Package description

What is @babel/plugin-transform-regenerator?

The @babel/plugin-transform-regenerator package is a Babel plugin that enables the transformation of generator functions and async functions into ES5-compatible JavaScript code using the regenerator runtime. It allows developers to use these modern features in environments that do not natively support them.

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

Transformation of generator functions

This plugin transforms generator functions into ES5 code by converting the generator syntax into a state machine that is compatible with older JavaScript engines.

function* gen() { yield 1; yield 2; yield 3; }

Transformation of async functions

It also transforms async functions into generator functions and then applies the generator function transformation to ensure compatibility with environments that do not support async/await syntax.

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

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": ["@babel/transform-regenerator"]
}

With options:

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

Via CLI

babel --plugins @babel/transform-regenerator script.js

Via Node API

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

FAQs

Last updated on 30 Oct 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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc