@babel/plugin-transform-regenerator

NOTE: This plugin is included in @babel/preset-env

Example

In

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

Out

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

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. [
  4. "@babel/plugin-transform-regenerator",
  5. {
  6. "asyncGenerators": false,
  7. "generators": false,
  8. "async": false
  9. }
  10. ]
  11. ]
  12. }

Via CLI

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

Via Node API

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