
Security News
New CVE Forecasting Tool Predicts 47,000 Disclosures in 2025
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.
pregenerator
Advanced tools
JS source transforms for generators (and more) using a lightweight babel-types replacement
pregenerator
is a lighter-weight, more narrowly focused package that aims to accomplish some of the goals of regenerator, while remaining small enough that it won’t (completely) break a website’s performance budget if run in the browser. It may not be able to boast as impressive size reductions as preact has compared to react, but it is a quarter of the size of regenerator (minified and gzipped), while supporting most of the same features.
This library does not aim to support the full set of ES6 to ES5 transforms. Specifically, it supports:
let
and const
) to var
It intentionally does not (and will not) support transforms for:
This function accepts a javascript string and returns ES5-compatible
javascript. If generators are involved, it assumes regeneratorRuntime
is available in the global scope.
// input
import { compile } from 'pregenerator';
console.log(compile('function *gen() { yield 1; }'));
// output
var _marked = /* #__PURE__ */ regeneratorRuntime.mark(gen);
function gen() {
return regeneratorRuntime.wrap(function gen$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return 1;
case 2:
case "end":
return _context.stop();
}
}, _marked);
}
Also importable from @pregenerator/transform
; performs an AST transform
(conforming to the ESTree Spec) to
ES5-compatible AST.
import transform from '@pregenerator/transform';
// input: AST for `let {x} = y`
var ast = transform({
type: 'File',
program: {
type: 'Program',
body: [{
type: 'VariableDeclaration',
kind: 'let',
declarations: [{
type: 'VariableDeclarator',
id: {
type: 'ObjectPattern',
properties: [
{
type: 'ObjectProperty',
key: {type: 'Identifier', name: 'x'},
value: {type: 'Identifier', name: 'x'},
shorthand: true
}
]
},
init: {type: 'Identifier', name: 'y'}
}]
}]
}
});
console.log(ast);
// result: AST for `var _y = y; var x = _y.x`
{
type: 'File',
program: {
type: 'Program',
body: [{
type: 'VariableDeclaration',
kind: 'var',
declarations: [{
type: 'VariableDeclarator',
id: {type: 'Identifier', name: '_y'},
init: {type: 'Identifier', name: 'y'}
}]
}, {
type: 'VariableDeclaration',
kind: 'var',
declarations: [{
type: 'VariableDeclarator',
id: {type: 'Identifier', name: 'x'},
init: {
type: 'MemberExpression',
object: {type: 'Identifier', name: '_y'},
property: {type: 'Identifier', name: 'x'},
computed: false
}
}]
}]
}
}
Stringifies AST (using astring), papering over some of the differences between the ESTree implementation of babylon, acorn, and astring.
@pregenerator/ast-types
TK
FAQs
JS source transforms for generators (and more) using a lightweight babel-types replacement
The npm package pregenerator receives a total of 8 weekly downloads. As such, pregenerator popularity was classified as not popular.
We found that pregenerator demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 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.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.