Socket
Socket
Sign inDemoInstall

@babel/traverse

Package Overview
Dependencies
31
Maintainers
4
Versions
172
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 7.23.2 to 7.23.3

6

lib/cache.js

@@ -12,6 +12,4 @@ "use strict";

exports.scope = exports.path = void 0;
let pathsCache = new WeakMap();
exports.path = pathsCache;
let scope = new WeakMap();
exports.scope = scope;
let pathsCache = exports.path = new WeakMap();
let scope = exports.scope = new WeakMap();
function clear() {

@@ -18,0 +16,0 @@ clearPath();

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

}
var _default = traverse;
exports.default = _default;
var _default = exports.default = traverse;
traverse.visitors = visitors;

@@ -58,0 +57,0 @@ traverse.verify = visitors.verify;

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

this.scope = this.getScope(target);
(_this$scope = this.scope) == null ? void 0 : _this$scope.init();
(_this$scope = this.scope) == null || _this$scope.init();
}

@@ -123,0 +123,0 @@ function setContext(context) {

@@ -31,8 +31,5 @@ "use strict";

const debug = _debug("babel");
const REMOVED = 1 << 0;
exports.REMOVED = REMOVED;
const SHOULD_STOP = 1 << 1;
exports.SHOULD_STOP = SHOULD_STOP;
const SHOULD_SKIP = 1 << 2;
exports.SHOULD_SKIP = SHOULD_SKIP;
const REMOVED = exports.REMOVED = 1 << 0;
const SHOULD_STOP = exports.SHOULD_STOP = 1 << 1;
const SHOULD_SKIP = exports.SHOULD_SKIP = 1 << 2;
class NodePath {

@@ -191,5 +188,4 @@ constructor(hub, parent) {

}
var _default = NodePath;
exports.default = _default;
var _default = exports.default = NodePath;
//# sourceMappingURL=index.js.map

@@ -51,4 +51,3 @@ "use strict";

}
const is = has;
exports.is = is;
const is = exports.is = has;
function isnt(key) {

@@ -55,0 +54,0 @@ return !this.has(key);

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

exports.hooks = void 0;
const hooks = [function (self, parent) {
const hooks = exports.hooks = [function (self, parent) {
const removeParent = self.key === "test" && (parent.isWhile() || parent.isSwitchCase()) || self.key === "declaration" && parent.isExportDeclaration() || self.key === "body" && parent.isLabeledStatement() || self.listKey === "declarations" && parent.isVariableDeclaration() && parent.node.declarations.length === 1 || self.key === "expression" && parent.isExpressionStatement();

@@ -37,4 +37,3 @@ if (removeParent) {

}];
exports.hooks = hooks;
//# sourceMappingURL=removal-hooks.js.map

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

exports.Var = exports.User = exports.Statement = exports.SpreadProperty = exports.Scope = exports.RestProperty = exports.ReferencedMemberExpression = exports.ReferencedIdentifier = exports.Referenced = exports.Pure = exports.NumericLiteralTypeAnnotation = exports.Generated = exports.ForAwaitStatement = exports.Flow = exports.Expression = exports.ExistentialTypeParam = exports.BlockScoped = exports.BindingIdentifier = void 0;
const ReferencedIdentifier = ["Identifier", "JSXIdentifier"];
exports.ReferencedIdentifier = ReferencedIdentifier;
const ReferencedMemberExpression = ["MemberExpression"];
exports.ReferencedMemberExpression = ReferencedMemberExpression;
const BindingIdentifier = ["Identifier"];
exports.BindingIdentifier = BindingIdentifier;
const Statement = ["Statement"];
exports.Statement = Statement;
const Expression = ["Expression"];
exports.Expression = Expression;
const Scope = ["Scopable", "Pattern"];
exports.Scope = Scope;
const Referenced = null;
exports.Referenced = Referenced;
const BlockScoped = null;
exports.BlockScoped = BlockScoped;
const Var = ["VariableDeclaration"];
exports.Var = Var;
const User = null;
exports.User = User;
const Generated = null;
exports.Generated = Generated;
const Pure = null;
exports.Pure = Pure;
const Flow = ["Flow", "ImportDeclaration", "ExportDeclaration", "ImportSpecifier"];
exports.Flow = Flow;
const RestProperty = ["RestElement"];
exports.RestProperty = RestProperty;
const SpreadProperty = ["RestElement"];
exports.SpreadProperty = SpreadProperty;
const ExistentialTypeParam = ["ExistsTypeAnnotation"];
exports.ExistentialTypeParam = ExistentialTypeParam;
const NumericLiteralTypeAnnotation = ["NumberLiteralTypeAnnotation"];
exports.NumericLiteralTypeAnnotation = NumericLiteralTypeAnnotation;
const ForAwaitStatement = ["ForOfStatement"];
exports.ForAwaitStatement = ForAwaitStatement;
const ReferencedIdentifier = exports.ReferencedIdentifier = ["Identifier", "JSXIdentifier"];
const ReferencedMemberExpression = exports.ReferencedMemberExpression = ["MemberExpression"];
const BindingIdentifier = exports.BindingIdentifier = ["Identifier"];
const Statement = exports.Statement = ["Statement"];
const Expression = exports.Expression = ["Expression"];
const Scope = exports.Scope = ["Scopable", "Pattern"];
const Referenced = exports.Referenced = null;
const BlockScoped = exports.BlockScoped = null;
const Var = exports.Var = ["VariableDeclaration"];
const User = exports.User = null;
const Generated = exports.Generated = null;
const Pure = exports.Pure = null;
const Flow = exports.Flow = ["Flow", "ImportDeclaration", "ExportDeclaration", "ImportSpecifier"];
const RestProperty = exports.RestProperty = ["RestElement"];
const SpreadProperty = exports.SpreadProperty = ["RestElement"];
const ExistentialTypeParam = exports.ExistentialTypeParam = ["ExistsTypeAnnotation"];
const NumericLiteralTypeAnnotation = exports.NumericLiteralTypeAnnotation = ["NumberLiteralTypeAnnotation"];
const ForAwaitStatement = exports.ForAwaitStatement = ["ForOfStatement"];
//# sourceMappingURL=virtual-types.js.map

@@ -25,5 +25,8 @@ "use strict";

blockStatement,
buildUndefinedNode,
callExpression,
cloneNode,
conditionalExpression,
expressionStatement,
getBindingIdentifiers,
identifier,

@@ -33,8 +36,13 @@ inheritLeadingComments,

inheritsComments,
isBlockStatement,
isEmptyStatement,
isExpression,
isExpressionStatement,
isIfStatement,
isProgram,
isStatement,
isVariableDeclaration,
removeComments,
returnStatement,
toSequenceExpression,
sequenceExpression,
validate,

@@ -49,3 +57,3 @@ yieldExpression

inheritTrailingComments(nodes[nodes.length - 1], this.node);
(_getCachedPaths = (0, _cache.getCachedPaths)(this.hub, this.parent)) == null ? void 0 : _getCachedPaths.delete(this.node);
(_getCachedPaths = (0, _cache.getCachedPaths)(this.hub, this.parent)) == null || _getCachedPaths.delete(this.node);
this.node = this.container[this.key] = null;

@@ -138,3 +146,3 @@ const paths = this.insertAfter(nodes);

this.debug(`Replace with ${node == null ? void 0 : node.type}`);
(_getCachedPaths2 = (0, _cache.getCachedPaths)(this.hub, this.parent)) == null ? void 0 : _getCachedPaths2.set(node, this).delete(this.node);
(_getCachedPaths2 = (0, _cache.getCachedPaths)(this.hub, this.parent)) == null || _getCachedPaths2.set(node, this).delete(this.node);
this.node = this.container[this.key] = node;

@@ -144,5 +152,9 @@ }

this.resync();
const nodesAsSequenceExpression = toSequenceExpression(nodes, this.scope);
if (nodesAsSequenceExpression) {
return this.replaceWith(nodesAsSequenceExpression)[0].get("expressions");
const declars = [];
const nodesAsSingleExpression = gatherSequenceExpressions(nodes, declars);
if (nodesAsSingleExpression) {
for (const id of declars) this.scope.push({
id
});
return this.replaceWith(nodesAsSingleExpression)[0].get("expressions");
}

@@ -194,2 +206,49 @@ const functionParent = this.getFunctionParent();

}
function gatherSequenceExpressions(nodes, declars) {
const exprs = [];
let ensureLastUndefined = true;
for (const node of nodes) {
if (!isEmptyStatement(node)) {
ensureLastUndefined = false;
}
if (isExpression(node)) {
exprs.push(node);
} else if (isExpressionStatement(node)) {
exprs.push(node.expression);
} else if (isVariableDeclaration(node)) {
if (node.kind !== "var") return;
for (const declar of node.declarations) {
const bindings = getBindingIdentifiers(declar);
for (const key of Object.keys(bindings)) {
declars.push(cloneNode(bindings[key]));
}
if (declar.init) {
exprs.push(assignmentExpression("=", declar.id, declar.init));
}
}
ensureLastUndefined = true;
} else if (isIfStatement(node)) {
const consequent = node.consequent ? gatherSequenceExpressions([node.consequent], declars) : buildUndefinedNode();
const alternate = node.alternate ? gatherSequenceExpressions([node.alternate], declars) : buildUndefinedNode();
if (!consequent || !alternate) return;
exprs.push(conditionalExpression(node.test, consequent, alternate));
} else if (isBlockStatement(node)) {
const body = gatherSequenceExpressions(node.body, declars);
if (!body) return;
exprs.push(body);
} else if (isEmptyStatement(node)) {
if (nodes.indexOf(node) === 0) {
ensureLastUndefined = true;
}
} else {
return;
}
}
if (ensureLastUndefined) exprs.push(buildUndefinedNode());
if (exprs.length === 1) {
return exprs[0];
} else {
return sequenceExpression(exprs);
}
}
function replaceInline(nodes) {

@@ -196,0 +255,0 @@ this.resync();

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

const binding = scope.getBinding(id.name);
binding == null ? void 0 : binding.reference(path);
binding == null || binding.reference(path);
} else if (isVariableDeclaration(declar)) {

@@ -231,3 +231,3 @@ for (const decl of declar.declarations) {

const binding = scope.getBinding(name);
binding == null ? void 0 : binding.reference(path);
binding == null || binding.reference(path);
}

@@ -517,3 +517,3 @@ }

var _this$getBinding;
(_this$getBinding = this.getBinding(name)) == null ? void 0 : _this$getBinding.reassign(path);
(_this$getBinding = this.getBinding(name)) == null || _this$getBinding.reassign(path);
}

@@ -878,3 +878,3 @@ }

var _this$getBinding3;
(_this$getBinding3 = this.getBinding(name)) == null ? void 0 : _this$getBinding3.scope.removeOwnBinding(name);
(_this$getBinding3 = this.getBinding(name)) == null || _this$getBinding3.scope.removeOwnBinding(name);
let scope = this;

@@ -881,0 +881,0 @@ do {

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

var virtualTypes = require("./path/lib/virtual-types.js");
var virtualTypesValidators = require("./path/lib/virtual-types-validator.js");
var _t = require("@babel/types");

@@ -191,4 +192,6 @@ const {

function wrapCheck(nodeType, fn) {
const fnKey = `is${nodeType}`;
const validator = virtualTypesValidators[fnKey];
const newFn = function (path) {
if (path[`is${nodeType}`]()) {
if (validator.call(path)) {
return fn.apply(this, arguments);

@@ -195,0 +198,0 @@ }

{
"name": "@babel/traverse",
"version": "7.23.2",
"version": "7.23.3",
"description": "The Babel Traverse module maintains the overall tree state, and is responsible for replacing, removing, and adding nodes",

@@ -20,3 +20,3 @@ "author": "The Babel Team (https://babel.dev/team)",

"@babel/code-frame": "^7.22.13",
"@babel/generator": "^7.23.0",
"@babel/generator": "^7.23.3",
"@babel/helper-environment-visitor": "^7.22.20",

@@ -26,4 +26,4 @@ "@babel/helper-function-name": "^7.23.0",

"@babel/helper-split-export-declaration": "^7.22.6",
"@babel/parser": "^7.23.0",
"@babel/types": "^7.23.0",
"@babel/parser": "^7.23.3",
"@babel/types": "^7.23.3",
"debug": "^4.1.0",

@@ -33,3 +33,3 @@ "globals": "^11.1.0"

"devDependencies": {
"@babel/core": "^7.23.0",
"@babel/core": "^7.23.3",
"@babel/helper-plugin-test-runner": "^7.22.5"

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc