Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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.11.1 to 0.12.0

lib/visit.js~

59

lib/emit.js

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

var _babelTypes = require("babel-types");
var t = _interopRequireWildcard(_babelTypes);
var _leap = require("./leap");

@@ -28,16 +24,19 @@

var hasOwn = Object.prototype.hasOwnProperty; /**
* Copyright (c) 2014, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* https://raw.github.com/facebook/regenerator/master/LICENSE file. An
* additional grant of patent rights can be found in the PATENTS file in
* the same directory.
*/
/**
* Copyright (c) 2014, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* https://raw.github.com/facebook/regenerator/master/LICENSE file. An
* additional grant of patent rights can be found in the PATENTS file in
* the same directory.
*/
var hasOwn = Object.prototype.hasOwnProperty;
function Emitter(contextId) {
_assert2.default.ok(this instanceof Emitter);
t.assertIdentifier(contextId);
util.getTypes().assertIdentifier(contextId);
// Used to generate unique temporary names.

@@ -82,3 +81,3 @@ this.nextTempId = 0;

function loc() {
return t.numericLiteral(-1);
return util.getTypes().numericLiteral(-1);
}

@@ -89,3 +88,3 @@

Ep.mark = function (loc) {
t.assertLiteral(loc);
util.getTypes().assertLiteral(loc);
var index = this.listing.length;

@@ -104,2 +103,4 @@ if (loc.value === -1) {

Ep.emit = function (node) {
var t = util.getTypes();
if (t.isExpression(node)) {

@@ -122,2 +123,3 @@ node = t.expressionStatement(node);

Ep.assign = function (lhs, rhs) {
var t = util.getTypes();
return t.expressionStatement(t.assignmentExpression("=", lhs, rhs));

@@ -129,2 +131,3 @@ };

Ep.contextProperty = function (name, computed) {
var t = util.getTypes();
return t.memberExpression(this.contextId, computed ? t.stringLiteral(name) : t.identifier(name), !!computed);

@@ -143,3 +146,3 @@ };

Ep.setReturnValue = function (valuePath) {
t.assertExpression(valuePath.value);
util.getTypes().assertExpression(valuePath.value);

@@ -150,2 +153,4 @@ this.emitAssign(this.contextProperty("rval"), this.explodeExpression(valuePath));

Ep.clearPendingException = function (tryLoc, assignee) {
var t = util.getTypes();
t.assertLiteral(tryLoc);

@@ -166,3 +171,3 @@

this.emitAssign(this.contextProperty("next"), toLoc);
this.emit(t.breakStatement());
this.emit(util.getTypes().breakStatement());
};

@@ -172,2 +177,4 @@

Ep.jumpIf = function (test, toLoc) {
var t = util.getTypes();
t.assertExpression(test);

@@ -181,2 +188,4 @@ t.assertLiteral(toLoc);

Ep.jumpIfNot = function (test, toLoc) {
var t = util.getTypes();
t.assertExpression(test);

@@ -206,2 +215,4 @@ t.assertLiteral(toLoc);

Ep.getContextFunction = function (id) {
var t = util.getTypes();
return t.functionExpression(id || null /*Anonymous*/

@@ -226,2 +237,3 @@ , [this.contextId], t.blockStatement([this.getDispatchLoop()]), false, // Not a generator anymore!

var self = this;
var t = util.getTypes();
var cases = [];

@@ -270,2 +282,3 @@ var current = void 0;

var t = util.getTypes();
var lastLocValue = 0;

@@ -302,2 +315,3 @@

Ep.explode = function (path, ignoreResult) {
var t = util.getTypes();
var node = path.node;

@@ -338,2 +352,3 @@ var self = this;

Ep.explodeStatement = function (path, labelId) {
var t = util.getTypes();
var stmt = path.node;

@@ -688,2 +703,3 @@ var self = this;

var t = util.getTypes();
var abruptArgs = [t.stringLiteral(record.type)];

@@ -712,3 +728,3 @@

if (type === "break" || type === "continue") {
return !hasOwn.call(record, "value") && t.isLiteral(record.target);
return !hasOwn.call(record, "value") && util.getTypes().isLiteral(record.target);
}

@@ -733,3 +749,3 @@

Ep.getUnmarkedCurrentLoc = function () {
return t.numericLiteral(this.listing.length);
return util.getTypes().numericLiteral(this.listing.length);
};

@@ -749,3 +765,3 @@

if (loc) {
t.assertLiteral(loc);
util.getTypes().assertLiteral(loc);

@@ -771,2 +787,3 @@ if (loc.value === -1) {

Ep.explodeExpression = function (path, ignoreResult) {
var t = util.getTypes();
var expr = path.node;

@@ -773,0 +790,0 @@ if (expr) {

"use strict";
var _babelTypes = require("babel-types");
var t = _interopRequireWildcard(_babelTypes);
var _util = require("./util");

@@ -13,2 +9,8 @@

var hasOwn = Object.prototype.hasOwnProperty;
// The hoist function takes a FunctionExpression or FunctionDeclaration
// and replaces any Declaration nodes in its body with assignments, then
// returns a VariableDeclaration containing just the names of the removed
// declarations.
/**

@@ -24,9 +26,4 @@ * Copyright (c) 2014, Facebook, Inc.

var hasOwn = Object.prototype.hasOwnProperty;
// The hoist function takes a FunctionExpression or FunctionDeclaration
// and replaces any Declaration nodes in its body with assignments, then
// returns a VariableDeclaration containing just the names of the removed
// declarations.
exports.hoist = function (funPath) {
var t = util.getTypes();
t.assertFunction(funPath.node);

@@ -120,2 +117,7 @@

path.skip();
},
ArrowFunctionExpression: function ArrowFunctionExpression(path) {
// Don't descend into nested function expressions.
path.skip();
}

@@ -122,0 +124,0 @@ });

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

var plugin = {
visitor: require("./visit").visitor
visitor: require("./visit").getVisitor(context)
};

@@ -10,0 +10,0 @@

@@ -7,9 +7,5 @@ "use strict";

var _babelTypes = require("babel-types");
var t = _interopRequireWildcard(_babelTypes);
var _util = require("util");
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
var _util2 = require("./util.js");

@@ -32,3 +28,3 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

Entry.call(this);
t.assertLiteral(returnLoc);
(0, _util2.getTypes)().assertLiteral(returnLoc);
this.returnLoc = returnLoc;

@@ -43,2 +39,4 @@ }

var t = (0, _util2.getTypes)();
t.assertLiteral(breakLoc);

@@ -63,3 +61,3 @@ t.assertLiteral(continueLoc);

Entry.call(this);
t.assertLiteral(breakLoc);
(0, _util2.getTypes)().assertLiteral(breakLoc);
this.breakLoc = breakLoc;

@@ -74,2 +72,3 @@ }

var t = (0, _util2.getTypes)();
t.assertLiteral(firstLoc);

@@ -103,2 +102,4 @@

var t = (0, _util2.getTypes)();
t.assertLiteral(firstLoc);

@@ -116,2 +117,3 @@ t.assertIdentifier(paramId);

Entry.call(this);
var t = (0, _util2.getTypes)();
t.assertLiteral(firstLoc);

@@ -129,2 +131,4 @@ t.assertLiteral(afterLoc);

var t = (0, _util2.getTypes)();
t.assertLiteral(breakLoc);

@@ -131,0 +135,0 @@ t.assertIdentifier(label);

@@ -7,20 +7,17 @@ "use strict";

var _babelTypes = require("babel-types");
var _util = require("./util.js");
var t = _interopRequireWildcard(_babelTypes);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var m = require("private").makeAccessor(); /**
* Copyright (c) 2014, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* https://raw.github.com/facebook/regenerator/master/LICENSE file. An
* additional grant of patent rights can be found in the PATENTS file in
* the same directory.
*/
/**
* Copyright (c) 2014, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* https://raw.github.com/facebook/regenerator/master/LICENSE file. An
* additional grant of patent rights can be found in the PATENTS file in
* the same directory.
*/
var m = require("private").makeAccessor();
var hasOwn = Object.prototype.hasOwnProperty;

@@ -30,2 +27,3 @@

function onlyChildren(node) {
var t = (0, _util.getTypes)();
t.assertNode(node);

@@ -61,3 +59,3 @@

function predicate(node) {
t.assertNode(node);
(0, _util.getTypes)().assertNode(node);

@@ -64,0 +62,0 @@ var meta = m(node);

@@ -6,6 +6,2 @@ "use strict";

var _babelTypes = require("babel-types");
var t = _interopRequireWildcard(_babelTypes);
var _util = require("./util");

@@ -46,2 +42,4 @@

function replaceShorthandObjectMethod(path) {
var t = util.getTypes();
if (!path.node || !t.isFunction(path.node)) {

@@ -48,0 +46,0 @@ throw new Error("replaceShorthandObjectMethod can only be called on Function AST node paths.");

"use strict";
exports.__esModule = true;
exports.wrapWithTypes = wrapWithTypes;
exports.getTypes = getTypes;
exports.runtimeProperty = runtimeProperty;
exports.isReference = isReference;
exports.replaceWithOrRemove = replaceWithOrRemove;
/**
* Copyright (c) 2014, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* https://raw.github.com/facebook/regenerator/master/LICENSE file. An
* additional grant of patent rights can be found in the PATENTS file in
* the same directory.
*/
var _babelTypes = require("babel-types");
var currentTypes = null;
var t = _interopRequireWildcard(_babelTypes);
function wrapWithTypes(types, fn) {
return function () {
var oldTypes = currentTypes;
currentTypes = types;
try {
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
return fn.apply(this, args);
} finally {
currentTypes = oldTypes;
}
};
}
function getTypes() {
return currentTypes;
}
function runtimeProperty(name) {
var t = getTypes();
return t.memberExpression(t.identifier("regeneratorRuntime"), t.identifier(name), false);
} /**
* Copyright (c) 2014, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* https://raw.github.com/facebook/regenerator/master/LICENSE file. An
* additional grant of patent rights can be found in the PATENTS file in
* the same directory.
*/
}

@@ -26,0 +46,0 @@ function isReference(path) {

@@ -17,6 +17,2 @@ /**

var _babelTypes = require("babel-types");
var t = _interopRequireWildcard(_babelTypes);
var _hoist = require("./hoist");

@@ -38,136 +34,139 @@

exports.visitor = {
Function: {
exit: function exit(path, state) {
var node = path.node;
exports.getVisitor = function (_ref) {
var t = _ref.types;
return {
Function: {
exit: util.wrapWithTypes(t, function (path, state) {
var node = path.node;
if (node.generator) {
if (node.async) {
// Async generator
if (state.opts.asyncGenerators === false) return;
if (node.generator) {
if (node.async) {
// Async generator
if (state.opts.asyncGenerators === false) return;
} else {
// Plain generator
if (state.opts.generators === false) return;
}
} else if (node.async) {
// Async function
if (state.opts.async === false) return;
} else {
// Plain generator
if (state.opts.generators === false) return;
// Not a generator or async function.
return;
}
} else if (node.async) {
// Async function
if (state.opts.async === false) return;
} else {
// Not a generator or async function.
return;
}
// if this is an ObjectMethod, we need to convert it to an ObjectProperty
path = (0, _replaceShorthandObjectMethod2.default)(path);
node = path.node;
// if this is an ObjectMethod, we need to convert it to an ObjectProperty
path = (0, _replaceShorthandObjectMethod2.default)(path);
node = path.node;
var contextId = path.scope.generateUidIdentifier("context");
var argsId = path.scope.generateUidIdentifier("args");
var contextId = path.scope.generateUidIdentifier("context");
var argsId = path.scope.generateUidIdentifier("args");
path.ensureBlock();
var bodyBlockPath = path.get("body");
path.ensureBlock();
var bodyBlockPath = path.get("body");
if (node.async) {
bodyBlockPath.traverse(awaitVisitor);
}
if (node.async) {
bodyBlockPath.traverse(awaitVisitor);
}
bodyBlockPath.traverse(functionSentVisitor, {
context: contextId
});
bodyBlockPath.traverse(functionSentVisitor, {
context: contextId
});
var outerBody = [];
var innerBody = [];
var outerBody = [];
var innerBody = [];
bodyBlockPath.get("body").forEach(function (childPath) {
var node = childPath.node;
if (t.isExpressionStatement(node) && t.isStringLiteral(node.expression)) {
// Babylon represents directives like "use strict" as elements
// of a bodyBlockPath.node.directives array, but they could just
// as easily be represented (by other parsers) as traditional
// string-literal-valued expression statements, so we need to
// handle that here. (#248)
outerBody.push(node);
} else if (node && node._blockHoist != null) {
outerBody.push(node);
} else {
innerBody.push(node);
bodyBlockPath.get("body").forEach(function (childPath) {
var node = childPath.node;
if (t.isExpressionStatement(node) && t.isStringLiteral(node.expression)) {
// Babylon represents directives like "use strict" as elements
// of a bodyBlockPath.node.directives array, but they could just
// as easily be represented (by other parsers) as traditional
// string-literal-valued expression statements, so we need to
// handle that here. (#248)
outerBody.push(node);
} else if (node && node._blockHoist != null) {
outerBody.push(node);
} else {
innerBody.push(node);
}
});
if (outerBody.length > 0) {
// Only replace the inner body if we actually hoisted any statements
// to the outer body.
bodyBlockPath.node.body = innerBody;
}
});
if (outerBody.length > 0) {
// Only replace the inner body if we actually hoisted any statements
// to the outer body.
bodyBlockPath.node.body = innerBody;
}
var outerFnExpr = getOuterFnExpr(path);
// Note that getOuterFnExpr has the side-effect of ensuring that the
// function has a name (so node.id will always be an Identifier), even
// if a temporary name has to be synthesized.
t.assertIdentifier(node.id);
var innerFnId = t.identifier(node.id.name + "$");
var outerFnExpr = getOuterFnExpr(path);
// Note that getOuterFnExpr has the side-effect of ensuring that the
// function has a name (so node.id will always be an Identifier), even
// if a temporary name has to be synthesized.
t.assertIdentifier(node.id);
var innerFnId = t.identifier(node.id.name + "$");
// Turn all declarations into vars, and replace the original
// declarations with equivalent assignment expressions.
var vars = (0, _hoist.hoist)(path);
// Turn all declarations into vars, and replace the original
// declarations with equivalent assignment expressions.
var vars = (0, _hoist.hoist)(path);
var didRenameArguments = renameArguments(path, argsId);
if (didRenameArguments) {
vars = vars || t.variableDeclaration("var", []);
var argumentIdentifier = t.identifier("arguments");
// we need to do this as otherwise arguments in arrow functions gets hoisted
argumentIdentifier._shadowedFunctionLiteral = path;
vars.declarations.push(t.variableDeclarator(argsId, argumentIdentifier));
}
var didRenameArguments = renameArguments(path, argsId);
if (didRenameArguments) {
vars = vars || t.variableDeclaration("var", []);
var argumentIdentifier = t.identifier("arguments");
// we need to do this as otherwise arguments in arrow functions gets hoisted
argumentIdentifier._shadowedFunctionLiteral = path;
vars.declarations.push(t.variableDeclarator(argsId, argumentIdentifier));
}
var emitter = new _emit.Emitter(contextId);
emitter.explode(path.get("body"));
var emitter = new _emit.Emitter(contextId);
emitter.explode(path.get("body"));
if (vars && vars.declarations.length > 0) {
outerBody.push(vars);
}
if (vars && vars.declarations.length > 0) {
outerBody.push(vars);
}
var wrapArgs = [emitter.getContextFunction(innerFnId),
// Async functions that are not generators don't care about the
// outer function because they don't need it to be marked and don't
// inherit from its .prototype.
node.generator ? outerFnExpr : t.nullLiteral(), t.thisExpression()];
var wrapArgs = [emitter.getContextFunction(innerFnId),
// Async functions that are not generators don't care about the
// outer function because they don't need it to be marked and don't
// inherit from its .prototype.
node.generator ? outerFnExpr : t.nullLiteral(), t.thisExpression()];
var tryLocsList = emitter.getTryLocsList();
if (tryLocsList) {
wrapArgs.push(tryLocsList);
}
var tryLocsList = emitter.getTryLocsList();
if (tryLocsList) {
wrapArgs.push(tryLocsList);
}
var wrapCall = t.callExpression(util.runtimeProperty(node.async ? "async" : "wrap"), wrapArgs);
var wrapCall = t.callExpression(util.runtimeProperty(node.async ? "async" : "wrap"), wrapArgs);
outerBody.push(t.returnStatement(wrapCall));
node.body = t.blockStatement(outerBody);
outerBody.push(t.returnStatement(wrapCall));
node.body = t.blockStatement(outerBody);
var oldDirectives = bodyBlockPath.node.directives;
if (oldDirectives) {
// Babylon represents directives like "use strict" as elements of
// a bodyBlockPath.node.directives array. (#248)
node.body.directives = oldDirectives;
}
var oldDirectives = bodyBlockPath.node.directives;
if (oldDirectives) {
// Babylon represents directives like "use strict" as elements of
// a bodyBlockPath.node.directives array. (#248)
node.body.directives = oldDirectives;
}
var wasGeneratorFunction = node.generator;
if (wasGeneratorFunction) {
node.generator = false;
}
var wasGeneratorFunction = node.generator;
if (wasGeneratorFunction) {
node.generator = false;
}
if (node.async) {
node.async = false;
}
if (node.async) {
node.async = false;
}
if (wasGeneratorFunction && t.isExpression(node)) {
util.replaceWithOrRemove(path, t.callExpression(util.runtimeProperty("mark"), [node]));
path.addComment("leading", "#__PURE__");
}
if (wasGeneratorFunction && t.isExpression(node)) {
util.replaceWithOrRemove(path, t.callExpression(util.runtimeProperty("mark"), [node]));
path.addComment("leading", "#__PURE__");
}
// 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();
// 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();
})
}
}
};
};

@@ -180,2 +179,3 @@

function getOuterFnExpr(funPath) {
var t = util.getTypes();
var node = funPath.node;

@@ -202,2 +202,3 @@ t.assertFunction(node);

function getMarkedFunctionId(funPath) {
var t = util.getTypes();
var node = funPath.node;

@@ -275,2 +276,3 @@ t.assertIdentifier(node.id);

if (node.meta.name === "function" && node.property.name === "sent") {
var t = util.getTypes();
util.replaceWithOrRemove(path, t.memberExpression(this.context, t.identifier("_sent")));

@@ -287,2 +289,4 @@ }

AwaitExpression: function AwaitExpression(path) {
var t = util.getTypes();
// Convert await expressions to yield expressions.

@@ -289,0 +293,0 @@ var argument = path.node.argument;

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

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

@@ -33,3 +33,2 @@ "keywords": [

"dependencies": {
"babel-types": "7.0.0-beta.3",
"private": "^0.1.6"

@@ -36,0 +35,0 @@ },

@@ -12,3 +12,2 @@ /**

import assert from "assert";
import * as t from "babel-types";
import * as leap from "./leap";

@@ -22,4 +21,5 @@ import * as meta from "./meta";

assert.ok(this instanceof Emitter);
t.assertIdentifier(contextId);
util.getTypes().assertIdentifier(contextId);
// Used to generate unique temporary names.

@@ -64,3 +64,3 @@ this.nextTempId = 0;

function loc() {
return t.numericLiteral(-1);
return util.getTypes().numericLiteral(-1);
}

@@ -71,3 +71,3 @@

Ep.mark = function(loc) {
t.assertLiteral(loc);
util.getTypes().assertLiteral(loc);
let index = this.listing.length;

@@ -86,2 +86,4 @@ if (loc.value === -1) {

Ep.emit = function(node) {
const t = util.getTypes();
if (t.isExpression(node)) {

@@ -104,2 +106,3 @@ node = t.expressionStatement(node);

Ep.assign = function(lhs, rhs) {
const t = util.getTypes();
return t.expressionStatement(

@@ -112,2 +115,3 @@ t.assignmentExpression("=", lhs, rhs));

Ep.contextProperty = function(name, computed) {
const t = util.getTypes();
return t.memberExpression(

@@ -130,3 +134,3 @@ this.contextId,

Ep.setReturnValue = function(valuePath) {
t.assertExpression(valuePath.value);
util.getTypes().assertExpression(valuePath.value);

@@ -140,2 +144,4 @@ this.emitAssign(

Ep.clearPendingException = function(tryLoc, assignee) {
const t = util.getTypes();
t.assertLiteral(tryLoc);

@@ -159,3 +165,3 @@

this.emitAssign(this.contextProperty("next"), toLoc);
this.emit(t.breakStatement());
this.emit(util.getTypes().breakStatement());
};

@@ -165,2 +171,4 @@

Ep.jumpIf = function(test, toLoc) {
const t = util.getTypes();
t.assertExpression(test);

@@ -180,2 +188,4 @@ t.assertLiteral(toLoc);

Ep.jumpIfNot = function(test, toLoc) {
const t = util.getTypes();
t.assertExpression(test);

@@ -212,2 +222,4 @@ t.assertLiteral(toLoc);

Ep.getContextFunction = function(id) {
const t = util.getTypes();
return t.functionExpression(

@@ -234,3 +246,4 @@ id || null/*Anonymous*/,

Ep.getDispatchLoop = function() {
let self = this;
const self = this;
const t = util.getTypes();
let cases = [];

@@ -297,2 +310,3 @@ let current;

const t = util.getTypes();
let lastLocValue = 0;

@@ -333,2 +347,3 @@

Ep.explode = function(path, ignoreResult) {
const t = util.getTypes();
let node = path.node;

@@ -381,2 +396,3 @@ let self = this;

Ep.explodeStatement = function(path, labelId) {
const t = util.getTypes();
let stmt = path.node;

@@ -796,2 +812,3 @@ let self = this;

const t = util.getTypes();
let abruptArgs = [t.stringLiteral(record.type)];

@@ -831,3 +848,3 @@

return !hasOwn.call(record, "value")
&& t.isLiteral(record.target);
&& util.getTypes().isLiteral(record.target);
}

@@ -855,3 +872,3 @@

Ep.getUnmarkedCurrentLoc = function() {
return t.numericLiteral(this.listing.length);
return util.getTypes().numericLiteral(this.listing.length);
};

@@ -871,3 +888,3 @@

if (loc) {
t.assertLiteral(loc);
util.getTypes().assertLiteral(loc);

@@ -894,2 +911,3 @@ if (loc.value === -1) {

Ep.explodeExpression = function(path, ignoreResult) {
const t = util.getTypes();
let expr = path.node;

@@ -896,0 +914,0 @@ if (expr) {

@@ -11,3 +11,2 @@ /**

import * as t from "babel-types";
import * as util from "./util";

@@ -21,2 +20,3 @@ let hasOwn = Object.prototype.hasOwnProperty;

exports.hoist = function(funPath) {
const t = util.getTypes();
t.assertFunction(funPath.node);

@@ -126,2 +126,7 @@

path.skip();
},
ArrowFunctionExpression: function(path) {
// Don't descend into nested function expressions.
path.skip();
}

@@ -128,0 +133,0 @@ });

@@ -13,3 +13,3 @@ /**

const plugin = {
visitor: require("./visit").visitor,
visitor: require("./visit").getVisitor(context),
};

@@ -16,0 +16,0 @@

@@ -12,4 +12,4 @@ /**

import assert from "assert";
import * as t from "babel-types";
import { inherits } from "util";
import { getTypes } from "./util.js";

@@ -22,3 +22,3 @@ function Entry() {

Entry.call(this);
t.assertLiteral(returnLoc);
getTypes().assertLiteral(returnLoc);
this.returnLoc = returnLoc;

@@ -33,2 +33,4 @@ }

const t = getTypes();
t.assertLiteral(breakLoc);

@@ -53,3 +55,3 @@ t.assertLiteral(continueLoc);

Entry.call(this);
t.assertLiteral(breakLoc);
getTypes().assertLiteral(breakLoc);
this.breakLoc = breakLoc;

@@ -64,2 +66,3 @@ }

const t = getTypes();
t.assertLiteral(firstLoc);

@@ -93,2 +96,4 @@

const t = getTypes();
t.assertLiteral(firstLoc);

@@ -106,2 +111,3 @@ t.assertIdentifier(paramId);

Entry.call(this);
const t = getTypes();
t.assertLiteral(firstLoc);

@@ -119,2 +125,4 @@ t.assertLiteral(afterLoc);

const t = getTypes();
t.assertLiteral(breakLoc);

@@ -121,0 +129,0 @@ t.assertIdentifier(label);

@@ -12,4 +12,4 @@ /**

import assert from "assert";
import { getTypes } from "./util.js";
let m = require("private").makeAccessor();
import * as t from "babel-types";
let hasOwn = Object.prototype.hasOwnProperty;

@@ -19,2 +19,3 @@

function onlyChildren(node) {
const t = getTypes();
t.assertNode(node);

@@ -50,3 +51,3 @@

function predicate(node) {
t.assertNode(node);
getTypes().assertNode(node);

@@ -53,0 +54,0 @@ let meta = m(node);

@@ -1,2 +0,1 @@

import * as t from "babel-types";
import * as util from "./util";

@@ -33,2 +32,4 @@

export default function replaceShorthandObjectMethod(path) {
const t = util.getTypes();
if (!path.node || !t.isFunction(path.node)) {

@@ -35,0 +36,0 @@ throw new Error("replaceShorthandObjectMethod can only be called on Function AST node paths.");

@@ -11,5 +11,22 @@ /**

import * as t from "babel-types";
let currentTypes = null;
export function wrapWithTypes(types, fn) {
return function (...args) {
const oldTypes = currentTypes;
currentTypes = types;
try {
return fn.apply(this, args);
} finally {
currentTypes = oldTypes;
}
};
}
export function getTypes() {
return currentTypes;
}
export function runtimeProperty(name) {
const t = getTypes();
return t.memberExpression(

@@ -16,0 +33,0 @@ t.identifier("regeneratorRuntime"),

@@ -14,3 +14,2 @@ /**

import assert from "assert";
import * as t from "babel-types";
import { hoist } from "./hoist";

@@ -21,5 +20,5 @@ import { Emitter } from "./emit";

exports.visitor = {
exports.getVisitor = ({ types: t }) => ({
Function: {
exit: function(path, state) {
exit: util.wrapWithTypes(t, function(path, state) {
let node = path.node;

@@ -163,5 +162,5 @@

path.requeue();
}
})
}
};
});

@@ -173,2 +172,3 @@ // Given a NodePath for a Function, return an Expression node that can be

function getOuterFnExpr(funPath) {
const t = util.getTypes();
let node = funPath.node;

@@ -195,2 +195,3 @@ t.assertFunction(node);

function getMarkedFunctionId(funPath) {
const t = util.getTypes();
const node = funPath.node;

@@ -272,4 +273,12 @@ t.assertIdentifier(node.id);

if (node.meta.name === "function" && node.property.name === "sent") {
util.replaceWithOrRemove(path, t.memberExpression(this.context, t.identifier("_sent")));
if (node.meta.name === "function" &&
node.property.name === "sent") {
const t = util.getTypes();
util.replaceWithOrRemove(
path,
t.memberExpression(
this.context,
t.identifier("_sent")
)
);
}

@@ -285,2 +294,4 @@ }

AwaitExpression: function(path) {
const t = util.getTypes();
// Convert await expressions to yield expressions.

@@ -287,0 +298,0 @@ let argument = path.node.argument;

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