@babel/traverse 7.17.10 → 7.18.2

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) {
@@ -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();
@@ -94,9 +94,12 @@ function isCompletionRecord(allowInsideFunction) {
94
94
  let first = true;
95
95
 
96
96
  do {
97
- const container = path.container;
97
+ const {
98
+ type,
99
+ container
100
+ } = path;
98
101
 
99
- if (path.isFunction() && !first) {
102
+ if (!first && (path.isFunction() || type === "StaticBlock")) {
100
103
  return !!allowInsideFunction;
101
104
  }
102
105
 
@@ -105,7 +108,7 @@ function isCompletionRecord(allowInsideFunction) {
105
108
  if (Array.isArray(container) && path.key !== container.length - 1) {
106
109
  return false;
107
110
  }
108
- } while ((path = path.parentPath) && !path.isProgram());
111
+ } while ((path = path.parentPath) && !path.isProgram() && !path.isDoExpression());
109
112
 
110
113
  return true;
111
114
  }
@@ -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.10",
3
+ "version": "7.18.2",
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.10",
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.10",
26
- "@babel/types": "^7.17.10",
25
+ "@babel/parser": "^7.18.0",
26
+ "@babel/types": "^7.18.2",
27
27
  "debug": "^4.1.0",
28
28
  "globals": "^11.1.0"
29
29
  },