@babel/plugin-transform-regenerator
info
这个插件包含在 @babel/preset-env 中
示例
🌐 Example
在
JavaScript
function* a() {
yield 1;
}
出
JavaScript
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
- Yarn
- pnpm
- Bun
npm install --save-dev @babel/plugin-transform-regenerator
yarn add --dev @babel/plugin-transform-regenerator
pnpm add --save-dev @babel/plugin-transform-regenerator
bun add --dev @babel/plugin-transform-regenerator
用法
🌐 Usage
使用配置文件(推荐)
🌐 With a configuration file (Recommended)
没有选项:
🌐 Without options:
babel.config.json
{
"plugins": ["@babel/plugin-transform-regenerator"]
}
有选项:
🌐 With options:
| 名称 | 默认值 |
|---|---|
| asyncGenerators | true |
| generators | true |
| async | true |
babel.config.json
{
"plugins": [
[
"@babel/plugin-transform-regenerator",
{
"asyncGenerators": false,
"generators": false,
"async": false
}
]
]
}
通过 CLI
🌐 Via CLI
Shell
babel --plugins @babel/plugin-transform-regenerator script.js
通过 Node API
🌐 Via Node API
JavaScript
require("@babel/core").transformSync("code", {
plugins: ["@babel/plugin-transform-regenerator"],
});