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

babel-traverse

Package Overview
Dependencies
Maintainers
5
Versions
78
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-traverse - npm Package Compare versions

Comparing version 7.0.0-alpha.19 to 7.0.0-alpha.20

31

lib/context.js

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

var _path2 = require("./path");
var _path4 = require("./path");
var _path3 = _interopRequireDefault(_path2);
var _path5 = _interopRequireDefault(_path4);

@@ -49,4 +49,4 @@ var _babelTypes = require("babel-types");

var key = _ref;
if (node[key]) return true;
var _key = _ref;
if (node[_key]) return true;
}

@@ -58,3 +58,3 @@

TraversalContext.prototype.create = function create(node, obj, key, listKey) {
return _path3.default.get({
return _path5.default.get({
parentPath: this.parentPath,

@@ -123,10 +123,11 @@ parent: node,

var path = _ref2;
path.resync();
var _path2 = _ref2;
if (path.contexts.length === 0 || path.contexts[path.contexts.length - 1] !== this) {
path.pushContext(this);
_path2.resync();
if (_path2.contexts.length === 0 || _path2.contexts[_path2.contexts.length - 1] !== this) {
_path2.pushContext(this);
}
if (path.key === null) continue;
if (_path2.key === null) continue;

@@ -137,6 +138,6 @@ if (testing && queue.length >= 10000) {

if (visited.indexOf(path.node) >= 0) continue;
visited.push(path.node);
if (visited.indexOf(_path2.node) >= 0) continue;
visited.push(_path2.node);
if (path.visit()) {
if (_path2.visit()) {
stop = true;

@@ -166,5 +167,5 @@ break;

var _path = _ref3;
var _path3 = _ref3;
_path.popContext();
_path3.popContext();
}

@@ -171,0 +172,0 @@

@@ -106,5 +106,5 @@ "use strict";

var key = _ref;
if (skipKeys && skipKeys[key]) continue;
if (context.visit(node, key)) return;
var _key = _ref;
if (skipKeys && skipKeys[_key]) continue;
if (context.visit(node, _key)) return;
}

@@ -111,0 +111,0 @@ };

@@ -63,10 +63,11 @@ "use strict";

var fn = _ref;
if (!fn) continue;
var _fn = _ref;
if (!_fn) continue;
var node = this.node;
if (!node) return true;
var ret = fn.call(this.state, this, this.state);
var ret = _fn.call(this.state, this, this.state);
if (ret) {
throw new Error("Unexpected return value from visitor method " + fn);
throw new Error("Unexpected return value from visitor method " + _fn);
}

@@ -238,4 +239,7 @@

function requeue() {
var pathToQueue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this;
function requeue(pathToQueue) {
if (pathToQueue === void 0) {
pathToQueue = this;
}
if (pathToQueue.removed) return;

@@ -256,4 +260,5 @@ var contexts = this.contexts;

var context = _ref2;
context.maybeQueue(pathToQueue);
var _context = _ref2;
_context.maybeQueue(pathToQueue);
}

@@ -260,0 +265,0 @@ }

@@ -58,4 +58,4 @@ "use strict";

function arrowFunctionToExpression() {
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
function arrowFunctionToExpression(_temp) {
var _ref = _temp === void 0 ? {} : _temp,
_ref$allowInsertArrow = _ref.allowInsertArrow,

@@ -89,7 +89,15 @@ allowInsertArrow = _ref$allowInsertArrow === undefined ? true : _ref$allowInsertArrow,

function hoistFunctionEnvironment(fnPath) {
var specCompliant = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
var allowInsertArrow = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
function hoistFunctionEnvironment(fnPath, specCompliant, allowInsertArrow) {
if (specCompliant === void 0) {
specCompliant = false;
}
if (allowInsertArrow === void 0) {
allowInsertArrow = true;
}
var thisEnvFn = fnPath.findParent(function (p) {
return p.isFunction() && !p.isArrowFunctionExpression() || p.isProgram() || p.isClassProperty();
return p.isFunction() && !p.isArrowFunctionExpression() || p.isProgram() || p.isClassProperty({
static: false
});
});

@@ -117,8 +125,9 @@ var inConstructor = thisEnvFn && thisEnvFn.node.kind === "constructor";

Function: function Function(child) {
if (child.isArrowFunctionExpression() || child.isClassProperty() || child === fnPath) {
return;
}
if (child.isArrowFunctionExpression()) return;
child.skip();
},
ClassProperty: function ClassProperty(child) {
if (child.node.static) return;
child.skip();
},
CallExpression: function CallExpression(child) {

@@ -259,4 +268,2 @@ if (!child.get("callee").isSuper()) return;

function getThisBinding(thisEnvFn, inConstructor) {
var _this = this;
return getBinding(thisEnvFn, "this", function (thisBinding) {

@@ -267,8 +274,9 @@ if (!inConstructor || !hasSuperClass(thisEnvFn)) return t.thisExpression();

Function: function Function(child) {
if (child.isArrowFunctionExpression() || child.isClassProperty() || child === _this) {
return;
}
if (child.isArrowFunctionExpression()) return;
child.skip();
},
ClassProperty: function ClassProperty(child) {
if (child.node.static) return;
child.skip();
},
CallExpression: function CallExpression(child) {

@@ -357,4 +365,8 @@ if (!child.get("callee").isSuper()) return;

fnPath.traverse({
ClassProperty: function ClassProperty(child) {
if (child.node.static) return;
child.skip();
},
Function: function Function(child) {
if (child.isArrowFunctionExpression() || child.isClassProperty()) return;
if (child.isArrowFunctionExpression()) return;
child.skip();

@@ -361,0 +373,0 @@ },

@@ -108,4 +108,5 @@ "use strict";

var value = _object.node.value;
var type = typeof value === "undefined" ? "undefined" : _typeof(value);
var type = _typeof(value);
if (type === "number" || type === "string") {

@@ -179,3 +180,3 @@ return value[_property.node.name];

case "typeof":
return typeof arg === "undefined" ? "undefined" : _typeof(arg);
return _typeof(arg);
}

@@ -200,9 +201,9 @@ }

var elem = _ref;
elem = elem.evaluate();
var _elem = _ref;
_elem = _elem.evaluate();
if (elem.confident) {
arr.push(elem.value);
if (_elem.confident) {
arr.push(_elem.value);
} else {
return deopt(elem, state);
return deopt(_elem, state);
}

@@ -230,12 +231,13 @@ }

var prop = _ref2;
var _prop = _ref2;
if (prop.isObjectMethod() || prop.isSpreadElement()) {
return deopt(prop, state);
if (_prop.isObjectMethod() || _prop.isSpreadElement()) {
return deopt(_prop, state);
}
var keyPath = prop.get("key");
var keyPath = _prop.get("key");
var key = keyPath;
if (prop.node.computed) {
if (_prop.node.computed) {
key = key.evaluate();

@@ -254,12 +256,12 @@

var valuePath = prop.get("value");
var valuePath = _prop.get("value");
var _value = valuePath.evaluate();
var _value2 = valuePath.evaluate();
if (!_value.confident) {
if (!_value2.confident) {
return deopt(valuePath, state);
}
_value = _value.value;
obj[key] = _value;
_value2 = _value2.value;
obj[key] = _value2;
}

@@ -412,4 +414,7 @@

function evaluateQuasis(path, quasis, state) {
var raw = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
function evaluateQuasis(path, quasis, state, raw) {
if (raw === void 0) {
raw = false;
}
var str = "";

@@ -431,5 +436,5 @@ var i = 0;

var elem = _ref3;
var _elem2 = _ref3;
if (!state.confident) break;
str += raw ? elem.value.raw : elem.value.cooked;
str += raw ? _elem2.value.raw : _elem2.value.cooked;
var expr = exprs[i++];

@@ -436,0 +441,0 @@ if (expr) str += String(evaluateCached(expr, state));

@@ -177,5 +177,11 @@ "use strict";

function getBindingIdentifierPaths() {
var duplicates = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
var outerOnly = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
function getBindingIdentifierPaths(duplicates, outerOnly) {
if (duplicates === void 0) {
duplicates = false;
}
if (outerOnly === void 0) {
outerOnly = false;
}
var path = this;

@@ -182,0 +188,0 @@ var search = [].concat(path);

@@ -167,4 +167,7 @@ "use strict";

NodePath.prototype.buildCodeFrameError = function buildCodeFrameError(msg) {
var Error = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : SyntaxError;
NodePath.prototype.buildCodeFrameError = function buildCodeFrameError(msg, Error) {
if (Error === void 0) {
Error = SyntaxError;
}
return this.hub.file.buildCodeFrameError(this.node, msg, Error);

@@ -171,0 +174,0 @@ };

@@ -203,4 +203,5 @@ "use strict";

var targetKeyPosition = t.VISITOR_KEYS[targetRelationship.type].indexOf(targetRelationship.key);
var selfKeyPosition = t.VISITOR_KEYS[selfRelationship.type].indexOf(selfRelationship.key);
var keys = t.VISITOR_KEYS[commonPath.type];
var targetKeyPosition = keys.indexOf(targetRelationship.key);
var selfKeyPosition = keys.indexOf(selfRelationship.key);
return targetKeyPosition > selfKeyPosition ? "before" : "after";

@@ -228,5 +229,5 @@ }

var path = _ref;
var _path2 = _ref;
if (path.key !== "callee" || !path.parentPath.isCallExpression()) {
if (_path2.key !== "callee" || !_path2.parentPath.isCallExpression()) {
return;

@@ -250,4 +251,4 @@ }

var _path = _ref2;
var childOfFunction = !!_path.find(function (path) {
var _path3 = _ref2;
var childOfFunction = !!_path3.find(function (path) {
return path.node === targetFuncPath.node;

@@ -257,3 +258,3 @@ });

var status = this._guessExecutionStatusRelativeTo(_path);
var status = this._guessExecutionStatusRelativeTo(_path3);

@@ -260,0 +261,0 @@ if (allStatus) {

@@ -12,2 +12,3 @@ "use strict";

exports.insertAfter = insertAfter;
exports._insertAfter = _insertAfter;
exports.updateSiblingKeys = updateSiblingKeys;

@@ -107,4 +108,5 @@ exports._verifyNodeList = _verifyNodeList;

var context = _ref;
context.maybeQueue(_path, true);
var _context = _ref;
_context.maybeQueue(_path, true);
}

@@ -125,2 +127,10 @@ }

function insertAfter(nodes) {
return this._insertAfter(nodes);
}
function _insertAfter(nodes, shouldRequeue) {
if (shouldRequeue === void 0) {
shouldRequeue = false;
}
this._assertUnremoved();

@@ -131,3 +141,3 @@

if (this.parentPath.isExpressionStatement() || this.parentPath.isLabeledStatement()) {
return this.parentPath.insertAfter(nodes);
return this.parentPath._insertAfter(nodes, true);
} else if (this.isNodeType("Expression") || this.parentPath.isForStatement() && this.key === "init") {

@@ -149,2 +159,6 @@ if (this.node) {

this._replaceWith(t.blockStatement(nodes));
if (shouldRequeue) {
this.requeue();
}
} else {

@@ -186,3 +200,3 @@ throw new Error("We don't know what to do with this node type. " + "We were previously a Statement but we can't fit in here?");

msg = "has falsy node";
} else if ((typeof node === "undefined" ? "undefined" : _typeof(node)) !== "object") {
} else if (_typeof(node) !== "object") {
msg = "contains a non-object node";

@@ -196,3 +210,3 @@ } else if (!node.type) {

if (msg) {
var type = Array.isArray(node) ? "array" : typeof node === "undefined" ? "undefined" : _typeof(node);
var type = Array.isArray(node) ? "array" : _typeof(node);
throw new Error("Node list " + msg + " with the index of " + i + " and type of " + type);

@@ -238,6 +252,9 @@ }

function hoist() {
var scope = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.scope;
function hoist(scope) {
if (scope === void 0) {
scope = this.scope;
}
var hoister = new _hoister2.default(this, scope);
return hoister.run();
}

@@ -203,5 +203,6 @@ "use strict";

var path = _ref;
if (!path.isExpressionStatement()) continue;
var loop = path.findParent(function (path) {
var _path = _ref;
if (!_path.isExpressionStatement()) continue;
var loop = _path.findParent(function (path) {
return path.isLoop();

@@ -222,5 +223,5 @@ });

path.get("expression").replaceWith(t.assignmentExpression("=", uid, path.node.expression));
_path.get("expression").replaceWith(t.assignmentExpression("=", uid, _path.node.expression));
} else {
path.replaceWith(t.returnStatement(path.node.expression));
_path.replaceWith(t.returnStatement(_path.node.expression));
}

@@ -227,0 +228,0 @@ }

@@ -67,4 +67,4 @@ "use strict";

var scope = _ref;
if (scope.parent === parentScope && scope.path === path) return scope;
var _scope = _ref;
if (_scope.parent === parentScope && _scope.path === path) return _scope;
}

@@ -145,3 +145,3 @@

if (left.isPattern() || left.isIdentifier()) {
state.constantViolations.push(left);
state.constantViolations.push(path);
}

@@ -184,7 +184,7 @@ },

UpdateExpression: function UpdateExpression(path, state) {
state.constantViolations.push(path.get("argument"));
state.constantViolations.push(path);
},
UnaryExpression: function UnaryExpression(path, state) {
if (path.node.operator === "delete") {
state.constantViolations.push(path.get("argument"));
state.constantViolations.push(path);
}

@@ -238,4 +238,7 @@ },

Scope.prototype.generateDeclaredUidIdentifier = function generateDeclaredUidIdentifier() {
var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "temp";
Scope.prototype.generateDeclaredUidIdentifier = function generateDeclaredUidIdentifier(name) {
if (name === void 0) {
name = "temp";
}
var id = this.generateUidIdentifier(name);

@@ -248,9 +251,15 @@ this.push({

Scope.prototype.generateUidIdentifier = function generateUidIdentifier() {
var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "temp";
Scope.prototype.generateUidIdentifier = function generateUidIdentifier(name) {
if (name === void 0) {
name = "temp";
}
return t.identifier(this.generateUid(name));
};
Scope.prototype.generateUid = function generateUid() {
var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "temp";
Scope.prototype.generateUid = function generateUid(name) {
if (name === void 0) {
name = "temp";
}
name = t.toIdentifier(name).replace(/^_+/, "").replace(/[0-9]+$/g, "");

@@ -328,2 +337,3 @@ var uid = void 0;

if (kind === "param") return;
if (local.kind === "local") return;
if (kind === "hoisted" && local.kind === "let") return;

@@ -361,5 +371,5 @@ var duplicate = kind === "let" || local.kind === "let" || local.kind === "const" || local.kind === "module" || local.kind === "param" && (kind === "let" || kind === "const");

for (var name in scope.bindings) {
var binding = scope.bindings[name];
console.log(" -", name, {
for (var _name in scope.bindings) {
var binding = scope.bindings[_name];
console.log(" -", _name, {
constant: binding.constant,

@@ -467,4 +477,4 @@ references: binding.references,

for (var name in ids) {
var binding = this.getBinding(name);
for (var _name2 in ids) {
var binding = this.getBinding(_name2);
if (binding) binding.reassign(path);

@@ -474,4 +484,7 @@ }

Scope.prototype.registerBinding = function registerBinding(kind, path) {
var bindingPath = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : path;
Scope.prototype.registerBinding = function registerBinding(kind, path, bindingPath) {
if (bindingPath === void 0) {
bindingPath = path;
}
if (!kind) throw new ReferenceError("no `kind`");

@@ -494,4 +507,4 @@

var declar = _ref2;
this.registerBinding(kind, declar);
var _declar2 = _ref2;
this.registerBinding(kind, _declar2);
}

@@ -505,17 +518,17 @@

for (var name in ids) {
var _arr8 = ids[name];
for (var _name3 in ids) {
var _arr8 = ids[_name3];
for (var _i10 = 0; _i10 < _arr8.length; _i10++) {
var _id3 = _arr8[_i10];
var local = this.getOwnBinding(name);
var local = this.getOwnBinding(_name3);
if (local) {
if (local.identifier === _id3) continue;
this.checkBlockScopedCollisions(local, kind, name, _id3);
this.checkBlockScopedCollisions(local, kind, _name3, _id3);
}
if (local && local.path.isFlow()) local = null;
parent.references[name] = true;
this.bindings[name] = new _binding3.default({
parent.references[_name3] = true;
this.bindings[_name3] = new _binding3.default({
identifier: _id3,

@@ -590,4 +603,4 @@ existing: local,

var method = _ref3;
if (!this.isPure(method, constantsOnly)) return false;
var _method = _ref3;
if (!this.isPure(_method, constantsOnly)) return false;
}

@@ -720,4 +733,4 @@

var param = _ref4;
this.registerBinding("param", param);
var _param = _ref4;
this.registerBinding("param", _param);
}

@@ -753,15 +766,15 @@ }

var _path = _ref5;
var _path3 = _ref5;
var ids = _path.getBindingIdentifiers();
var ids = _path3.getBindingIdentifiers();
var programParent = void 0;
for (var name in ids) {
if (_path.scope.getBinding(name)) continue;
programParent = programParent || _path.scope.getProgramParent();
programParent.addGlobal(ids[name]);
for (var _name4 in ids) {
if (_path3.scope.getBinding(_name4)) continue;
programParent = programParent || _path3.scope.getProgramParent();
programParent.addGlobal(ids[_name4]);
}
_path.scope.registerConstantViolation(_path);
_path3.scope.registerConstantViolation(_path3);
}

@@ -781,9 +794,10 @@

var ref = _ref6;
var binding = ref.scope.getBinding(ref.node.name);
var _ref8 = _ref6;
var binding = _ref8.scope.getBinding(_ref8.node.name);
if (binding) {
binding.reference(ref);
binding.reference(_ref8);
} else {
ref.scope.getProgramParent().addGlobal(ref.node);
_ref8.scope.getProgramParent().addGlobal(_ref8.node);
}

@@ -804,5 +818,5 @@ }

var _path2 = _ref7;
var _path4 = _ref7;
_path2.scope.registerConstantViolation(_path2);
_path4.scope.registerConstantViolation(_path4);
}

@@ -905,5 +919,5 @@ };

do {
for (var name in scope.bindings) {
var binding = scope.bindings[name];
if (binding.kind === kind) ids[name] = binding;
for (var _name5 in scope.bindings) {
var binding = scope.bindings[_name5];
if (binding.kind === kind) ids[_name5] = binding;
}

@@ -910,0 +924,0 @@

@@ -54,4 +54,4 @@ "use strict";

var part = _ref;
visitor[part] = fns;
var _part = _ref;
visitor[_part] = fns;
}

@@ -123,4 +123,4 @@ }

var alias = _ref2;
var existing = visitor[alias];
var _alias = _ref2;
var existing = visitor[_alias];

@@ -130,3 +130,3 @@ if (existing) {

} else {
visitor[alias] = (0, _clone2.default)(_fns2);
visitor[_alias] = (0, _clone2.default)(_fns2);
}

@@ -164,3 +164,3 @@ }

if ((typeof visitors === "undefined" ? "undefined" : _typeof(visitors)) === "object") {
if (_typeof(visitors) === "object") {
for (var visitorKey in visitors) {

@@ -194,6 +194,6 @@ if (visitorKey === "enter" || visitorKey === "exit") {

var fn = _ref3;
var _fn = _ref3;
if (typeof fn !== "function") {
throw new TypeError("Non-function found defined in " + path + " with type " + (typeof fn === "undefined" ? "undefined" : _typeof(fn)));
if (typeof _fn !== "function") {
throw new TypeError("Non-function found defined in " + path + " with type " + _typeof(_fn));
}

@@ -203,5 +203,7 @@ }

function merge(visitors) {
var states = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
var wrapper = arguments[2];
function merge(visitors, states, wrapper) {
if (states === void 0) {
states = [];
}
var rootVisitor = {};

@@ -208,0 +210,0 @@

{
"name": "babel-traverse",
"version": "7.0.0-alpha.19",
"version": "7.0.0-alpha.20",
"description": "The Babel Traverse module maintains the overall tree state, and is responsible for replacing, removing, and adding nodes",

@@ -11,7 +11,7 @@ "author": "Sebastian McKenzie <sebmck@gmail.com>",

"dependencies": {
"babel-code-frame": "7.0.0-alpha.19",
"babel-helper-function-name": "7.0.0-alpha.19",
"babel-messages": "7.0.0-alpha.19",
"babel-types": "7.0.0-alpha.19",
"babylon": "7.0.0-beta.19",
"babel-code-frame": "7.0.0-alpha.20",
"babel-helper-function-name": "7.0.0-alpha.20",
"babel-messages": "7.0.0-alpha.20",
"babel-types": "7.0.0-alpha.20",
"babylon": "7.0.0-beta.22",
"debug": "^2.2.0",

@@ -23,5 +23,5 @@ "globals": "^10.0.0",

"devDependencies": {
"babel-generator": "7.0.0-alpha.19",
"babel-helper-plugin-test-runner": "7.0.0-alpha.19"
"babel-generator": "7.0.0-alpha.20",
"babel-helper-plugin-test-runner": "7.0.0-alpha.20"
}
}
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