@babel/traverse
Advanced tools
Comparing version 7.22.7 to 7.22.8
@@ -9,7 +9,5 @@ "use strict"; | ||
exports.clearScope = clearScope; | ||
exports.getCachedPaths = getCachedPaths; | ||
exports.getOrCreateCachedPaths = getOrCreateCachedPaths; | ||
exports.scope = exports.path = void 0; | ||
let pathsCache = new WeakMap(); | ||
exports.path = pathsCache; | ||
let path = new WeakMap(); | ||
exports.path = path; | ||
let scope = new WeakMap(); | ||
@@ -22,3 +20,3 @@ exports.scope = scope; | ||
function clearPath() { | ||
exports.path = pathsCache = new WeakMap(); | ||
exports.path = path = new WeakMap(); | ||
} | ||
@@ -28,15 +26,3 @@ 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 |
@@ -38,3 +38,3 @@ "use strict"; | ||
} = _t; | ||
function traverse(parent, opts = {}, scope, state, parentPath, visitSelf) { | ||
function traverse(parent, opts = {}, scope, state, parentPath) { | ||
if (!parent) return; | ||
@@ -46,5 +46,2 @@ if (!opts.noScope && !scope) { | ||
} | ||
if (!parentPath && visitSelf) { | ||
throw new Error("visitSelf can only be used when providing a NodePath."); | ||
} | ||
if (!VISITOR_KEYS[parent.type]) { | ||
@@ -54,3 +51,3 @@ return; | ||
visitors.explode(opts); | ||
(0, _traverseNode.traverseNode)(parent, opts, scope, state, parentPath, null, visitSelf); | ||
(0, _traverseNode.traverseNode)(parent, opts, scope, state, parentPath); | ||
} | ||
@@ -71,2 +68,3 @@ var _default = traverse; | ||
removeProperties(node, opts); | ||
cache.path.delete(node); | ||
}; | ||
@@ -73,0 +71,0 @@ traverse.removeProperties = function (tree, opts) { |
@@ -71,3 +71,7 @@ "use strict"; | ||
const targetNode = container[key]; | ||
const paths = (0, _cache.getOrCreateCachedPaths)(hub, parent); | ||
let paths = _cache.path.get(parent); | ||
if (!paths) { | ||
paths = new Map(); | ||
_cache.path.set(parent, paths); | ||
} | ||
let path = paths.get(targetNode); | ||
@@ -74,0 +78,0 @@ if (!path) { |
@@ -161,3 +161,3 @@ "use strict"; | ||
if (!this.parent) return; | ||
const paths = (0, _cache.getCachedPaths)(this.hub, this.parent) || []; | ||
const paths = _cache.path.get(this.parent); | ||
for (const [, path] of paths) { | ||
@@ -164,0 +164,0 @@ if (typeof path.key === "number" && path.key >= fromIndex) { |
@@ -49,5 +49,3 @@ "use strict"; | ||
this._traverseFlags |= _index.SHOULD_SKIP | _index.REMOVED; | ||
if (this.parent) { | ||
(0, _cache.getCachedPaths)(this.hub, this.parent).delete(this.node); | ||
} | ||
if (this.parent) _cache.path.get(this.parent).delete(this.node); | ||
this.node = null; | ||
@@ -54,0 +52,0 @@ } |
@@ -42,3 +42,3 @@ "use strict"; | ||
function replaceWithMultiple(nodes) { | ||
var _getCachedPaths; | ||
var _pathCache$get; | ||
this.resync(); | ||
@@ -48,3 +48,3 @@ nodes = this._verifyNodeList(nodes); | ||
inheritTrailingComments(nodes[nodes.length - 1], this.node); | ||
(_getCachedPaths = (0, _cache.getCachedPaths)(this.hub, this.parent)) == null ? void 0 : _getCachedPaths.delete(this.node); | ||
(_pathCache$get = _cache.path.get(this.parent)) == null ? void 0 : _pathCache$get.delete(this.node); | ||
this.node = this.container[this.key] = null; | ||
@@ -127,3 +127,3 @@ const paths = this.insertAfter(nodes); | ||
function _replaceWith(node) { | ||
var _getCachedPaths2; | ||
var _pathCache$get2; | ||
if (!this.container) { | ||
@@ -138,3 +138,3 @@ throw new ReferenceError("Container is falsy"); | ||
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); | ||
(_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; | ||
@@ -141,0 +141,0 @@ } |
@@ -12,12 +12,8 @@ "use strict"; | ||
} = _t; | ||
function traverseNode(node, opts, scope, state, path, skipKeys, visitSelf) { | ||
function traverseNode(node, opts, scope, state, path, skipKeys) { | ||
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 != null && skipKeys[key]) continue; | ||
if (skipKeys && skipKeys[key]) continue; | ||
if (context.visit(node, key)) { | ||
@@ -24,0 +20,0 @@ return true; |
{ | ||
"name": "@babel/traverse", | ||
"version": "7.22.7", | ||
"version": "7.22.8", | ||
"description": "The Babel Traverse module maintains the overall tree state, and is responsible for replacing, removing, and adding nodes", | ||
@@ -31,3 +31,2 @@ "author": "The Babel Team (https://babel.dev/team)", | ||
"devDependencies": { | ||
"@babel/core": "^7.22.7", | ||
"@babel/helper-plugin-test-runner": "^7.22.5" | ||
@@ -34,0 +33,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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1
7
29
596907
5115