@babel/traverse 7.17.12 → 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.

@@ -129,7 +129,11 @@ function stop() {
129
129
  function setScope() {
130
130
  if (this.opts && this.opts.noScope) return;
131
131
  let path = this.parentPath;
132
- if (this.key === "key" && path.isMethod()) path = path.parentPath;
132
+
133
+ if ((this.key === "key" || this.listKey === "decorators") && path.isMethod()) {
134
+ path = path.parentPath;
135
+ }
136
+
133
137
  let target;
134
138
 
135
139
  while (path && !target) {
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}`;
@@ -33,10 +33,16 @@ const {
33
33
  } = _t;
34
34
 
35
35
  function getTypeAnnotation() {
36
- if (this.typeAnnotation) return this.typeAnnotation;
37
- let type = this._getTypeAnnotation() || anyTypeAnnotation();
36
+ let type = this.getData("typeAnnotation");
37
+
38
+ if (type != null) {
39
+ return type;
40
+ }
41
+
42
+ type = this._getTypeAnnotation() || anyTypeAnnotation();
38
43
  if (isTypeAnnotation(type)) type = type.typeAnnotation;
39
- return this.typeAnnotation = type;
44
+ this.setData("typeAnnotation", type);
45
+ return type;
40
46
  }
41
47
 
42
48
  const typeAnnotationInferringNodes = new WeakSet();
@@ -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;
@@ -94,9 +93,12 @@ function isCompletionRecord(allowInsideFunction) {
94
93
  let first = true;
95
94
 
96
95
  do {
97
- const container = path.container;
96
+ const {
97
+ type,
98
+ container
99
+ } = path;
98
100
 
99
- if (path.isFunction() && !first) {
101
+ if (!first && (path.isFunction() || type === "StaticBlock")) {
100
102
  return !!allowInsideFunction;
101
103
  }
102
104
 
@@ -105,7 +107,7 @@ function isCompletionRecord(allowInsideFunction) {
105
107
  if (Array.isArray(container) && path.key !== container.length - 1) {
106
108
  return false;
107
109
  }
108
- } while ((path = path.parentPath) && !path.isProgram());
110
+ } while ((path = path.parentPath) && !path.isProgram() && !path.isDoExpression());
109
111
 
110
112
  return true;
111
113
  }
@@ -229,20 +231,24 @@ function isExecutionUncertainInList(paths, maxIndex) {
229
231
  }
230
232
 
231
233
  function _guessExecutionStatusRelativeTo(target) {
234
+ return _guessExecutionStatusRelativeToCached(this, target, new Map());
235
+ }
236
+
237
+ function _guessExecutionStatusRelativeToCached(base, target, cache) {
232
238
  const funcParent = {
233
- this: getOuterFunction(this),
239
+ this: getOuterFunction(base),
234
240
  target: getOuterFunction(target)
235
241
  };
236
242
 
237
243
  if (funcParent.target.node !== funcParent.this.node) {
238
- return this._guessExecutionStatusRelativeToDifferentFunctions(funcParent.target);
244
+ return _guessExecutionStatusRelativeToDifferentFunctionsCached(base, funcParent.target, cache);
239
245
  }
240
246
 
241
247
  const paths = {
242
248
  target: target.getAncestry(),
243
- this: this.getAncestry()
249
+ this: base.getAncestry()
244
250
  };
245
- if (paths.target.indexOf(this) >= 0) return "after";
251
+ if (paths.target.indexOf(base) >= 0) return "after";
246
252
  if (paths.this.indexOf(target) >= 0) return "before";
247
253
  let commonPath;
248
254
  const commonIndex = {
@@ -286,9 +292,9 @@ function _guessExecutionStatusRelativeTo(target) {
286
292
  return keyPosition.target > keyPosition.this ? "before" : "after";
287
293
  }
288
294
 
289
- const executionOrderCheckedNodes = new WeakSet();
295
+ const executionOrderCheckedNodes = new Set();
290
296
 
291
- function _guessExecutionStatusRelativeToDifferentFunctions(target) {
297
+ function _guessExecutionStatusRelativeToDifferentFunctionsInternal(base, target, cache) {
292
298
  if (!target.isFunctionDeclaration() || target.parentPath.isExportDeclaration()) {
293
299
  return "unknown";
294
300
  }
@@ -309,20 +315,37 @@ function _guessExecutionStatusRelativeToDifferentFunctions(target) {
309
315
  if (executionOrderCheckedNodes.has(path.node)) continue;
310
316
  executionOrderCheckedNodes.add(path.node);
311
317
 
312
- const status = this._guessExecutionStatusRelativeTo(path);
313
-
314
- executionOrderCheckedNodes.delete(path.node);
318
+ try {
319
+ const status = _guessExecutionStatusRelativeToCached(base, path, cache);
315
320
 
316
- if (allStatus && allStatus !== status) {
317
- return "unknown";
318
- } else {
319
- allStatus = status;
321
+ if (allStatus && allStatus !== status) {
322
+ return "unknown";
323
+ } else {
324
+ allStatus = status;
325
+ }
326
+ } finally {
327
+ executionOrderCheckedNodes.delete(path.node);
320
328
  }
321
329
  }
322
330
 
323
331
  return allStatus;
324
332
  }
325
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
+
326
349
  function resolve(dangerous, resolved) {
327
350
  return this._resolve(dangerous, resolved) || this;
328
351
  }
@@ -368,9 +368,9 @@ class Scope {
368
368
  path = this.path;
369
369
 
370
370
  do {
371
- const isKey = path.key === "key";
371
+ const shouldSkip = path.key === "key" || path.listKey === "decorators";
372
372
  path = path.parentPath;
373
- if (isKey && path.isMethod()) path = path.parentPath;
373
+ if (shouldSkip && path.isMethod()) path = path.parentPath;
374
374
  if (path && path.isScope()) parent = path;
375
375
  } while (path && !parent);
376
376
 
@@ -854,7 +854,9 @@ class Scope {
854
854
  push(opts) {
855
855
  let path = this.path;
856
856
 
857
- if (!path.isBlockStatement() && !path.isProgram()) {
857
+ if (path.isPattern()) {
858
+ path = this.getPatternParent().path;
859
+ } else if (!path.isBlockStatement() && !path.isProgram()) {
858
860
  path = this.getBlockParent().path;
859
861
  }
860
862
 
@@ -921,6 +923,18 @@ class Scope {
921
923
  throw new Error("We couldn't find a BlockStatement, For, Switch, Function, Loop or Program...");
922
924
  }
923
925
 
926
+ getPatternParent() {
927
+ let scope = this;
928
+
929
+ do {
930
+ if (!scope.path.isPattern()) {
931
+ return scope.getBlockParent();
932
+ }
933
+ } while (scope = scope.parent.parent);
934
+
935
+ throw new Error("We couldn't find a BlockStatement, For, Switch, Function, Loop or Program...");
936
+ }
937
+
924
938
  getAllBindings() {
925
939
  const ids = Object.create(null);
926
940
  let scope = this;
@@ -11,8 +11,9 @@ var _helperSplitExportDeclaration = require("@babel/helper-split-export-declarat
11
11
 
12
12
  var _t = require("@babel/types");
13
13
 
14
+ var _helperEnvironmentVisitor = require("@babel/helper-environment-visitor");
15
+
14
16
  const {
15
- VISITOR_KEYS,
16
17
  assignmentExpression,
17
18
  identifier,
18
19
  toExpression,
@@ -30,7 +31,11 @@ const renameVisitor = {
30
31
 
31
32
  Scope(path, state) {
32
33
  if (!path.scope.bindingIdentifierEquals(state.oldName, state.binding.identifier)) {
33
- skipAllButComputedMethodKey(path);
34
+ path.skip();
35
+
36
+ if (path.isMethod()) {
37
+ (0, _helperEnvironmentVisitor.requeueComputedKeyAndDecorators)(path);
38
+ }
34
39
  }
35
40
  },
36
41
 
@@ -130,17 +135,4 @@ class Renamer {
130
135
 
131
136
  }
132
137
 
133
- exports.default = Renamer;
134
-
135
- function skipAllButComputedMethodKey(path) {
136
- if (!path.isMethod() || !path.node.computed) {
137
- path.skip();
138
- return;
139
- }
140
-
141
- const keys = VISITOR_KEYS[path.type];
142
-
143
- for (const key of keys) {
144
- if (key !== "key") path.skipKey(key);
145
- }
146
- }
138
+ exports.default = Renamer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babel/traverse",
3
- "version": "7.17.12",
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",
@@ -17,13 +17,13 @@
17
17
  "main": "./lib/index.js",
18
18
  "dependencies": {
19
19
  "@babel/code-frame": "^7.16.7",
20
- "@babel/generator": "^7.17.12",
21
- "@babel/helper-environment-visitor": "^7.16.7",
20
+ "@babel/generator": "^7.18.2",
21
+ "@babel/helper-environment-visitor": "^7.18.2",
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.17.12",
26
- "@babel/types": "^7.17.12",
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
  },