@babel/plugin-transform-regenerator

Example

In

  1. function* a() {
  2. yield 1;
  3. }

Out

  1. var _marked = [a].map(regeneratorRuntime.mark);
  2. function a() {
  3. return regeneratorRuntime.wrap(function a$(_context) {
  4. while (1) {
  5. switch (_context.prev = _context.next) {
  6. case 0:
  7. _context.next = 2;
  8. return 1;
  9. case 2:
  10. case "end":
  11. return _context.stop();
  12. }
  13. }
  14. }, _marked[0], this);
  15. }

Installation

  1. npm install --save-dev @babel/plugin-transform-regenerator

Usage

Without options:

  1. {
  2. "plugins": ["@babel/plugin-transform-regenerator"]
  3. }

With options:

namedefault value
asyncGeneratorstrue
generatorstrue
asynctrue
  1. {
  2. "plugins": [
  3. ["@babel/plugin-transform-regenerator", {
  4. "asyncGenerators": false,
  5. "generators": false,
  6. "async": false
  7. }]
  8. ]
  9. }

Via CLI

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

Via Node API

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