Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

@babel/traverse

Package Overview
Dependencies
Maintainers
4
Versions
212
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.28.4
to
7.28.5
+68
lib/scope/traverseForScope.js
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = traverseForScope;
var _t = require("@babel/types");
var _index = require("../index.js");
var _visitors = require("../visitors.js");
var _context = require("../path/context.js");
const {
VISITOR_KEYS
} = _t;
function traverseForScope(path, visitors, state) {
const exploded = (0, _visitors.explode)(visitors);
if (exploded.enter || exploded.exit) {
throw new Error("Should not be used with enter/exit visitors.");
}
_traverse(path.parentPath, path.parent, path.node, path.container, path.key, path.listKey, path.hub, path);
function _traverse(parentPath, parent, node, container, key, listKey, hub, inPath) {
if (!node) {
return;
}
const path = inPath || _index.NodePath.get({
hub,
parentPath,
parent,
container,
listKey,
key
});
_context.setScope.call(path);
const visitor = exploded[node.type];
if (visitor) {
if (visitor.enter) {
for (const visit of visitor.enter) {
visit.call(state, path, state);
}
}
if (visitor.exit) {
for (const visit of visitor.exit) {
visit.call(state, path, state);
}
}
}
if (path.shouldSkip) {
return;
}
const keys = VISITOR_KEYS[node.type];
if (!(keys != null && keys.length)) {
return;
}
for (const key of keys) {
const prop = node[key];
if (!prop) continue;
if (Array.isArray(prop)) {
for (let i = 0; i < prop.length; i++) {
const value = prop[i];
_traverse(path, node, value, prop, i, key);
}
} else {
_traverse(path, node, prop, node, key, null);
}
}
}
}
//# sourceMappingURL=traverseForScope.js.map
{"version":3,"names":["_t","require","_index","_visitors","_context","VISITOR_KEYS","traverseForScope","path","visitors","state","exploded","explode","enter","exit","Error","_traverse","parentPath","parent","node","container","key","listKey","hub","inPath","NodePath","get","setScope","call","visitor","type","visit","shouldSkip","keys","length","prop","Array","isArray","i","value"],"sources":["../../src/scope/traverseForScope.ts"],"sourcesContent":["import { VISITOR_KEYS } from \"@babel/types\";\nimport type * as t from \"@babel/types\";\nimport type { HubInterface, Visitor } from \"../index.ts\";\nimport { NodePath } from \"../index.ts\";\nimport { explode } from \"../visitors.ts\";\nimport { setScope } from \"../path/context.ts\";\n\nexport default function traverseForScope(\n path: NodePath,\n visitors: Visitor,\n state: any,\n) {\n const exploded = explode(visitors);\n\n if (exploded.enter || exploded.exit) {\n throw new Error(\"Should not be used with enter/exit visitors.\");\n }\n\n _traverse(\n path.parentPath,\n path.parent,\n path.node,\n path.container!,\n path.key!,\n path.listKey,\n path.hub,\n path,\n );\n\n function _traverse(\n parentPath: NodePath,\n parent: t.Node,\n node: t.Node,\n container: t.Node | t.Node[],\n key: string | number,\n listKey: string | null | undefined,\n hub?: HubInterface,\n inPath?: NodePath,\n ) {\n if (!node) {\n return;\n }\n\n const path =\n inPath ||\n NodePath.get({\n hub,\n parentPath,\n parent,\n container,\n listKey,\n key,\n });\n\n setScope.call(path);\n\n const visitor = exploded[node.type];\n if (visitor) {\n if (visitor.enter) {\n for (const visit of visitor.enter) {\n visit.call(state, path, state);\n }\n }\n if (visitor.exit) {\n for (const visit of visitor.exit) {\n visit.call(state, path, state);\n }\n }\n }\n if (path.shouldSkip) {\n return;\n }\n\n const keys = VISITOR_KEYS[node.type];\n if (!keys?.length) {\n return;\n }\n\n for (const key of keys) {\n // @ts-expect-error key must present in node\n const prop = node[key];\n if (!prop) continue;\n if (Array.isArray(prop)) {\n for (let i = 0; i < prop.length; i++) {\n const value = prop[i];\n _traverse(path, node, value, prop, i, key);\n }\n } else {\n _traverse(path, node, prop, node, key, null);\n }\n }\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,EAAA,GAAAC,OAAA;AAGA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AAA8C;EALrCI;AAAY,IAAA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AI,EAAEE,KAAK,CAAC;QAChC;MACF;IACF;IACA,IAAIF,IAAI,CAACwB,UAAU,EAAE;MACnB;IACF;IAEA,MAAMC,IAAI,GAAG3B,YAAY,CAACa,IAAI,CAACW,IAAI,CAAC;IACpC,IAAI,EAACG,IAAI,YAAJA,IAAI,CAAEC,MAAM,GAAE;MACjB;IACF;IAEA,KAAK,MAAMb,GAAG,IAAIY,IAAI,EAAE;MAEtB,MAAME,IAAI,GAAGhB,IAAI,CAACE,GAAG,CAAC;MACtB,IAAI,CAACc,IAAI,EAAE;MACX,IAAIC,KAAK,CAACC,OAAO,CAACF,IAAI,CAAC,EAAE;QACvB,KAAK,IAAIG,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGH,IAAI,CAACD,MAAM,EAAEI,CAAC,EAAE,EAAE;UACpC,MAAMC,KAAK,GAAGJ,IAAI,CAACG,CAAC,CAAC;UACrBtB,SAAS,CAACR,IAAI,EAAEW,IAAI,EAAEoB,KAAK,EAAEJ,IAAI,EAAEG,CAAC,EAAEjB,GAAG,CAAC;QAC5C;MACF,CAAC,MAAM;QACLL,SAAS,CAACR,IAAI,EAAEW,IAAI,EAAEgB,IAAI,EAAEhB,IAAI,EAAEE,GAAG,EAAE,IAAI,CAAC;MAC9C;IACF;EACF;AACF","ignoreList":[]}
{
"compilerOptions": {
"strictNullChecks": true,
"strictPropertyInitialization": true
}
}
+2
-0

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

_context.resync.call(path);
;
if (path.contexts.length === 0 || path.contexts[path.contexts.length - 1] !== this) {

@@ -103,2 +104,3 @@ _context.pushContext.call(path, this);

for (let i = 0; i < visitIndex; i++) {
;
_context.popContext.call(queue[i]);

@@ -105,0 +107,0 @@ }

+1
-1

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

visitors.explode(opts);
(0, _traverseNode.traverseNode)(parent, opts, scope, state, parentPath, null, visitSelf);
(0, _traverseNode.traverseNode)(parent, opts, scope, state, parentPath, undefined, visitSelf);
}

@@ -56,0 +56,0 @@ var _default = exports.default = traverse;

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

return {
thisBinding,
thisBinding: thisBinding,
fnPath

@@ -304,4 +304,6 @@ };

const tmp = superProp.scope.generateDeclaredUidIdentifier("tmp");
const object = superProp.node.object;
const property = superProp.node.property;
const {
object,
property
} = superProp.node;
assignmentPath.get("left").replaceWith(memberExpression(object, assignmentExpression("=", tmp, property), true));

@@ -308,0 +310,0 @@ assignmentPath.get("right").replaceWith(rightExpression(isLogicalAssignment ? "=" : op, memberExpression(object, identifier(tmp.name), true), value));

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

this.state = null;
this.opts = null;
this._traverseFlags = 0;

@@ -42,0 +41,0 @@ this.skipKeys = null;

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

if (parentPath.isFunction()) {
if (parentPath.parentPath.scope.getBinding(name) !== binding) return;
if (name == null || parentPath.parentPath.scope.getBinding(name) !== binding) return;
}

@@ -122,0 +122,0 @@ path = parentPath;

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

}
return false;
});

@@ -396,0 +397,0 @@ return !!strictParent;

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

} while (path = path.parentPath);
return path;
}

@@ -143,0 +144,0 @@ hasOwnParamBindings(scope) {

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

type: "BlockStatement",
directives: [],
body: []

@@ -33,0 +34,0 @@ });

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

} = this;
if (!isIdentifier(node, opts) && !isJSXMemberExpression(parent, opts)) {
if (isJSXIdentifier(node, opts)) {
if (isCompatTag(node.name)) return false;
} else {
return false;
}
if (isIdentifier(node, opts)) {
return nodeIsReferenced(node, parent, this.parentPath.parent);
} else if (isJSXIdentifier(node, opts)) {
if (!isJSXMemberExpression(parent) && isCompatTag(node.name)) return false;
return nodeIsReferenced(node, parent, this.parentPath.parent);
} else {
return false;
}
return nodeIsReferenced(node, parent, this.parentPath.parent);
}

@@ -118,3 +118,4 @@ function isReferencedMemberExpression() {

function isUser() {
return this.node && !!this.node.loc;
var _this$node;
return !!((_this$node = this.node) != null && _this$node.loc);
}

@@ -121,0 +122,0 @@ function isGenerated() {

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

const Referenced = exports.Referenced = null;
const BlockScoped = exports.BlockScoped = null;
const BlockScoped = exports.BlockScoped = ["FunctionDeclaration", "ClassDeclaration", "VariableDeclaration"];
const Var = exports.Var = ["VariableDeclaration"];

@@ -17,0 +17,0 @@ const User = exports.User = null;

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

var _index = require("./index.js");
var _t = require("@babel/types");
var t = require("@babel/types");
var _modification = require("./modification.js");
var _context = require("./context.js");
const {
getBindingIdentifiers
} = _t;
function remove() {

@@ -39,3 +36,3 @@ var _this$opts;

function _removeFromScope() {
const bindings = getBindingIdentifiers(this.node, false, false, true);
const bindings = t.getBindingIdentifiers(this.node, false, false, true);
Object.keys(bindings).forEach(name => this.scope.removeBinding(name));

@@ -42,0 +39,0 @@ }

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

(_getCachedPaths2 = (0, _cache.getCachedPaths)(this)) == null || _getCachedPaths2.set(node, this).delete(this.node);
this.node = this.container[this.key] = node;
this.node = node;
this.container[this.key] = node;
}

@@ -148,0 +149,0 @@ function replaceExpressionWithStatements(nodes) {

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

var _index = require("../index.js");
var _traverseForScope = require("./traverseForScope.js");
var _binding = require("./binding.js");

@@ -190,2 +191,5 @@ var _t = require("@babel/types");

}
function isAnonymousFunctionExpression(path) {
return path.isFunctionExpression() && !path.node.id || path.isArrowFunctionExpression();
}
{

@@ -682,2 +686,3 @@ var NOT_LOCAL_BINDING = Symbol.for("should not be considered a local binding");

const path = this.path;
;
resetScope(this);

@@ -705,5 +710,2 @@ this.data = Object.create(null);

if (path.type !== "Program") {
for (const visit of scopeVisitor.enter) {
visit.call(state, path, state);
}
const typeVisitors = scopeVisitor[path.type];

@@ -716,3 +718,5 @@ if (typeVisitors) {

}
path.traverse(scopeVisitor, state);
{
path.traverse(scopeVisitor, state);
}
this.crawling = false;

@@ -755,3 +759,3 @@ for (const path of state.assignments) {

} = opts;
if (!init && !unique && (kind === "var" || kind === "let") && path.isFunction() && !path.node.name && isCallExpression(path.parent, {
if (!init && !unique && (kind === "var" || kind === "let") && isAnonymousFunctionExpression(path) && isCallExpression(path.parent, {
callee: path.node

@@ -945,3 +949,3 @@ }) && path.parent.arguments.length <= path.node.params.length && isIdentifier(id)) {

}
if (parentPath.parentPath.isFor({
if (parentPath.parentPath.isForXStatement({
left: parent

@@ -948,0 +952,0 @@ })) {

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

for (const type of types) {
if (visitor[type]) {
mergePair(visitor[type], fns);
} else {
visitor[type] = fns;
}
var _visitor$type;
(_visitor$type = visitor[type]) != null ? _visitor$type : visitor[type] = {};
mergePair(visitor[type], fns);
}

@@ -108,3 +106,3 @@ } else {

if (!TYPES.includes(nodeType)) {
throw new Error(`You gave us a visitor for the node type ${nodeType} but it's not a valid type in @babel/traverse ${"7.28.4"}`);
throw new Error(`You gave us a visitor for the node type ${nodeType} but it's not a valid type in @babel/traverse ${"7.28.5"}`);
}

@@ -111,0 +109,0 @@ const visitors = visitor[nodeType];

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

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

"@babel/code-frame": "^7.27.1",
"@babel/generator": "^7.28.3",
"@babel/generator": "^7.28.5",
"@babel/helper-globals": "^7.28.0",
"@babel/parser": "^7.28.4",
"@babel/parser": "^7.28.5",
"@babel/template": "^7.27.2",
"@babel/types": "^7.28.4",
"@babel/types": "^7.28.5",
"debug": "^4.3.1"
},
"devDependencies": {
"@babel/core": "^7.28.4",
"@babel/core": "^7.28.5",
"@babel/helper-plugin-test-runner": "^7.27.1"

@@ -31,0 +31,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

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 too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet