@babel/traverse 7.18.2 → 7.18.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of @babel/traverse might be problematic. Click here for more details.

package/lib/path/index.js CHANGED
@@ -227,6 +227,9 @@ class NodePath {
227
227
  }
228
228
 
229
229
  Object.assign(NodePath.prototype, NodePath_ancestry, NodePath_inference, NodePath_replacement, NodePath_evaluation, NodePath_conversion, NodePath_introspection, NodePath_context, NodePath_removal, NodePath_modification, NodePath_family, NodePath_comments);
230
+ {
231
+ NodePath.prototype._guessExecutionStatusRelativeToDifferentFunctions = NodePath_introspection._guessExecutionStatusRelativeTo;
232
+ }
230
233
 
231
234
  for (const type of t.TYPES) {
232
235
  const typeKey = `is${type}`;
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports._guessExecutionStatusRelativeTo = _guessExecutionStatusRelativeTo;
7
- exports._guessExecutionStatusRelativeToDifferentFunctions = _guessExecutionStatusRelativeToDifferentFunctions;
8
7
  exports._resolve = _resolve;
9
8
  exports.canHaveVariableDeclarationOrExpression = canHaveVariableDeclarationOrExpression;
10
9
  exports.canSwapBetweenExpressionAndStatement = canSwapBetweenExpressionAndStatement;
@@ -232,20 +231,24 @@ function isExecutionUncertainInList(paths, maxIndex) {
232
231
  }
233
232
 
234
233
  function _guessExecutionStatusRelativeTo(target) {
234
+ return _guessExecutionStatusRelativeToCached(this, target, new Map());
235
+ }
236
+
237
+ function _guessExecutionStatusRelativeToCached(base, target, cache) {
235
238
  const funcParent = {
236
- this: getOuterFunction(this),
239
+ this: getOuterFunction(base),
237
240
  target: getOuterFunction(target)
238
241
  };
239
242
 
240
243
  if (funcParent.target.node !== funcParent.this.node) {
241
- return this._guessExecutionStatusRelativeToDifferentFunctions(funcParent.target);
244
+ return _guessExecutionStatusRelativeToDifferentFunctionsCached(base, funcParent.target, cache);
242
245
  }
243
246
 
244
247
  const paths = {
245
248
  target: target.getAncestry(),
246
- this: this.getAncestry()
249
+ this: base.getAncestry()
247
250
  };
248
- if (paths.target.indexOf(this) >= 0) return "after";
251
+ if (paths.target.indexOf(base) >= 0) return "after";
249
252
  if (paths.this.indexOf(target) >= 0) return "before";
250
253
  let commonPath;
251
254
  const commonIndex = {
@@ -289,9 +292,9 @@ function _guessExecutionStatusRelativeTo(target) {
289
292
  return keyPosition.target > keyPosition.this ? "before" : "after";
290
293
  }
291
294
 
292
- const executionOrderCheckedNodes = new WeakSet();
295
+ const executionOrderCheckedNodes = new Set();
293
296
 
294
- function _guessExecutionStatusRelativeToDifferentFunctions(target) {
297
+ function _guessExecutionStatusRelativeToDifferentFunctionsInternal(base, target, cache) {
295
298
  if (!target.isFunctionDeclaration() || target.parentPath.isExportDeclaration()) {
296
299
  return "unknown";
297
300
  }
@@ -312,20 +315,37 @@ function _guessExecutionStatusRelativeToDifferentFunctions(target) {
312
315
  if (executionOrderCheckedNodes.has(path.node)) continue;
313
316
  executionOrderCheckedNodes.add(path.node);
314
317
 
315
- const status = this._guessExecutionStatusRelativeTo(path);
316
-
317
- executionOrderCheckedNodes.delete(path.node);
318
+ try {
319
+ const status = _guessExecutionStatusRelativeToCached(base, path, cache);
318
320
 
319
- if (allStatus && allStatus !== status) {
320
- return "unknown";
321
- } else {
322
- allStatus = status;
321
+ if (allStatus && allStatus !== status) {
322
+ return "unknown";
323
+ } else {
324
+ allStatus = status;
325
+ }
326
+ } finally {
327
+ executionOrderCheckedNodes.delete(path.node);
323
328
  }
324
329
  }
325
330
 
326
331
  return allStatus;
327
332
  }
328
333
 
334
+ function _guessExecutionStatusRelativeToDifferentFunctionsCached(base, target, cache) {
335
+ let nodeMap = cache.get(base.node);
336
+
337
+ if (!nodeMap) {
338
+ cache.set(base.node, nodeMap = new Map());
339
+ } else if (nodeMap.has(target.node)) {
340
+ return nodeMap.get(target.node);
341
+ }
342
+
343
+ const result = _guessExecutionStatusRelativeToDifferentFunctionsInternal(base, target, cache);
344
+
345
+ nodeMap.set(target.node, result);
346
+ return result;
347
+ }
348
+
329
349
  function resolve(dangerous, resolved) {
330
350
  return this._resolve(dangerous, resolved) || this;
331
351
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babel/traverse",
3
- "version": "7.18.2",
3
+ "version": "7.18.5",
4
4
  "description": "The Babel Traverse module maintains the overall tree state, and is responsible for replacing, removing, and adding nodes",
5
5
  "author": "The Babel Team (https://babel.dev/team)",
6
6
  "homepage": "https://babel.dev/docs/en/next/babel-traverse",
@@ -22,8 +22,8 @@
22
22
  "@babel/helper-function-name": "^7.17.9",
23
23
  "@babel/helper-hoist-variables": "^7.16.7",
24
24
  "@babel/helper-split-export-declaration": "^7.16.7",
25
- "@babel/parser": "^7.18.0",
26
- "@babel/types": "^7.18.2",
25
+ "@babel/parser": "^7.18.5",
26
+ "@babel/types": "^7.18.4",
27
27
  "debug": "^4.1.0",
28
28
  "globals": "^11.1.0"
29
29
  },