@babel/plugin-transform-regenerator
信息
This plugin is included in @babel/preset-env
Example
In
JavaScript
function* a() {
yield 1;
}
Out
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
npm install --save-dev @babel/plugin-transform-regenerator
yarn add --dev @babel/plugin-transform-regenerator
pnpm add --save-dev @babel/plugin-transform-regenerator
Usage
With a configuration file (Recommended)
Without options:
babel.config.json
{
"plugins": ["@babel/plugin-transform-regenerator"]
}
With options:
name | default value |
---|---|
asyncGenerators | true |
generators | true |
async | true |
babel.config.json
{
"plugins": [
[
"@babel/plugin-transform-regenerator",
{
"asyncGenerators": false,
"generators": false,
"async": false
}
]
]
}
Via CLI
Shell
babel --plugins @babel/plugin-transform-regenerator script.js
Via Node API
JavaScript
require("@babel/core").transformSync("code", {
plugins: ["@babel/plugin-transform-regenerator"],
});