Babel 中文文档
  • 印记中文
  • 文档
  • 配置
  • 试用
  • 视频
  • 博客
  • 赞助
  • 团队
  • GitHub
Edit

@babel/plugin-transform-regenerator

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

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

With a configuration file (Recommended)

Without options:

{
  "plugins": ["@babel/plugin-transform-regenerator"]
}

With options:

namedefault value
asyncGeneratorstrue
generatorstrue
asynctrue
{
  "plugins": [
    [
      "@babel/plugin-transform-regenerator",
      {
        "asyncGenerators": false,
        "generators": false,
        "async": false
      }
    ]
  ]
}

Via CLI

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

Via Node API

require("@babel/core").transformSync("code", {
  plugins: ["@babel/plugin-transform-regenerator"],
});
  • Example
  • Installation
  • Usage
    • With a configuration file (Recommended)
    • Via CLI
    • Via Node API
Babel 中文文档
文档
学习 ES2015
社区
视频用户Stack OverflowSlack 频道Twitter
更多
博客GitHub 组织GitHub 仓库Website 仓库旧版网址 6.x旧版网址 5.x