6.22.0 • Published 2 years ago

@nkduy/babel-plugin-transform-regenerator v6.22.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

@nkduy/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);
}

Try in REPL

Installation

npm install --save-dev @nkduy/babel-plugin-transform-regenerator

Usage

Via .babelrc (Recommended)

.babelrc

// without options
{
  "plugins": ["transform-regenerator"]
}
// with options
{
  "plugins": [
    ["transform-regenerator", {
      asyncGenerators: false, // true by default
      generators: false, // true by default
      async: false // true by default
    }]
  ]
}

Via CLI

babel --plugins transform-regenerator script.js

Via Node API

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