Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
@babel/plugin-transform-regenerator
Advanced tools
Explode async and generator functions into a state machine.
The @babel/plugin-transform-regenerator package is a Babel plugin that enables the transformation of generator functions and async functions into ES5-compatible JavaScript code using the regenerator runtime. It allows developers to use these modern features in environments that do not natively support them.
Transformation of generator functions
This plugin transforms generator functions into ES5 code by converting the generator syntax into a state machine that is compatible with older JavaScript engines.
function* gen() { yield 1; yield 2; yield 3; }
Transformation of async functions
It also transforms async functions into generator functions and then applies the generator function transformation to ensure compatibility with environments that do not support async/await syntax.
async function foo() { await someAsyncFunction(); }
The regenerator-runtime package provides the runtime needed to support the generator functions in environments that do not natively support them. It is often used in conjunction with @babel/plugin-transform-regenerator, which handles the syntax transformation.
This package is similar to @babel/plugin-transform-regenerator in that it transforms async functions into generator functions. However, it focuses solely on async functions and does not handle generator functions.
fast-async is a Babel plugin that transforms async/await functions into ES5-compatible code using Promises instead of generators. It provides an alternative approach to handling async functions and can be faster than regenerator-based transformations.
Transform async/generator functions with regenerator
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);
}
npm install --save-dev @babel/plugin-transform-regenerator
.babelrc
(Recommended)Without options:
{
"plugins": ["@babel/plugin-transform-regenerator"]
}
With options:
name | default value |
---|---|
asyncGenerators | true |
generators | true |
async | true |
{
"plugins": [
["@babel/plugin-transform-regenerator", {
"asyncGenerators": false,
"generators": false,
"async": false
}]
]
}
babel --plugins @babel/plugin-transform-regenerator script.js
require("@babel/core").transform("code", {
plugins: ["@babel/plugin-transform-regenerator"]
});
FAQs
Explode async and generator functions into a state machine.
The npm package @babel/plugin-transform-regenerator receives a total of 23,429,906 weekly downloads. As such, @babel/plugin-transform-regenerator popularity was classified as popular.
We found that @babel/plugin-transform-regenerator demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.