Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including babel-plugin-transform-regenerator with all npm packages installed. Try it out:

var babelPluginTransformRegenerator = require("babel-plugin-transform-regenerator")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

babel-plugin-transform-regenerator v6.26.0

Explode async and generator functions into a state machine.

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

Via .babelrc (Recommended)

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"]
});
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free