@babel/traverse
Advanced tools
+10
-15
@@ -24,18 +24,13 @@ "use strict"; | ||
| } | ||
| const nullHub = Object.freeze({}); | ||
| function getCachedPaths(hub, parent) { | ||
| var _pathsCache$get; | ||
| { | ||
| hub = null; | ||
| } | ||
| return (_pathsCache$get = pathsCache.get(hub != null ? hub : nullHub)) == null ? void 0 : _pathsCache$get.get(parent); | ||
| function getCachedPaths(path) { | ||
| const { | ||
| parent, | ||
| parentPath | ||
| } = path; | ||
| return pathsCache.get(parent); | ||
| } | ||
| function getOrCreateCachedPaths(hub, parent) { | ||
| { | ||
| hub = null; | ||
| } | ||
| 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()); | ||
| function getOrCreateCachedPaths(node, parentPath) { | ||
| ; | ||
| let paths = pathsCache.get(node); | ||
| if (!paths) pathsCache.set(node, paths = new Map()); | ||
| return paths; | ||
@@ -42,0 +37,0 @@ } |
@@ -157,5 +157,9 @@ "use strict"; | ||
| return; | ||
| } else { | ||
| return evaluateCached(resolved, state); | ||
| } | ||
| const value = evaluateCached(resolved, state); | ||
| if (typeof value === "object" && value !== null && binding.references > 1) { | ||
| deopt(resolved, state); | ||
| return; | ||
| } | ||
| return value; | ||
| } | ||
@@ -162,0 +166,0 @@ if (path.isUnaryExpression({ |
+13
-7
@@ -122,8 +122,12 @@ "use strict"; | ||
| completions.push(...statementCompletions); | ||
| replaceBreakStatementInBreakCompletion(statementCompletions, true); | ||
| if (!context.shouldPreserveBreak) { | ||
| replaceBreakStatementInBreakCompletion(statementCompletions, true); | ||
| } | ||
| } | ||
| replaceBreakStatementInBreakCompletion(statementCompletions, false); | ||
| if (!context.shouldPreserveBreak) { | ||
| replaceBreakStatementInBreakCompletion(statementCompletions, false); | ||
| } | ||
| } else { | ||
| completions.push(...statementCompletions); | ||
| if (!context.shouldPopulateBreak) { | ||
| if (!context.shouldPopulateBreak && !context.shouldPreserveBreak) { | ||
| replaceBreakStatementInBreakCompletion(statementCompletions, true); | ||
@@ -152,3 +156,3 @@ } | ||
| const pathCompletions = _getCompletionRecords(paths[i], context); | ||
| if (pathCompletions.length > 1 || pathCompletions.length === 1 && !pathCompletions[0].path.isVariableDeclaration()) { | ||
| if (pathCompletions.length > 1 || pathCompletions.length === 1 && !pathCompletions[0].path.isVariableDeclaration() && !pathCompletions[0].path.isEmptyStatement()) { | ||
| completions.push(...pathCompletions); | ||
@@ -183,3 +187,4 @@ break; | ||
| shouldPopulateBreak: false, | ||
| inCaseClause: true | ||
| inCaseClause: true, | ||
| shouldPreserveBreak: context.shouldPreserveBreak | ||
| }); | ||
@@ -193,7 +198,8 @@ } else if (path.isBreakStatement()) { | ||
| } | ||
| function getCompletionRecords() { | ||
| function getCompletionRecords(shouldPreserveBreak = false) { | ||
| const records = _getCompletionRecords(this, { | ||
| canHaveBreak: false, | ||
| shouldPopulateBreak: false, | ||
| inCaseClause: false | ||
| inCaseClause: false, | ||
| shouldPreserveBreak | ||
| }); | ||
@@ -200,0 +206,0 @@ return records.map(r => r.path); |
@@ -48,2 +48,3 @@ "use strict"; | ||
| this.type = null; | ||
| this._store = null; | ||
| this.parent = parent; | ||
@@ -88,3 +89,3 @@ this.hub = hub; | ||
| const targetNode = container[key]; | ||
| const paths = cache.getOrCreateCachedPaths(hub, parent); | ||
| const paths = cache.getOrCreateCachedPaths(parent, parentPath); | ||
| let path = paths.get(targetNode); | ||
@@ -91,0 +92,0 @@ if (!path) { |
@@ -164,3 +164,4 @@ "use strict"; | ||
| if (!this.parent) return; | ||
| const paths = (0, _cache.getCachedPaths)(this.hub, this.parent) || []; | ||
| const paths = (0, _cache.getCachedPaths)(this); | ||
| if (!paths) return; | ||
| for (const [, path] of paths) { | ||
@@ -167,0 +168,0 @@ if (typeof path.key === "number" && path.container === this.container && path.key >= fromIndex) { |
@@ -59,3 +59,4 @@ "use strict"; | ||
| if (this.parent) { | ||
| (0, _cache.getCachedPaths)(this.hub, this.parent).delete(this.node); | ||
| var _getCachedPaths; | ||
| (_getCachedPaths = (0, _cache.getCachedPaths)(this)) == null || _getCachedPaths.delete(this.node); | ||
| } | ||
@@ -62,0 +63,0 @@ this.node = null; |
@@ -56,3 +56,3 @@ "use strict"; | ||
| inheritTrailingComments(nodes[nodes.length - 1], this.node); | ||
| (_getCachedPaths = (0, _cache.getCachedPaths)(this.hub, this.parent)) == null || _getCachedPaths.delete(this.node); | ||
| (_getCachedPaths = (0, _cache.getCachedPaths)(this)) == null || _getCachedPaths.delete(this.node); | ||
| this.node = this.container[this.key] = null; | ||
@@ -145,3 +145,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 || _getCachedPaths2.set(node, this).delete(this.node); | ||
| (_getCachedPaths2 = (0, _cache.getCachedPaths)(this)) == null || _getCachedPaths2.set(node, this).delete(this.node); | ||
| this.node = this.container[this.key] = node; | ||
@@ -148,0 +148,0 @@ } |
@@ -357,6 +357,6 @@ "use strict"; | ||
| let uid; | ||
| let i = 1; | ||
| let i = 0; | ||
| do { | ||
| uid = `_${name}`; | ||
| if (i > 1) uid += i; | ||
| if (i >= 11) uid += i - 1;else if (i >= 9) uid += i - 9;else if (i >= 1) uid += i + 1; | ||
| i++; | ||
@@ -363,0 +363,0 @@ } while (this.hasLabel(uid) || this.hasBinding(uid) || this.hasGlobal(uid) || this.hasReference(uid)); |
+109
-0
@@ -8,7 +8,116 @@ "use strict"; | ||
| var _context = require("./context.js"); | ||
| var _index = require("./path/index.js"); | ||
| var _t = require("@babel/types"); | ||
| var _context2 = require("./path/context.js"); | ||
| const { | ||
| VISITOR_KEYS | ||
| } = _t; | ||
| function _visitPaths(ctx, paths) { | ||
| ctx.queue = paths; | ||
| ctx.priorityQueue = []; | ||
| const visited = new Set(); | ||
| let stop = false; | ||
| let visitIndex = 0; | ||
| for (; visitIndex < paths.length;) { | ||
| const path = paths[visitIndex]; | ||
| visitIndex++; | ||
| _context2.resync.call(path); | ||
| if (path.contexts.length === 0 || path.contexts[path.contexts.length - 1] !== ctx) { | ||
| _context2.pushContext.call(path, ctx); | ||
| } | ||
| if (path.key === null) continue; | ||
| const { | ||
| node | ||
| } = path; | ||
| if (visited.has(node)) continue; | ||
| if (node) visited.add(node); | ||
| if (_visit(ctx, path)) { | ||
| stop = true; | ||
| break; | ||
| } | ||
| if (ctx.priorityQueue.length) { | ||
| stop = _visitPaths(ctx, ctx.priorityQueue); | ||
| ctx.priorityQueue = []; | ||
| ctx.queue = paths; | ||
| if (stop) break; | ||
| } | ||
| } | ||
| for (let i = 0; i < visitIndex; i++) { | ||
| _context2.popContext.call(paths[i]); | ||
| } | ||
| ctx.queue = null; | ||
| return stop; | ||
| } | ||
| function _visit(ctx, path) { | ||
| var _opts$denylist; | ||
| const node = path.node; | ||
| if (!node) { | ||
| return false; | ||
| } | ||
| const opts = ctx.opts; | ||
| const denylist = (_opts$denylist = opts.denylist) != null ? _opts$denylist : opts.blacklist; | ||
| if (denylist != null && denylist.includes(node.type)) { | ||
| return false; | ||
| } | ||
| if (opts.shouldSkip != null && opts.shouldSkip(path)) { | ||
| return false; | ||
| } | ||
| if (path.shouldSkip) return path.shouldStop; | ||
| if (_context2._call.call(path, opts.enter)) return path.shouldStop; | ||
| if (path.node) { | ||
| var _opts$node$type; | ||
| if (_context2._call.call(path, (_opts$node$type = opts[node.type]) == null ? void 0 : _opts$node$type.enter)) return path.shouldStop; | ||
| } | ||
| path.shouldStop = _traverse(path.node, opts, path.scope, ctx.state, path, path.skipKeys); | ||
| if (path.node) { | ||
| if (_context2._call.call(path, opts.exit)) return true; | ||
| } | ||
| if (path.node) { | ||
| var _opts$node$type2; | ||
| _context2._call.call(path, (_opts$node$type2 = opts[node.type]) == null ? void 0 : _opts$node$type2.exit); | ||
| } | ||
| return path.shouldStop; | ||
| } | ||
| function _traverse(node, opts, scope, state, path, skipKeys, visitSelf) { | ||
| const keys = VISITOR_KEYS[node.type]; | ||
| if (!(keys != null && keys.length)) return false; | ||
| const ctx = new _context.default(scope, opts, state, path); | ||
| if (visitSelf) { | ||
| if (skipKeys != null && skipKeys[path.parentKey]) return false; | ||
| return _visitPaths(ctx, [path]); | ||
| } | ||
| for (const key of keys) { | ||
| if (skipKeys != null && skipKeys[key]) continue; | ||
| const prop = node[key]; | ||
| if (!prop) continue; | ||
| if (Array.isArray(prop)) { | ||
| if (!prop.length) continue; | ||
| const paths = []; | ||
| for (let i = 0; i < prop.length; i++) { | ||
| const childPath = _index.default.get({ | ||
| parentPath: path, | ||
| parent: node, | ||
| container: prop, | ||
| key: i, | ||
| listKey: key | ||
| }); | ||
| paths.push(childPath); | ||
| } | ||
| if (_visitPaths(ctx, paths)) return true; | ||
| } else { | ||
| if (_visitPaths(ctx, [_index.default.get({ | ||
| parentPath: path, | ||
| parent: node, | ||
| container: node, | ||
| key, | ||
| listKey: null | ||
| })])) { | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
| function traverseNode(node, opts, scope, state, path, skipKeys, visitSelf) { | ||
| ; | ||
| const keys = VISITOR_KEYS[node.type]; | ||
@@ -15,0 +124,0 @@ if (!keys) return false; |
+1
-1
@@ -107,3 +107,3 @@ "use strict"; | ||
| 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.27.0"}`); | ||
| throw new Error(`You gave us a visitor for the node type ${nodeType} but it's not a valid type in @babel/traverse ${"7.27.1"}`); | ||
| } | ||
@@ -110,0 +110,0 @@ const visitors = visitor[nodeType]; |
+8
-8
| { | ||
| "name": "@babel/traverse", | ||
| "version": "7.27.0", | ||
| "version": "7.27.1", | ||
| "description": "The Babel Traverse module maintains the overall tree state, and is responsible for replacing, removing, and adding nodes", | ||
@@ -19,7 +19,7 @@ "author": "The Babel Team (https://babel.dev/team)", | ||
| "dependencies": { | ||
| "@babel/code-frame": "^7.26.2", | ||
| "@babel/generator": "^7.27.0", | ||
| "@babel/parser": "^7.27.0", | ||
| "@babel/template": "^7.27.0", | ||
| "@babel/types": "^7.27.0", | ||
| "@babel/code-frame": "^7.27.1", | ||
| "@babel/generator": "^7.27.1", | ||
| "@babel/parser": "^7.27.1", | ||
| "@babel/template": "^7.27.1", | ||
| "@babel/types": "^7.27.1", | ||
| "debug": "^4.3.1", | ||
@@ -29,4 +29,4 @@ "globals": "^11.1.0" | ||
| "devDependencies": { | ||
| "@babel/core": "^7.26.10", | ||
| "@babel/helper-plugin-test-runner": "^7.25.9" | ||
| "@babel/core": "^7.27.1", | ||
| "@babel/helper-plugin-test-runner": "^7.27.1" | ||
| }, | ||
@@ -33,0 +33,0 @@ "engines": { |
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
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
689113
1.86%5767
2.07%3
50%Updated
Updated
Updated
Updated
Updated