Socket
Socket
Sign inDemoInstall

@babel/traverse

Package Overview
Dependencies
Maintainers
4
Versions
180
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.20.10 to 7.20.12

16

lib/context.js

@@ -21,15 +21,10 @@ "use strict";

}
shouldVisit(node) {
const opts = this.opts;
if (opts.enter || opts.exit) return true;
if (opts[node.type]) return true;
const keys = VISITOR_KEYS[node.type];
if (!(keys != null && keys.length)) return false;
for (const key of keys) {
if (
node[key]) {
if (node[key]) {
return true;

@@ -61,3 +56,2 @@ }

const queue = [];
for (let key = 0; key < container.length; key++) {

@@ -72,4 +66,3 @@ const node = container[key];

visitSingle(node, key) {
if (this.shouldVisit(
node[key])) {
if (this.shouldVisit(node[key])) {
return this.visitQueue([this.create(node, node, key)]);

@@ -85,3 +78,2 @@ } else {

let stop = false;
for (const path of queue) {

@@ -92,5 +84,3 @@ path.resync();

}
if (path.key === null) continue;
const {

@@ -112,7 +102,5 @@ node

}
for (const path of queue) {
path.popContext();
}
this.queue = null;

@@ -119,0 +107,0 @@ return stop;

5

lib/index.js

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

} = _t;
function traverse(parent,
opts = {}, scope, state, parentPath) {
function traverse(parent, opts = {}, scope, state, parentPath) {
if (!parent) return;

@@ -64,3 +63,2 @@ if (!opts.noScope && !scope) {

};
traverse.clearNode = function (node, opts) {

@@ -82,3 +80,2 @@ removeProperties(node, opts);

if (denylistTypes != null && denylistTypes.includes(tree.type)) return false;
if (tree.type === type) return true;

@@ -85,0 +82,0 @@ const state = {

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

} = _t;
function findParent(callback) {

@@ -29,3 +28,2 @@ let path = this;

}
function find(callback) {

@@ -38,7 +36,5 @@ let path = this;

}
function getFunctionParent() {
return this.findParent(p => p.isFunction());
}
function getStatementParent() {

@@ -58,3 +54,2 @@ let path = this;

}
function getEarliestCommonAncestorFrom(paths) {

@@ -66,3 +61,2 @@ return this.getDeepestCommonAncestorFrom(paths, function (deepest, i, ancestries) {

const path = ancestry[i + 1];
if (!earliest) {

@@ -72,3 +66,2 @@ earliest = path;

}
if (path.listKey && earliest.listKey === path.listKey) {

@@ -80,3 +73,2 @@ if (path.key < earliest.key) {

}
const earliestKeyIndex = keys.indexOf(earliest.parentKey);

@@ -91,3 +83,2 @@ const currentKeyIndex = keys.indexOf(path.parentKey);

}
function getDeepestCommonAncestorFrom(paths, filter) {

@@ -100,7 +91,4 @@ if (!paths.length) {

}
let minDepth = Infinity;
let lastCommonIndex, lastCommon;
const ancestries = paths.map(path => {

@@ -111,3 +99,2 @@ const ancestry = [];

} while ((path = path.parentPath) && path !== this);
if (ancestry.length < minDepth) {

@@ -118,5 +105,3 @@ minDepth = ancestry.length;

});
const first = ancestries[0];
depthLoop: for (let i = 0; i < minDepth; i++) {

@@ -129,3 +114,2 @@ const shouldMatch = first[i];

}
lastCommonIndex = i;

@@ -144,3 +128,2 @@ lastCommon = shouldMatch;

}
function getAncestry() {

@@ -154,7 +137,5 @@ let path = this;

}
function isAncestor(maybeDescendant) {
return maybeDescendant.isDescendant(this);
}
function isDescendant(maybeAncestor) {

@@ -161,0 +142,0 @@ return !!this.findParent(parent => parent === maybeAncestor);

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

} = _t;
function shareCommentsWithSiblings() {

@@ -36,3 +35,2 @@ if (typeof this.key === "string") return;

}
function addComments(type, comments) {

@@ -39,0 +37,0 @@ _addComments(this.node, type, comments);

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

var _index = require("./index");
function call(key) {

@@ -54,5 +53,3 @@ const opts = this.opts;

}
if (this.node !== node) return true;
if (this._traverseFlags > 0) return true;

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

}
function restoreContext(path, context) {

@@ -113,5 +109,3 @@ if (path.context !== context) {

let path = this.parentPath;
if (
(this.key === "key" || this.listKey === "decorators") && path.isMethod() ||
this.key === "discriminant" && path.isSwitchStatement()) {
if ((this.key === "key" || this.listKey === "decorators") && path.isMethod() || this.key === "discriminant" && path.isSwitchStatement()) {
path = path.parentPath;

@@ -141,3 +135,2 @@ }

}
function resync() {

@@ -149,3 +142,2 @@ if (this.removed) return;

}
function _resyncParent() {

@@ -158,7 +150,5 @@ if (this.parentPath) {

if (!this.container) return;
if (this.node ===
this.container[this.key]) {
if (this.node === this.container[this.key]) {
return;
}
if (Array.isArray(this.container)) {

@@ -177,3 +167,2 @@ for (let i = 0; i < this.container.length; i++) {

}
this.key = null;

@@ -183,11 +172,8 @@ }

if (!this.parent || !this.inList) return;
const newContainer =
this.parent[this.listKey];
const newContainer = this.parent[this.listKey];
if (this.container === newContainer) return;
this.container = newContainer || null;
}
function _resyncRemoved() {
if (this.key == null || !this.container ||
this.container[this.key] !== this.node) {
if (this.key == null || !this.container || this.container[this.key] !== this.node) {
this._markRemoved();

@@ -217,4 +203,3 @@ }

this.key = key;
this.node =
this.container[this.key];
this.node = this.container[this.key];
this.type = (_this$node = this.node) == null ? void 0 : _this$node.type;

@@ -224,3 +209,2 @@ }

if (pathToQueue.removed) return;
;

@@ -227,0 +211,0 @@ const contexts = this.contexts;

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

}
if (!this.node.computed) {

@@ -90,7 +89,5 @@ if (isIdentifier(key)) key = stringLiteral(key.name);

const parentPath = this.get(stringPath);
body.setup(parentPath, listKey ?
parentPath.node[listKey] : parentPath.node, listKey, key);
body.setup(parentPath, listKey ? parentPath.node[listKey] : parentPath.node, listKey, key);
return this.node;
}
function arrowFunctionToShadowed() {

@@ -100,3 +97,2 @@ if (!this.isArrowFunctionExpression()) return;

}
function unwrapFunctionEnvironment() {

@@ -111,3 +107,2 @@ if (!this.isArrowFunctionExpression() && !this.isFunctionExpression() && !this.isFunctionDeclaration()) {

}
function arrowFunctionToExpression({

@@ -126,3 +121,2 @@ allowInsertArrow = true,

} = hoistFunctionEnvironment(this, noNewArrows, allowInsertArrow, allowInsertArrowWithRest);
fn.ensureBlock();

@@ -139,4 +133,3 @@ setType(fn, "FunctionExpression");

fn.get("body").unshiftContainer("body", expressionStatement(callExpression(this.hub.addHelper("newArrowCheck"), [thisExpression(), checkBinding ? identifier(checkBinding.name) : identifier(thisBinding)])));
fn.replaceWith(callExpression(memberExpression(
(0, _helperFunctionName.default)(this, true) || fn.node, identifier("bind")), [checkBinding ? identifier(checkBinding.name) : thisExpression()]));
fn.replaceWith(callExpression(memberExpression((0, _helperFunctionName.default)(this, true) || fn.node, identifier("bind")), [checkBinding ? identifier(checkBinding.name) : thisExpression()]));
return fn.get("callee.object");

@@ -154,5 +147,3 @@ }

}, _helperEnvironmentVisitor.default]);
function hoistFunctionEnvironment(fnPath,
noNewArrows = true, allowInsertArrow = true, allowInsertArrowWithRest = true) {
function hoistFunctionEnvironment(fnPath, noNewArrows = true, allowInsertArrow = true, allowInsertArrowWithRest = true) {
let arrowParent;

@@ -192,3 +183,2 @@ let thisEnvFn = fnPath.findParent(p => {

} = getScopeInformation(fnPath);
if (inConstructor && superCalls.length > 0) {

@@ -212,3 +202,2 @@ if (!allowInsertArrow) {

}
if (argumentsPaths.length > 0) {

@@ -229,3 +218,2 @@ const argumentsBinding = getBinding(thisEnvFn, "arguments", () => {

}
if (newTargetPaths.length > 0) {

@@ -239,3 +227,2 @@ const newTargetBinding = getBinding(thisEnvFn, "newtarget", () => metaProperty(identifier("new"), identifier("target")));

}
if (superProps.length > 0) {

@@ -247,4 +234,3 @@ if (!allowInsertArrow) {

flatSuperProps.forEach(superProp => {
const key = superProp.node.computed ? "" :
superProp.get("property").node.name;
const key = superProp.node.computed ? "" : superProp.get("property").node.name;
const superParentPath = superProp.parentPath;

@@ -284,8 +270,6 @@ const isAssignment = superParentPath.isAssignmentExpression({

}
let thisBinding;
if (thisPaths.length > 0 || !noNewArrows) {
thisBinding = getThisBinding(thisEnvFn, inConstructor);
if (noNewArrows ||
inConstructor && hasSuperClass(thisEnvFn)) {
if (noNewArrows || inConstructor && hasSuperClass(thisEnvFn)) {
thisPaths.forEach(thisChild => {

@@ -314,3 +298,2 @@ const thisRef = thisChild.isJSX() ? jsxIdentifier(thisBinding) : identifier(thisBinding);

if (superProp.node.computed) {
const tmp = superProp.scope.generateDeclaredUidIdentifier("tmp");

@@ -320,6 +303,4 @@ const object = superProp.node.object;

assignmentPath.get("left").replaceWith(memberExpression(object, assignmentExpression("=", tmp, property), true));
assignmentPath.get("right").replaceWith(rightExpression(isLogicalAssignment ? "=" : op, memberExpression(object, identifier(tmp.name), true), value));
} else {
const object = superProp.node.object;

@@ -340,4 +321,3 @@ const property = superProp.node.property;

const computedKey = superProp.node.computed ? superProp.scope.generateDeclaredUidIdentifier("prop") : null;
const parts = [assignmentExpression("=", tmp, memberExpression(superProp.node.object, computedKey ? assignmentExpression("=", computedKey, superProp.node.property) : superProp.node.property, superProp.node.computed)), assignmentExpression("=", memberExpression(superProp.node.object, computedKey ? identifier(computedKey.name) : superProp.node.property, superProp.node.computed), binaryExpression(
superProp.parentPath.node.operator[0], identifier(tmp.name), numericLiteral(1)))];
const parts = [assignmentExpression("=", tmp, memberExpression(superProp.node.object, computedKey ? assignmentExpression("=", computedKey, superProp.node.property) : superProp.node.property, superProp.node.computed)), assignmentExpression("=", memberExpression(superProp.node.object, computedKey ? identifier(computedKey.name) : superProp.node.property, superProp.node.computed), binaryExpression(superProp.parentPath.node.operator[0], identifier(tmp.name), numericLiteral(1)))];
if (!superProp.parentPath.node.prefix) {

@@ -374,3 +354,2 @@ parts.push(identifier(tmp.name));

}, _helperEnvironmentVisitor.default]);
function getThisBinding(thisEnvFn, inConstructor) {

@@ -385,3 +364,2 @@ return getBinding(thisEnvFn, "this", thisBinding => {

}
function getSuperBinding(thisEnvFn) {

@@ -393,3 +371,2 @@ return getBinding(thisEnvFn, "supercall", () => {

}
function getSuperPropBinding(thisEnvFn, isAssignment, propName) {

@@ -407,3 +384,2 @@ const op = isAssignment ? "set" : "get";

}
if (isAssignment) {

@@ -410,0 +386,0 @@ const valueIdent = thisEnvFn.scope.generateUidIdentifier("value");

@@ -8,14 +8,10 @@ "use strict";

exports.evaluateTruthy = evaluateTruthy;
const VALID_CALLEES = ["String", "Number", "Math"];
const INVALID_METHODS = ["random"];
function isValidCallee(val) {
return VALID_CALLEES.includes(
val);
return VALID_CALLEES.includes(val);
}
function isInvalidMethod(val) {
return INVALID_METHODS.includes(
val);
return INVALID_METHODS.includes(val);
}
function evaluateTruthy() {

@@ -30,3 +26,2 @@ const res = this.evaluate();

}
function evaluateCached(path, state) {

@@ -83,4 +78,3 @@ const {

const property = path.get("tag.property");
if (object.isIdentifier() && name === "String" &&
!path.scope.getBinding(name) && property.isIdentifier() && property.node.name === "raw") {
if (object.isIdentifier() && name === "String" && !path.scope.getBinding(name) && property.isIdentifier() && property.node.name === "raw") {
return evaluateQuasis(path, path.node.quasi.quasis, state, true);

@@ -101,3 +95,2 @@ }

}
if (path.isMemberExpression() && !path.parentPath.isCallExpression({

@@ -108,8 +101,15 @@ callee: path.node

const object = path.get("object");
if (object.isLiteral() && property.isIdentifier()) {
if (object.isLiteral()) {
const value = object.node.value;
const type = typeof value;
if (type === "number" || type === "string") {
return value[property.node.name];
let key = null;
if (path.node.computed) {
key = evaluateCached(property, state);
if (!state.confident) return;
} else if (property.isIdentifier()) {
key = property.node.name;
}
if ((type === "number" || type === "string") && key != null && (typeof key === "number" || typeof key === "string")) {
return value[key];
}
}

@@ -285,3 +285,2 @@ }

let func;
if (callee.isIdentifier() && !path.scope.getBinding(callee.node.name) && isValidCallee(callee.node.name)) {

@@ -293,3 +292,2 @@ func = global[callee.node.name];

const property = callee.get("property");
if (object.isIdentifier() && property.isIdentifier() && isValidCallee(object.node.name) && !isInvalidMethod(property.node.name)) {

@@ -299,3 +297,2 @@ context = global[object.node.name];

}
if (object.isLiteral() && property.isIdentifier()) {

@@ -320,8 +317,6 @@ const type = typeof object.node.value;

let i = 0;
const exprs = path.get("expressions");
const exprs = path.isTemplateLiteral() ? path.get("expressions") : path.get("quasi.expressions");
for (const elem of quasis) {
if (!state.confident) break;
str += raw ? elem.value.raw : elem.value.cooked;
const expr = exprs[i++];

@@ -333,3 +328,2 @@ if (expr) str += String(evaluateCached(expr, state));

}
function evaluate() {

@@ -336,0 +330,0 @@ const state = {

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

}
function replaceBreakStatementInBreakCompletion(completions, reachable) {

@@ -109,4 +108,3 @@ completions.forEach(c => {

});
if (path.isBlockStatement() && (context.inCaseClause ||
context.shouldPopulateBreak)) {
if (path.isBlockStatement() && (context.inCaseClause || context.shouldPopulateBreak)) {
newContext.shouldPopulateBreak = true;

@@ -117,4 +115,3 @@ } else {

const statementCompletions = _getCompletionRecords(path, newContext);
if (statementCompletions.length > 0 &&
statementCompletions.every(c => c.type === BREAK_COMPLETION)) {
if (statementCompletions.length > 0 && statementCompletions.every(c => c.type === BREAK_COMPLETION)) {
if (lastNormalCompletions.length > 0 && statementCompletions.every(c => c.path.isBreakStatement({

@@ -195,3 +192,2 @@ label: null

}
function getCompletionRecords() {

@@ -240,3 +236,2 @@ const records = _getCompletionRecords(this, {

}
function get(key, context = true) {

@@ -302,4 +297,3 @@ if (context === true) context = this.context;

if (!id.node) continue;
const keys =
_getBindingIdentifiers.keys[id.node.type];
const keys = _getBindingIdentifiers.keys[id.node.type];
if (id.isIdentifier()) {

@@ -306,0 +300,0 @@ if (duplicates) {

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

}
const targetNode =
container[key];
const targetNode = container[key];
let paths = _cache.path.get(parent);

@@ -141,3 +140,2 @@ if (!paths) {

}
get parentKey() {

@@ -181,3 +179,2 @@ return this.listKey || this.key;

}
for (const type of t.TYPES) {

@@ -189,3 +186,2 @@ const typeKey = `is${type}`;

};
NodePath.prototype[`assert${type}`] = function (opts) {

@@ -197,3 +193,2 @@ if (!fn(this.node, opts)) {

}
Object.assign(NodePath.prototype, NodePath_virtual_types_validator);

@@ -200,0 +195,0 @@ for (const type of Object.keys(virtualTypes)) {

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

} = _t;
function getTypeAnnotation() {

@@ -50,5 +49,3 @@ let type = this.getData("typeAnnotation");

}
const typeAnnotationInferringNodes = new WeakSet();
function _getTypeAnnotation() {

@@ -60,7 +57,5 @@ const node = this.node;

const declarParent = declar.parentPath;
if (declar.key === "left" && declarParent.isForInStatement()) {
return stringTypeAnnotation();
}
if (declar.key === "left" && declarParent.isForOfStatement()) {

@@ -74,3 +69,2 @@ return anyTypeAnnotation();

}
if (node.typeAnnotation) {

@@ -85,8 +79,6 @@ return node.typeAnnotation;

var _inferer;
let inferer =
inferers[node.type];
let inferer = inferers[node.type];
if (inferer) {
return inferer.call(this, node);
}
inferer = inferers[this.parentPath.type];

@@ -93,0 +85,0 @@ if ((_inferer = inferer) != null && _inferer.validParent) {

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

if (!this.isReferenced()) return;
const binding = this.scope.getBinding(node.name);

@@ -27,3 +26,2 @@ if (binding) {

}
if (node.name === "undefined") {

@@ -33,6 +31,4 @@ return voidTypeAnnotation();

return numberTypeAnnotation();
} else if (node.name === "arguments") {
}
} else if (node.name === "arguments") {}
}
function getTypeAnnotationBindingConstantViolations(binding, path, name) {

@@ -45,11 +41,7 @@ const types = [];

const testConstantViolations = getConstantViolationsBefore(binding, testType.ifStatement);
constantViolations = constantViolations.filter(path => testConstantViolations.indexOf(path) < 0);
types.push(testType.typeAnnotation);
}
if (constantViolations.length) {
constantViolations.push(...functionConstantViolations);
for (const violation of constantViolations) {

@@ -98,3 +90,2 @@ types.push(violation.getTypeAnnotation());

if (operator !== "===" && operator !== "==") return;
let typeofPath;

@@ -117,9 +108,6 @@ let typePath;

})) return;
typePath = typePath.resolve();
if (!typePath.isLiteral()) return;
const typeValue = typePath.node.value;
if (typeof typeValue !== "string") return;
return createTypeAnnotationBasedOnTypeof(typeValue);

@@ -126,0 +114,0 @@ }

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

}
return unionTypeAnnotation([stringTypeAnnotation(), numberTypeAnnotation()]);

@@ -175,4 +174,3 @@ }

return arrayTypeAnnotation(stringTypeAnnotation());
} else if (isArrayFrom(callee) || isObjectValues(callee) ||
isIdentifier(callee, {
} else if (isArrayFrom(callee) || isObjectValues(callee) || isIdentifier(callee, {
name: "Array"

@@ -206,4 +204,3 @@ })) {

return callee.node.returnType;
} else {
}
} else {}
}

@@ -210,0 +207,0 @@ }

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

} = _t;
function matchesPattern(pattern, allowPartial) {
return _matchesPattern(this.node, pattern, allowPartial);
}
function has(key) {

@@ -51,27 +49,19 @@ const val = this.node && this.node[key];

}
function isStatic() {
return this.scope.isStatic(this.node);
}
const is = has;
exports.is = is;
function isnt(key) {
return !this.has(key);
}
function equals(key, value) {
return this.node[key] === value;
}
function isNodeType(type) {
return isType(this.type, type);
}
function canHaveVariableDeclarationOrExpression() {
return (this.key === "init" || this.key === "left") && this.parentPath.isFor();
}
function canSwapBetweenExpressionAndStatement(replacement) {

@@ -88,3 +78,2 @@ if (this.key !== "body" || !this.parentPath.isArrowFunctionExpression()) {

}
function isCompletionRecord(allowInsideFunction) {

@@ -98,3 +87,2 @@ let path = this;

} = path;
if (!first && (path.isFunction() || type === "StaticBlock")) {

@@ -104,3 +92,2 @@ return !!allowInsideFunction;

first = false;
if (Array.isArray(container) && path.key !== container.length - 1) {

@@ -112,3 +99,2 @@ return false;

}
function isStatementOrBlock() {

@@ -121,3 +107,2 @@ if (this.parentPath.isLabeledStatement() || isBlockStatement(this.container)) {

}
function referencesImport(moduleSource, importName) {

@@ -138,3 +123,2 @@ if (!this.isReferencedIdentifier()) {

if (!parent.isImportDeclaration()) return false;
if (parent.node.source.value === moduleSource) {

@@ -158,3 +142,2 @@ if (!importName) return true;

}
function getSource() {

@@ -178,7 +161,5 @@ const node = this.node;

return key === "right";
case "ConditionalExpression":
case "IfStatement":
return key === "consequent" || key === "alternate";
case "WhileStatement":

@@ -189,18 +170,12 @@ case "DoWhileStatement":

return key === "body";
case "ForStatement":
return key === "body" || key === "update";
case "SwitchStatement":
return key === "cases";
case "TryStatement":
return key === "handler";
case "AssignmentPattern":
return key === "right";
case "OptionalMemberExpression":
return key === "property";
case "OptionalCallExpression":

@@ -221,5 +196,3 @@ return key === "arguments";

}
const SYMBOL_CHECKING = Symbol();
function _guessExecutionStatusRelativeTo(target) {

@@ -233,3 +206,2 @@ return _guessExecutionStatusRelativeToCached(this, target, new Map());

};
if (funcParent.target.node !== funcParent.this.node) {

@@ -242,6 +214,4 @@ return _guessExecutionStatusRelativeToDifferentFunctionsCached(base, funcParent.target, cache);

};
if (paths.target.indexOf(base) >= 0) return "after";
if (paths.this.indexOf(target) >= 0) return "before";
let commonPath;

@@ -271,7 +241,5 @@ const commonIndex = {

};
if (divergence.target.listKey && divergence.this.listKey && divergence.target.container === divergence.this.container) {
return divergence.target.key > divergence.this.key ? "before" : "after";
}
const keys = VISITOR_KEYS[commonPath.type];

@@ -293,9 +261,6 @@ const keyPosition = {

}
const binding = target.scope.getBinding(target.node.id.name);
if (!binding.references) return "before";
const referencePaths = binding.referencePaths;
let allStatus;
for (const path of referencePaths) {

@@ -332,3 +297,2 @@ const childOfFunction = !!path.find(path => path.node === target.node);

}
function resolve(dangerous, resolved) {

@@ -339,3 +303,2 @@ return this._resolve(dangerous, resolved) || this;

if (resolved && resolved.indexOf(this) >= 0) return;
resolved = resolved || [];

@@ -346,10 +309,7 @@ resolved.push(this);

return this.get("init").resolve(dangerous, resolved);
} else {
}
} else {}
} else if (this.isReferencedIdentifier()) {
const binding = this.scope.getBinding(this.node.name);
if (!binding) return;
if (!binding.constant) return;
if (binding.kind === "module") return;

@@ -364,6 +324,4 @@ if (binding.path !== this) {

} else if (dangerous && this.isMemberExpression()) {
const targetKey = this.toComputedKey();
if (!isLiteral(targetKey)) return;
const targetName = targetKey.value;

@@ -376,7 +334,5 @@ const target = this.get("object").resolve(dangerous, resolved);

const key = prop.get("key");
let match = prop.isnt("computed") && key.isIdentifier({
name: targetName
});
match = match || key.isLiteral({

@@ -383,0 +339,0 @@ value: targetName

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

}
if (path.node.name === "this") {

@@ -34,6 +33,4 @@ let scope = path.scope;

}
const binding = path.scope.getBinding(path.node.name);
if (!binding) return;
for (const violation of binding.constantViolations) {

@@ -46,3 +43,2 @@ if (violation.scope !== binding.path.scope) {

}
if (binding !== state.scope.getBinding(path.node.name)) return;

@@ -69,3 +65,2 @@ state.bindings[path.node.name] = binding;

}
isCompatibleScope(scope) {

@@ -80,3 +75,2 @@ for (const key of Object.keys(this.bindings)) {

}
getCompatibleScopes() {

@@ -90,3 +84,2 @@ let scope = this.path.scope;

}
if (this.breakOnScopePaths.indexOf(scope.path) >= 0) {

@@ -101,7 +94,5 @@ break;

let targetScope = path.scope;
if (targetScope.path === path) {
targetScope = path.scope.parent;
}
if (targetScope.path.isProgram() || targetScope.path.isFunction()) {

@@ -111,13 +102,9 @@ for (const name of Object.keys(this.bindings)) {

const binding = this.bindings[name];
if (binding.kind === "param" || binding.path.parentKey === "params") {
continue;
}
const bindingParentPath = this.getAttachmentParentForPath(binding.path);
if (bindingParentPath.key >= path.key) {
this.attachAfter = true;
path = binding.path;
for (const violationPath of binding.constantViolations) {

@@ -140,3 +127,2 @@ if (this.getAttachmentParentForPath(violationPath).key > path.key) {

if (this.scope === scope) return;
const bodies = scope.path.get("body").get("body");

@@ -158,8 +144,5 @@ for (let i = 0; i < bodies.length; i++) {

}
getAttachmentParentForPath(path) {
do {
if (
!path.parentPath ||
Array.isArray(path.container) && path.isStatement()) {
if (!path.parentPath || Array.isArray(path.container) && path.isStatement()) {
return path;

@@ -169,3 +152,2 @@ }

}
hasOwnParamBindings(scope) {

@@ -185,7 +167,4 @@ for (const name of Object.keys(this.bindings)) {

if (!attachTo) return;
if (attachTo.getFunctionParent() === this.path.getFunctionParent()) return;
let uid = attachTo.scope.generateUidIdentifier("ref");
const declarator = variableDeclarator(uid, this.path.node);

@@ -192,0 +171,0 @@ const insertFn = this.attachAfter ? "insertAfter" : "insertBefore";

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

exports.hooks = void 0;
const 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();
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();
if (removeParent) {

@@ -17,0 +11,0 @@ parent.remove();

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

}
return nodeIsReferenced(node, parent, this.parentPath.parent);

@@ -145,3 +144,2 @@ }

}
function isRestProperty() {

@@ -148,0 +146,0 @@ return nodeIsRestElement(this.node) && this.parentPath && this.parentPath.isObjectPattern();

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

const Flow = ["Flow", "ImportDeclaration", "ExportDeclaration", "ImportSpecifier"];
exports.Flow = Flow;

@@ -35,0 +34,0 @@ const RestProperty = ["RestElement"];

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

} = _t;
function insertBefore(nodes_) {

@@ -46,4 +45,3 @@ this._assertUnremoved();

} = this;
if (parentPath.isExpressionStatement() || parentPath.isLabeledStatement() ||
isExportNamedDeclaration(parent) || parentPath.isExportDefaultDeclaration() && this.isDeclaration()) {
if (parentPath.isExpressionStatement() || parentPath.isLabeledStatement() || isExportNamedDeclaration(parent) || parentPath.isExportDefaultDeclaration() && this.isDeclaration()) {
return parentPath.insertBefore(nodes);

@@ -59,4 +57,3 @@ } else if (this.isNodeType("Expression") && !this.isJSXElement() || parentPath.isForStatement() && this.key === "init") {

this.replaceWith(blockStatement(shouldInsertCurrentNode ? [node] : []));
return this.unshiftContainer("body",
nodes);
return this.unshiftContainer("body", nodes);
} else {

@@ -69,3 +66,2 @@ 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?");

const paths = [];
this.container.splice(from, 0, ...nodes);

@@ -104,8 +100,5 @@ for (let i = 0; i < nodes.length; i++) {

}
const blockScope = scope.getBlockParent();
return blockScope.hasOwnBinding(node.left.name) && blockScope.getOwnBinding(node.left.name).constantViolations.length <= 1;
}
function insertAfter(nodes_) {

@@ -121,4 +114,3 @@ this._assertUnremoved();

} = this;
if (parentPath.isExpressionStatement() || parentPath.isLabeledStatement() ||
isExportNamedDeclaration(parent) || parentPath.isExportDefaultDeclaration() && this.isDeclaration()) {
if (parentPath.isExpressionStatement() || parentPath.isLabeledStatement() || isExportNamedDeclaration(parent) || parentPath.isExportDefaultDeclaration() && this.isDeclaration()) {
return parentPath.insertAfter(nodes.map(node => {

@@ -141,4 +133,3 @@ return isExpression(node) ? expressionStatement(node) : node;

nodes.unshift(node);
}
else if (isCallExpression(node) && isSuper(node.callee)) {
} else if (isCallExpression(node) && isSuper(node.callee)) {
nodes.unshift(node);

@@ -159,4 +150,3 @@ nodes.push(thisExpression());

const temp = scope.generateDeclaredUidIdentifier();
nodes.unshift(expressionStatement(
assignmentExpression("=", cloneNode(temp), node)));
nodes.unshift(expressionStatement(assignmentExpression("=", cloneNode(temp), node)));
nodes.push(expressionStatement(cloneNode(temp)));

@@ -177,3 +167,2 @@ }

}
function updateSiblingKeys(fromIndex, incrementBy) {

@@ -216,5 +205,3 @@ if (!this.parent) return;

this._assertUnremoved();
nodes = this._verifyNodeList(nodes);
const path = _index.default.get({

@@ -227,10 +214,7 @@ parentPath: this,

}).setContext(this.context);
return path._containerInsertBefore(
nodes);
return path._containerInsertBefore(nodes);
}
function pushContainer(listKey, nodes) {
this._assertUnremoved();
const verifiedNodes = this._verifyNodeList(
nodes);
const verifiedNodes = this._verifyNodeList(nodes);
const container = this.node[listKey];

@@ -246,3 +230,2 @@ const path = _index.default.get({

}
function hoist(scope = this.scope) {

@@ -249,0 +232,0 @@ const hoister = new _hoister.default(this, scope);

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

var _index = require("./index");
function remove() {

@@ -18,0 +17,0 @@ var _this$opts;

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

} = _t;
function replaceWithMultiple(nodes) {

@@ -50,4 +49,3 @@ var _pathCache$get;

(_pathCache$get = _cache.path.get(this.parent)) == null ? void 0 : _pathCache$get.delete(this.node);
this.node =
this.container[this.key] = null;
this.node = this.container[this.key] = null;
const paths = this.insertAfter(nodes);

@@ -61,3 +59,2 @@ if (this.node) {

}
function replaceWithSourceString(replacement) {

@@ -86,3 +83,2 @@ this.resync();

}
function replaceWith(replacementPath) {

@@ -126,12 +122,8 @@ this.resync();

}
this._replaceWith(replacement);
this.type = replacement.type;
this.setScope();
this.requeue();
return [nodePath ? this.get(nodePath) : this];
}
function _replaceWith(node) {

@@ -149,6 +141,4 @@ var _pathCache$get2;

(_pathCache$get2 = _cache.path.get(this.parent)) == null ? void 0 : _pathCache$get2.set(node, this).delete(this.node);
this.node =
this.container[this.key] = node;
this.node = this.container[this.key] = node;
}
function replaceExpressionWithStatements(nodes) {

@@ -165,3 +155,2 @@ this.resync();

this.replaceWith(callExpression(container, []));
const callee = this.get("callee");

@@ -173,3 +162,2 @@ (0, _helperHoistVariables.default)(callee.get("body"), id => {

}, "var");
const completionRecords = this.get("callee").getCompletionRecords();

@@ -193,6 +181,4 @@ for (const path of completionRecords) {

}
callee.arrowFunctionToExpression();
const newCallee = callee;
const needToAwaitFunction = isParentAsync && _index.default.hasType(this.get("callee.body").node, "AwaitExpression", FUNCTION_TYPES);

@@ -199,0 +185,0 @@ const needToYieldFunction = isParentGenerator && _index.default.hasType(this.get("callee.body").node, "YieldExpression", FUNCTION_TYPES);

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

exports.default = void 0;
class Binding {

@@ -29,4 +28,3 @@ constructor({

this.kind = kind;
if ((kind === "var" || kind === "hoisted") &&
isDeclaredInLoop(path || (() => {
if ((kind === "var" || kind === "hoisted") && isDeclaredInLoop(path || (() => {
throw new Error("Internal Babel error: unreachable ");

@@ -52,3 +50,2 @@ })())) {

}
reassign(path) {

@@ -61,3 +58,2 @@ this.constant = false;

}
reference(path) {

@@ -71,3 +67,2 @@ if (this.referencePaths.indexOf(path) !== -1) {

}
dereference() {

@@ -74,0 +69,0 @@ this.references--;

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

}
const collectorVisitor = {

@@ -188,7 +187,4 @@ ForStatement(path) {

if (path.isBlockScoped()) return;
if (path.isImportDeclaration()) return;
if (path.isExportDeclaration()) return;
const parent = path.scope.getFunctionParent() || path.scope.getProgramParent();

@@ -208,4 +204,3 @@ parent.registerDeclaration(path);

state.constantViolations.push(path);
}
else if (left.isVar()) {
} else if (left.isVar()) {
const {

@@ -260,3 +255,2 @@ scope

parent.registerDeclaration(path);
if (path.isClassDeclaration() && path.node.id) {

@@ -276,5 +270,3 @@ const id = path.node.id;

}
if (path.isFunctionExpression() && path.has("id") &&
!path.get("id").node[NOT_LOCAL_BINDING]) {
if (path.isFunctionExpression() && path.has("id") && !path.get("id").node[NOT_LOCAL_BINDING]) {
path.scope.registerBinding("local", path.get("id"), path);

@@ -284,4 +276,3 @@ }

ClassExpression(path) {
if (path.has("id") &&
!path.get("id").node[NOT_LOCAL_BINDING]) {
if (path.has("id") && !path.get("id").node[NOT_LOCAL_BINDING]) {
path.scope.registerBinding("local", path);

@@ -319,3 +310,2 @@ }

}
get parent() {

@@ -342,3 +332,2 @@ var _parent;

}
generateDeclaredUidIdentifier(name) {

@@ -351,7 +340,5 @@ const id = this.generateUidIdentifier(name);

}
generateUidIdentifier(name) {
return identifier(this.generateUid(name));
}
generateUid(name = "temp") {

@@ -370,3 +357,2 @@ name = toIdentifier(name).replace(/^_+/, "").replace(/[0-9]+$/g, "");

}
_generateUid(name, i) {

@@ -384,7 +370,5 @@ let id = name;

}
generateUidIdentifierBasedOnNode(node, defaultName) {
return identifier(this.generateUidBasedOnNode(node, defaultName));
}
isStatic(node) {

@@ -404,3 +388,2 @@ if (isThisExpression(node) || isSuper(node) || isTopicReference(node)) {

}
maybeGenerateMemoised(node, dontPush) {

@@ -422,7 +405,4 @@ if (this.isStatic(node)) {

if (kind === "param") return;
if (local.kind === "local") return;
const duplicate =
kind === "let" || local.kind === "let" || local.kind === "const" || local.kind === "module" ||
local.kind === "param" && kind === "const";
const duplicate = kind === "let" || local.kind === "let" || local.kind === "const" || local.kind === "module" || local.kind === "param" && kind === "const";
if (duplicate) {

@@ -439,3 +419,2 @@ throw this.hub.buildError(id, `Duplicate declaration "${name}"`, TypeError);

}
_renameFromMap(map, oldName, newName, value) {

@@ -465,3 +444,2 @@ if (map[oldName]) {

}
toArray(node, i, arrayLikeIsIterable) {

@@ -488,3 +466,2 @@ if (isIdentifier(node)) {

args.push(numericLiteral(i));
helperName = "slicedToArray";

@@ -498,3 +475,2 @@ } else {

}
return callExpression(this.hub.addHelper(helperName), args);

@@ -572,3 +548,2 @@ }

}
if (local) {

@@ -673,7 +648,5 @@ this.registerConstantViolation(bindingPath);

}
setData(key, val) {
return this.data[key] = val;
}
getData(key) {

@@ -686,3 +659,2 @@ let scope = this;

}
removeData(key) {

@@ -729,3 +701,2 @@ let scope = this;

this.crawling = false;
for (const path of state.assignments) {

@@ -737,6 +708,4 @@ const ids = path.getBindingIdentifiers();

}
path.scope.registerConstantViolation(path);
}
for (const ref of state.references) {

@@ -750,3 +719,2 @@ const binding = ref.scope.getBinding(ref.node.name);

}
for (const path of state.constantViolations) {

@@ -785,3 +753,2 @@ path.scope.registerConstantViolation(path);

}
getProgramParent() {

@@ -796,3 +763,2 @@ let scope = this;

}
getFunctionParent() {

@@ -807,3 +773,2 @@ let scope = this;

}
getBlockParent() {

@@ -818,3 +783,2 @@ let scope = this;

}
getPatternParent() {

@@ -829,3 +793,2 @@ let scope = this;

}
getAllBindings() {

@@ -844,3 +807,2 @@ const ids = Object.create(null);

}
getAllBindingsOfKind(...kinds) {

@@ -870,5 +832,3 @@ const ids = Object.create(null);

var _previousPath;
if ((_previousPath = previousPath) != null && _previousPath.isPattern() && binding.kind !== "param" && binding.kind !== "local") {
} else {
if ((_previousPath = previousPath) != null && _previousPath.isPattern() && binding.kind !== "param" && binding.kind !== "local") {} else {
return binding;

@@ -885,3 +845,2 @@ }

}
getBindingIdentifier(name) {

@@ -891,3 +850,2 @@ var _this$getBinding;

}
getOwnBindingIdentifier(name) {

@@ -900,3 +858,2 @@ const binding = this.bindings[name];

}
hasBinding(name, opts) {

@@ -921,3 +878,2 @@ var _opts, _opts2, _opts3;

}
moveBindingTo(name, scope) {

@@ -937,3 +893,2 @@ const info = this.getBinding(name);

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

@@ -940,0 +895,0 @@ do {

@@ -62,10 +62,6 @@ "use strict";

return path;
}
maybeConvertFromClassFunctionExpression(path) {
return path;
}
rename(block) {

@@ -88,4 +84,3 @@ const {

}
(0, _traverseNode.traverseNode)(block || scope.block, (0, _visitors.explode)(renameVisitor), scope, this, scope.path,
{
(0, _traverseNode.traverseNode)(block || scope.block, (0, _visitors.explode)(renameVisitor), scope, this, scope.path, {
discriminant: true

@@ -92,0 +87,0 @@ });

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

}
function explode(visitor) {
if (visitor._exploded) return visitor;
visitor._exploded = true;
for (const nodeType of Object.keys(visitor)) {

@@ -35,15 +33,9 @@ if (shouldIgnoreKey(nodeType)) continue;

}
verify(visitor);
delete visitor.__esModule;
ensureEntranceObjects(visitor);
ensureCallbackArrays(visitor);
for (const nodeType of Object.keys(visitor)) {
if (shouldIgnoreKey(nodeType)) continue;
if (!isVirtualType(nodeType)) continue;
const fns = visitor[nodeType];

@@ -53,3 +45,2 @@ for (const type of Object.keys(fns)) {

}
delete visitor[nodeType];

@@ -69,3 +60,2 @@ const types = virtualTypes[nodeType];

}
for (const nodeType of Object.keys(visitor)) {

@@ -81,3 +71,2 @@ if (shouldIgnoreKey(nodeType)) continue;

if (!aliases) continue;
delete visitor[nodeType];

@@ -95,4 +84,3 @@ for (const alias of aliases) {

if (shouldIgnoreKey(nodeType)) continue;
ensureCallbackArrays(
visitor[nodeType]);
ensureCallbackArrays(visitor[nodeType]);
}

@@ -143,7 +131,5 @@ return visitor;

let visitorType = visitor[type];
if (state || wrapper) {
visitorType = wrapWithStateOrWrapper(visitorType, state, wrapper);
}
const nodeVisitor = rootVisitor[type] || (rootVisitor[type] = {});

@@ -159,5 +145,3 @@ mergePair(nodeVisitor, visitorType);

let fns = oldVisitor[key];
if (!Array.isArray(fns)) continue;
fns = fns.map(function (fn) {

@@ -173,3 +157,2 @@ let newFn = fn;

}
if (newFn !== fn) {

@@ -180,3 +163,2 @@ newFn.toString = () => fn.toString();

});
newVisitor[key] = fns;

@@ -212,7 +194,4 @@ }

if (key[0] === "_") return true;
if (key === "enter" || key === "exit" || key === "shouldSkip") return true;
if (key === "denylist" || key === "noScope" || key === "skipKeys" ||
key === "blacklist") {
if (key === "denylist" || key === "noScope" || key === "skipKeys" || key === "blacklist") {
return true;

@@ -219,0 +198,0 @@ }

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

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

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

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

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc