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.22.6 to 7.22.7

20

lib/cache.js

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

exports.clearScope = clearScope;
exports.getCachedPaths = getCachedPaths;
exports.getOrCreateCachedPaths = getOrCreateCachedPaths;
exports.scope = exports.path = void 0;
let path = new WeakMap();
exports.path = path;
let pathsCache = new WeakMap();
exports.path = pathsCache;
let scope = new WeakMap();

@@ -20,3 +22,3 @@ exports.scope = scope;

function clearPath() {
exports.path = path = new WeakMap();
exports.path = pathsCache = new WeakMap();
}

@@ -26,3 +28,15 @@ function clearScope() {

}
const nullHub = Object.freeze({});
function getCachedPaths(hub, parent) {
var _pathsCache$get;
return (_pathsCache$get = pathsCache.get(hub != null ? hub : nullHub)) == null ? void 0 : _pathsCache$get.get(parent);
}
function getOrCreateCachedPaths(hub, parent) {
let parents = pathsCache.get(hub != null ? hub : nullHub);
if (!parents) pathsCache.set(hub != null ? hub : nullHub, parents = new WeakMap());
let paths = parents.get(parent);
if (!paths) parents.set(parent, paths = new Map());
return paths;
}
//# sourceMappingURL=cache.js.map

8

lib/index.js

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

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

@@ -46,2 +46,5 @@ if (!opts.noScope && !scope) {

}
if (!parentPath && visitSelf) {
throw new Error("visitSelf can only be used when providing a NodePath.");
}
if (!VISITOR_KEYS[parent.type]) {

@@ -51,3 +54,3 @@ return;

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

@@ -68,3 +71,2 @@ var _default = traverse;

removeProperties(node, opts);
cache.path.delete(node);
};

@@ -71,0 +73,0 @@ traverse.removeProperties = function (tree, opts) {

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

const targetNode = container[key];
let paths = _cache.path.get(parent);
if (!paths) {
paths = new Map();
_cache.path.set(parent, paths);
}
const paths = (0, _cache.getOrCreateCachedPaths)(hub, parent);
let path = paths.get(targetNode);

@@ -78,0 +74,0 @@ if (!path) {

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

if (!this.parent) return;
const paths = _cache.path.get(this.parent);
const paths = (0, _cache.getCachedPaths)(this.hub, this.parent) || [];
for (const [, path] of paths) {

@@ -164,0 +164,0 @@ if (typeof path.key === "number" && path.key >= fromIndex) {

@@ -49,3 +49,5 @@ "use strict";

this._traverseFlags |= _index.SHOULD_SKIP | _index.REMOVED;
if (this.parent) _cache.path.get(this.parent).delete(this.node);
if (this.parent) {
(0, _cache.getCachedPaths)(this.hub, this.parent).delete(this.node);
}
this.node = null;

@@ -52,0 +54,0 @@ }

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

function replaceWithMultiple(nodes) {
var _pathCache$get;
var _getCachedPaths;
this.resync();

@@ -48,3 +48,3 @@ nodes = this._verifyNodeList(nodes);

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

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

function _replaceWith(node) {
var _pathCache$get2;
var _getCachedPaths2;
if (!this.container) {

@@ -138,3 +138,3 @@ throw new ReferenceError("Container is falsy");

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

@@ -141,0 +141,0 @@ }

@@ -12,8 +12,12 @@ "use strict";

} = _t;
function traverseNode(node, opts, scope, state, path, skipKeys) {
function traverseNode(node, opts, scope, state, path, skipKeys, visitSelf) {
const keys = VISITOR_KEYS[node.type];
if (!keys) return false;
const context = new _context.default(scope, opts, state, path);
if (visitSelf) {
if (skipKeys != null && skipKeys[path.parentKey]) return false;
return context.visitQueue([path]);
}
for (const key of keys) {
if (skipKeys && skipKeys[key]) continue;
if (skipKeys != null && skipKeys[key]) continue;
if (context.visit(node, key)) {

@@ -20,0 +24,0 @@ return true;

@@ -128,22 +128,28 @@ "use strict";

function merge(visitors, states = [], wrapper) {
const rootVisitor = {};
const mergedVisitor = {};
for (let i = 0; i < visitors.length; i++) {
const visitor = visitors[i];
const visitor = explode(visitors[i]);
const state = states[i];
explode(visitor);
for (const type of Object.keys(visitor)) {
let visitorType = visitor[type];
let topVisitor = visitor;
if (state || wrapper) {
topVisitor = wrapWithStateOrWrapper(topVisitor, state, wrapper);
}
mergePair(mergedVisitor, topVisitor);
for (const key of Object.keys(visitor)) {
if (shouldIgnoreKey(key)) continue;
let typeVisitor = visitor[key];
if (state || wrapper) {
visitorType = wrapWithStateOrWrapper(visitorType, state, wrapper);
typeVisitor = wrapWithStateOrWrapper(typeVisitor, state, wrapper);
}
const nodeVisitor = rootVisitor[type] || (rootVisitor[type] = {});
mergePair(nodeVisitor, visitorType);
const nodeVisitor = mergedVisitor[key] || (mergedVisitor[key] = {});
mergePair(nodeVisitor, typeVisitor);
}
}
return rootVisitor;
;
return mergedVisitor;
}
function wrapWithStateOrWrapper(oldVisitor, state, wrapper) {
const newVisitor = {};
for (const key of Object.keys(oldVisitor)) {
let fns = oldVisitor[key];
for (const phase of ["enter", "exit"]) {
let fns = oldVisitor[phase];
if (!Array.isArray(fns)) continue;

@@ -158,3 +164,3 @@ fns = fns.map(function (fn) {

if (wrapper) {
newFn = wrapper(state.key, key, newFn);
newFn = wrapper(state == null ? void 0 : state.key, phase, newFn);
}

@@ -166,3 +172,3 @@ if (newFn !== fn) {

});
newVisitor[key] = fns;
newVisitor[phase] = fns;
}

@@ -209,4 +215,5 @@ return newVisitor;

function mergePair(dest, src) {
for (const key of Object.keys(src)) {
dest[key] = [].concat(dest[key] || [], src[key]);
for (const phase of ["enter", "exit"]) {
if (!src[phase]) continue;
dest[phase] = [].concat(dest[phase] || [], src[phase]);
}

@@ -213,0 +220,0 @@ }

{
"name": "@babel/traverse",
"version": "7.22.6",
"version": "7.22.7",
"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.5",
"@babel/generator": "^7.22.5",
"@babel/generator": "^7.22.7",
"@babel/helper-environment-visitor": "^7.22.5",

@@ -26,3 +26,3 @@ "@babel/helper-function-name": "^7.22.5",

"@babel/helper-split-export-declaration": "^7.22.6",
"@babel/parser": "^7.22.6",
"@babel/parser": "^7.22.7",
"@babel/types": "^7.22.5",

@@ -33,2 +33,3 @@ "debug": "^4.1.0",

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

@@ -35,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