Socket
Socket
Sign inDemoInstall

regenerator-transform

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

regenerator-transform - npm Package Compare versions

Comparing version 0.13.0 to 0.13.1

107

lib/emit.js

@@ -39,6 +39,7 @@ "use strict";

this.marked = [true]; // The last location will be marked when this.getDispatchLoop is
this.marked = [true];
this.insertedLocs = new Set(); // The last location will be marked when this.getDispatchLoop is
// called.
this.finalLoc = loc(); // A list of all leap.TryEntry statements emitted.
this.finalLoc = this.loc(); // A list of all leap.TryEntry statements emitted.

@@ -59,5 +60,15 @@ this.tryEntries = []; // Each time we evaluate the body of a loop, we tell this.leapManager

function loc() {
return util.getTypes().numericLiteral(-1);
} // Sets the exact value of the given location to the offset of the next
Ep.loc = function () {
var l = util.getTypes().numericLiteral(-1);
this.insertedLocs.add(l);
return l;
};
Ep.getInsertedLocs = function () {
return this.insertedLocs;
};
Ep.getContextId = function () {
return util.getTypes().clone(this.contextId);
}; // Sets the exact value of the given location to the offset of the next
// Statement emitted.

@@ -103,3 +114,3 @@

var t = util.getTypes();
return t.expressionStatement(t.assignmentExpression("=", lhs, rhs));
return t.expressionStatement(t.assignmentExpression("=", t.cloneDeep(lhs), rhs));
}; // Convenience function for generating expressions like context.next,

@@ -111,3 +122,3 @@ // context.sent, and context.rval.

var t = util.getTypes();
return t.memberExpression(this.contextId, computed ? t.stringLiteral(name) : t.identifier(name), !!computed);
return t.memberExpression(this.getContextId(), computed ? t.stringLiteral(name) : t.identifier(name), !!computed);
}; // Shorthand for setting context.rval and jumping to `context.stop()`.

@@ -132,3 +143,3 @@

t.assertLiteral(tryLoc);
var catchCall = t.callExpression(this.contextProperty("catch", true), [tryLoc]);
var catchCall = t.callExpression(this.contextProperty("catch", true), [t.clone(tryLoc)]);

@@ -187,3 +198,3 @@ if (assignee) {

/*Anonymous*/
, [this.contextId], t.blockStatement([this.getDispatchLoop()]), false, // Not a generator anymore!
, [this.getContextId()], t.blockStatement([this.getDispatchLoop()]), false, // Not a generator anymore!
false // Nor an expression.

@@ -259,3 +270,5 @@ );

return t.arrayExpression(locs);
return t.arrayExpression(locs.map(function (loc) {
return loc && t.clone(loc);
}));
}));

@@ -338,3 +351,3 @@ }; // All side effects must be realized in order.

case "LabeledStatement":
after = loc(); // Did you know you can break from any labeled block statement or
after = this.loc(); // Did you know you can break from any labeled block statement or
// control structure? Well, you can! Note: when a labeled loop is

@@ -367,4 +380,4 @@ // encountered, the leap.LabeledEntry created here will immediately

case "WhileStatement":
before = loc();
after = loc();
before = this.loc();
after = this.loc();
self.mark(before);

@@ -380,5 +393,5 @@ self.jumpIfNot(self.explodeExpression(path.get("test")), after);

case "DoWhileStatement":
var first = loc();
var test = loc();
after = loc();
var first = this.loc();
var test = this.loc();
after = this.loc();
self.mark(first);

@@ -394,5 +407,5 @@ self.leapManager.withEntry(new leap.LoopEntry(after, test, labelId), function () {

case "ForStatement":
head = loc();
var update = loc();
after = loc();
head = this.loc();
var update = this.loc();
after = this.loc();

@@ -431,4 +444,4 @@ if (stmt.init) {

case "ForInStatement":
head = loc();
after = loc();
head = this.loc();
after = this.loc();
var keyIterNextFn = self.makeTempVar();

@@ -438,4 +451,4 @@ self.emitAssign(keyIterNextFn, t.callExpression(util.runtimeProperty("keys"), [self.explodeExpression(path.get("right"))]));

var keyInfoTmpVar = self.makeTempVar();
self.jumpIf(t.memberExpression(t.assignmentExpression("=", keyInfoTmpVar, t.callExpression(keyIterNextFn, [])), t.identifier("done"), false), after);
self.emitAssign(stmt.left, t.memberExpression(keyInfoTmpVar, t.identifier("value"), false));
self.jumpIf(t.memberExpression(t.assignmentExpression("=", keyInfoTmpVar, t.callExpression(t.cloneDeep(keyIterNextFn), [])), t.identifier("done"), false), after);
self.emitAssign(stmt.left, t.memberExpression(t.cloneDeep(keyInfoTmpVar), t.identifier("value"), false));
self.leapManager.withEntry(new leap.LoopEntry(after, head, labelId), function () {

@@ -466,4 +479,4 @@ self.explodeStatement(path.get("body"));

var disc = self.emitAssign(self.makeTempVar(), self.explodeExpression(path.get("discriminant")));
after = loc();
var defaultLoc = loc();
after = this.loc();
var defaultLoc = this.loc();
var condition = defaultLoc;

@@ -479,3 +492,3 @@ var caseLocs = []; // If there are no cases, .cases might be undefined.

if (c.test) {
condition = t.conditionalExpression(t.binaryExpression("===", disc, c.test), caseLocs[i] = loc(), condition);
condition = t.conditionalExpression(t.binaryExpression("===", t.cloneDeep(disc), c.test), caseLocs[i] = this.loc(), condition);
} else {

@@ -509,4 +522,4 @@ caseLocs[i] = defaultLoc;

case "IfStatement":
var elseLoc = stmt.alternate && loc();
after = loc();
var elseLoc = stmt.alternate && this.loc();
after = this.loc();
self.jumpIfNot(self.explodeExpression(path.get("test")), elseLoc || after);

@@ -535,7 +548,7 @@ self.explodeStatement(path.get("consequent"));

case "TryStatement":
after = loc();
after = this.loc();
var handler = stmt.handler;
var catchLoc = handler && loc();
var catchLoc = handler && this.loc();
var catchEntry = catchLoc && new leap.CatchEntry(catchLoc, handler.param);
var finallyLoc = stmt.finalizer && loc();
var finallyLoc = stmt.finalizer && this.loc();
var finallyEntry = finallyLoc && new leap.FinallyEntry(finallyLoc, after);

@@ -565,3 +578,5 @@ var tryEntry = new leap.TryEntry(self.getUnmarkedCurrentLoc(), catchEntry, finallyEntry);

bodyPath.traverse(catchParamVisitor, {
safeParam: safeParam,
getSafeParam: function getSafeParam() {
return t.cloneDeep(safeParam);
},
catchParamName: handler.param.name

@@ -597,3 +612,3 @@ });

if (path.node.name === state.catchParamName && util.isReference(path)) {
util.replaceWithOrRemove(path, state.safeParam);
util.replaceWithOrRemove(path, state.getSafeParam());
}

@@ -622,7 +637,7 @@ },

t.assertLiteral(record.target);
abruptArgs[1] = record.target;
abruptArgs[1] = this.insertedLocs.has(record.target) ? record.target : t.cloneDeep(record.target);
} else if (record.type === "return" || record.type === "throw") {
if (record.value) {
t.assertExpression(record.value);
abruptArgs[1] = record.value;
abruptArgs[1] = this.insertedLocs.has(record.value) ? record.value : t.cloneDeep(record.value);
}

@@ -676,4 +691,6 @@ }

Ep.updateContextPrevLoc = function (loc) {
var t = util.getTypes();
if (loc) {
util.getTypes().assertLiteral(loc);
t.assertLiteral(loc);

@@ -796,3 +813,3 @@ if (loc.value === -1) {

newArgs.unshift(newObject);
newCallee = t.memberExpression(t.memberExpression(newObject, newProperty, calleePath.node.computed), t.identifier("call"), false);
newCallee = t.memberExpression(t.memberExpression(t.cloneDeep(newObject), newProperty, calleePath.node.computed), t.identifier("call"), false);
} else {

@@ -813,3 +830,3 @@ newCallee = self.explodeExpression(calleePath);

// object.
newCallee = t.sequenceExpression([t.numericLiteral(0), newCallee]);
newCallee = t.sequenceExpression([t.numericLiteral(0), t.cloneDeep(newCallee)]);
}

@@ -821,3 +838,5 @@ }

});
return finish(t.callExpression(newCallee, newArgs));
return finish(t.callExpression(newCallee, newArgs.map(function (arg) {
return t.cloneDeep(arg);
})));

@@ -855,3 +874,3 @@ case "NewExpression":

case "LogicalExpression":
after = loc();
after = this.loc();

@@ -877,4 +896,4 @@ if (!ignoreResult) {

case "ConditionalExpression":
var elseLoc = loc();
after = loc();
var elseLoc = this.loc();
after = this.loc();
var test = self.explodeExpression(path.get("test"));

@@ -909,3 +928,3 @@ self.jumpIfNot(test, elseLoc);

case "YieldExpression":
after = loc();
after = this.loc();
var arg = expr.argument && self.explodeExpression(path.get("argument"));

@@ -925,3 +944,3 @@

self.emitAssign(self.contextProperty("next"), after);
var ret = t.returnStatement(arg || null); // Preserve the `yield` location so that source mappings for the statements
var ret = t.returnStatement(t.cloneDeep(arg) || null); // Preserve the `yield` location so that source mappings for the statements
// link back to the yield properly.

@@ -928,0 +947,0 @@

@@ -78,3 +78,3 @@ "use strict";

vars[node.id.name] = node.id;
var assignment = t.expressionStatement(t.assignmentExpression("=", node.id, t.functionExpression(path.scope.generateUidIdentifierBasedOnNode(node), node.params, node.body, node.generator, node.expression)));
var assignment = t.expressionStatement(t.assignmentExpression("=", t.clone(node.id), t.functionExpression(path.scope.generateUidIdentifierBasedOnNode(node), node.params, node.body, node.generator, node.expression)));

@@ -81,0 +81,0 @@ if (path.parentPath.isBlockStatement()) {

@@ -95,3 +95,5 @@ /**

var vars = (0, _hoist.hoist)(path);
var didRenameArguments = renameArguments(path, argsId);
var didRenameArguments = renameArguments(path, function () {
return t.clone(argsId);
});

@@ -103,3 +105,3 @@ if (didRenameArguments) {

argumentIdentifier._shadowedFunctionLiteral = path;
vars.declarations.push(t.variableDeclarator(argsId, argumentIdentifier));
vars.declarations.push(t.variableDeclarator(t.clone(argsId), argumentIdentifier));
}

@@ -148,7 +150,17 @@

path.addComment("leading", "#__PURE__");
} // Generators are processed in 'exit' handlers so that regenerator only has to run on
}
var insertedLocs = emitter.getInsertedLocs();
path.traverse({
NumericLiteral: function NumericLiteral(path) {
if (!insertedLocs.has(path.node)) {
return;
}
path.replaceWith(t.numericLiteral(path.node.value));
}
}); // Generators are processed in 'exit' handlers so that regenerator only has to run on
// an ES5 AST, but that means traversal will not pick up newly inserted references
// to things like 'regeneratorRuntime'. To avoid this, we explicitly requeue.
path.requeue();

@@ -181,3 +193,3 @@ })

return node.id;
return t.clone(node.id);
}

@@ -215,3 +227,3 @@

var markedId = blockPath.scope.generateUidIdentifier("marked");
var markCallExp = t.callExpression(util.runtimeProperty("mark"), [node.id]);
var markCallExp = t.callExpression(util.runtimeProperty("mark"), [t.clone(node.id)]);
var index = info.decl.declarations.push(t.variableDeclarator(markedId, markCallExp)) - 1;

@@ -223,9 +235,9 @@ var markCallExpPath = info.declPath.get("declarations." + index + ".init");

markCallExpPath.addComment("leading", "#__PURE__");
return markedId;
return t.clone(markedId);
}
function renameArguments(funcPath, argsId) {
function renameArguments(funcPath, getArgsId) {
var state = {
didRenameArguments: false,
argsId: argsId
getArgsId: getArgsId
};

@@ -246,3 +258,3 @@ funcPath.traverse(argumentsVisitor, state); // If the traversal replaced any arguments references, then we need to

if (path.node.name === "arguments" && util.isReference(path)) {
util.replaceWithOrRemove(path, state.argsId);
util.replaceWithOrRemove(path, state.getArgsId());
state.didRenameArguments = true;

@@ -258,3 +270,3 @@ }

var t = util.getTypes();
util.replaceWithOrRemove(path, t.memberExpression(this.context, t.identifier("_sent")));
util.replaceWithOrRemove(path, t.memberExpression(t.clone(this.context), t.identifier("_sent")));
}

@@ -261,0 +273,0 @@ }

@@ -5,3 +5,3 @@ {

"description": "Explode async and generator functions into a state machine.",
"version": "0.13.0",
"version": "0.13.1",
"main": "lib/index.js",

@@ -8,0 +8,0 @@ "keywords": [

@@ -37,5 +37,7 @@ /**

this.insertedLocs = new Set();
// The last location will be marked when this.getDispatchLoop is
// called.
this.finalLoc = loc();
this.finalLoc = this.loc();

@@ -59,6 +61,16 @@ // A list of all leap.TryEntry statements emitted.

// refers to the location.
function loc() {
return util.getTypes().numericLiteral(-1);
Ep.loc = function() {
const l = util.getTypes().numericLiteral(-1)
this.insertedLocs.add(l);
return l;
}
Ep.getInsertedLocs = function() {
return this.insertedLocs;
}
Ep.getContextId = function() {
return util.getTypes().clone(this.contextId);
}
// Sets the exact value of the given location to the offset of the next

@@ -102,3 +114,3 @@ // Statement emitted.

return t.expressionStatement(
t.assignmentExpression("=", lhs, rhs));
t.assignmentExpression("=", t.cloneDeep(lhs), rhs));
};

@@ -111,3 +123,3 @@

return t.memberExpression(
this.contextId,
this.getContextId(),
computed ? t.stringLiteral(name) : t.identifier(name),

@@ -143,3 +155,3 @@ !!computed

this.contextProperty("catch", true),
[tryLoc]
[t.clone(tryLoc)]
);

@@ -216,3 +228,3 @@

id || null/*Anonymous*/,
[this.contextId],
[this.getContextId()],
t.blockStatement([this.getDispatchLoop()]),

@@ -322,3 +334,3 @@ false, // Not a generator anymore!

return t.arrayExpression(locs);
return t.arrayExpression(locs.map(loc => loc && t.clone(loc)));
})

@@ -422,3 +434,3 @@ );

case "LabeledStatement":
after = loc();
after = this.loc();

@@ -457,4 +469,4 @@ // Did you know you can break from any labeled block statement or

case "WhileStatement":
before = loc();
after = loc();
before = this.loc();
after = this.loc();

@@ -473,5 +485,5 @@ self.mark(before);

case "DoWhileStatement":
let first = loc();
let test = loc();
after = loc();
let first = this.loc();
let test = this.loc();
after = this.loc();

@@ -490,5 +502,5 @@ self.mark(first);

case "ForStatement":
head = loc();
let update = loc();
after = loc();
head = this.loc();
let update = this.loc();
after = this.loc();

@@ -532,4 +544,4 @@ if (stmt.init) {

case "ForInStatement":
head = loc();
after = loc();
head = this.loc();
after = this.loc();

@@ -553,3 +565,3 @@ let keyIterNextFn = self.makeTempVar();

keyInfoTmpVar,
t.callExpression(keyIterNextFn, [])
t.callExpression(t.cloneDeep(keyIterNextFn), [])
),

@@ -565,3 +577,3 @@ t.identifier("done"),

t.memberExpression(
keyInfoTmpVar,
t.cloneDeep(keyInfoTmpVar),
t.identifier("value"),

@@ -607,4 +619,4 @@ false

after = loc();
let defaultLoc = loc();
after = this.loc();
let defaultLoc = this.loc();
let condition = defaultLoc;

@@ -622,4 +634,4 @@ let caseLocs = [];

condition = t.conditionalExpression(
t.binaryExpression("===", disc, c.test),
caseLocs[i] = loc(),
t.binaryExpression("===", t.cloneDeep(disc), c.test),
caseLocs[i] = this.loc(),
condition

@@ -659,4 +671,4 @@ );

case "IfStatement":
let elseLoc = stmt.alternate && loc();
after = loc();
let elseLoc = stmt.alternate && this.loc();
after = this.loc();

@@ -692,7 +704,7 @@ self.jumpIfNot(

case "TryStatement":
after = loc();
after = this.loc();
let handler = stmt.handler;
let catchLoc = handler && loc();
let catchLoc = handler && this.loc();
let catchEntry = catchLoc && new leap.CatchEntry(

@@ -703,3 +715,3 @@ catchLoc,

let finallyLoc = stmt.finalizer && loc();
let finallyLoc = stmt.finalizer && this.loc();
let finallyEntry = finallyLoc &&

@@ -740,3 +752,3 @@ new leap.FinallyEntry(finallyLoc, after);

bodyPath.traverse(catchParamVisitor, {
safeParam: safeParam,
getSafeParam: () => t.cloneDeep(safeParam),
catchParamName: handler.param.name

@@ -785,3 +797,3 @@ });

if (path.node.name === state.catchParamName && util.isReference(path)) {
util.replaceWithOrRemove(path, state.safeParam);
util.replaceWithOrRemove(path, state.getSafeParam());
}

@@ -819,3 +831,5 @@ },

t.assertLiteral(record.target);
abruptArgs[1] = record.target;
abruptArgs[1] = this.insertedLocs.has(record.target)
? record.target
: t.cloneDeep(record.target);
} else if (record.type === "return" ||

@@ -825,3 +839,5 @@ record.type === "throw") {

t.assertExpression(record.value);
abruptArgs[1] = record.value;
abruptArgs[1] = this.insertedLocs.has(record.value)
? record.value
: t.cloneDeep(record.value);
}

@@ -887,4 +903,5 @@ }

Ep.updateContextPrevLoc = function(loc) {
const t = util.getTypes();
if (loc) {
util.getTypes().assertLiteral(loc);
t.assertLiteral(loc);

@@ -1036,3 +1053,3 @@ if (loc.value === -1) {

t.memberExpression(
newObject,
t.cloneDeep(newObject),
newProperty,

@@ -1063,3 +1080,3 @@ calleePath.node.computed

t.numericLiteral(0),
newCallee
t.cloneDeep(newCallee)
]);

@@ -1075,3 +1092,3 @@ }

newCallee,
newArgs
newArgs.map(arg => t.cloneDeep(arg))
));

@@ -1123,3 +1140,3 @@

case "LogicalExpression":
after = loc();
after = this.loc();

@@ -1146,4 +1163,4 @@ if (!ignoreResult) {

case "ConditionalExpression":
let elseLoc = loc();
after = loc();
let elseLoc = this.loc();
after = this.loc();
let test = self.explodeExpression(path.get("test"));

@@ -1198,3 +1215,3 @@

case "YieldExpression":
after = loc();
after = this.loc();
let arg = expr.argument && self.explodeExpression(path.get("argument"));

@@ -1223,3 +1240,3 @@

let ret = t.returnStatement(arg || null);
let ret = t.returnStatement(t.cloneDeep(arg) || null);
// Preserve the `yield` location so that source mappings for the statements

@@ -1226,0 +1243,0 @@ // link back to the yield properly.

@@ -88,3 +88,3 @@ /**

"=",
node.id,
t.clone(node.id),
t.functionExpression(

@@ -91,0 +91,0 @@ path.scope.generateUidIdentifierBasedOnNode(node),

@@ -92,3 +92,3 @@ /**

let didRenameArguments = renameArguments(path, argsId);
let didRenameArguments = renameArguments(path, () => t.clone(argsId));
if (didRenameArguments) {

@@ -100,3 +100,3 @@ vars = vars || t.variableDeclaration("var", []);

vars.declarations.push(t.variableDeclarator(
argsId, argumentIdentifier
t.clone(argsId), argumentIdentifier
));

@@ -155,2 +155,14 @@ }

const insertedLocs = emitter.getInsertedLocs();
path.traverse({
NumericLiteral(path) {
if (!insertedLocs.has(path.node)) {
return;
}
path.replaceWith(t.numericLiteral(path.node.value));
},
})
// Generators are processed in 'exit' handlers so that regenerator only has to run on

@@ -185,3 +197,3 @@ // an ES5 AST, but that means traversal will not pick up newly inserted references

return node.id;
return t.clone(node.id);
}

@@ -220,3 +232,3 @@

util.runtimeProperty("mark"),
[node.id]
[t.clone(node.id)]
);

@@ -235,9 +247,9 @@

return markedId;
return t.clone(markedId);
}
function renameArguments(funcPath, argsId) {
function renameArguments(funcPath, getArgsId) {
let state = {
didRenameArguments: false,
argsId: argsId
getArgsId: getArgsId
};

@@ -261,3 +273,3 @@

if (path.node.name === "arguments" && util.isReference(path)) {
util.replaceWithOrRemove(path, state.argsId);
util.replaceWithOrRemove(path, state.getArgsId());
state.didRenameArguments = true;

@@ -278,3 +290,3 @@ }

t.memberExpression(
this.context,
t.clone(this.context),
t.identifier("_sent")

@@ -281,0 +293,0 @@ )

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc