1. babel-plugin-transform-regenerator
Explode async and generator functions into a state machine.
babel-plugin-transform-regenerator
Package: babel-plugin-transform-regenerator
Created by: babel
Last modified: Sat, 17 Jun 2023 23:09:13 GMT
Version: 6.26.0
License: MIT
Downloads: 5,953,329
Repository: https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-regenerator

Install

npm install babel-plugin-transform-regenerator
yarn add babel-plugin-transform-regenerator

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:

name default value
asyncGenerators true
generators true
async true
 {
  "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"]
});

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin