@babel/traverse 7.12.8 → 7.12.13

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/context.js CHANGED
@@ -20,6 +20,7 @@ const testing = process.env.NODE_ENV === "test";
20
20
  class TraversalContext {
21
21
  constructor(scope, opts, state, parentPath) {
22
22
  this.queue = null;
23
+ this.priorityQueue = null;
23
24
  this.parentPath = parentPath;
24
25
  this.scope = scope;
25
26
  this.state = state;
package/lib/index.js CHANGED
@@ -3,7 +3,6 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = traverse;
7
6
  Object.defineProperty(exports, "NodePath", {
8
7
  enumerable: true,
9
8
  get: function () {
@@ -22,7 +21,7 @@ Object.defineProperty(exports, "Hub", {
22
21
  return _hub.default;
23
22
  }
24
23
  });
25
- exports.visitors = void 0;
24
+ exports.visitors = exports.default = void 0;
26
25
 
27
26
  var _context = _interopRequireDefault(require("./context"));
28
27
 
@@ -46,9 +45,8 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
46
45
 
47
46
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
48
47
 
49
- function traverse(parent, opts, scope, state, parentPath) {
48
+ function traverse(parent, opts = {}, scope, state, parentPath) {
50
49
  if (!parent) return;
51
- if (!opts) opts = {};
52
50
 
53
51
  if (!opts.noScope && !scope) {
54
52
  if (parent.type !== "Program" && parent.type !== "File") {
@@ -64,6 +62,8 @@ function traverse(parent, opts, scope, state, parentPath) {
64
62
  traverse.node(parent, opts, scope, state, parentPath);
65
63
  }
66
64
 
65
+ var _default = traverse;
66
+ exports.default = _default;
67
67
  traverse.visitors = visitors;
68
68
  traverse.verify = visitors.verify;
69
69
  traverse.explode = visitors.explode;
@@ -167,11 +167,11 @@ function isDescendant(maybeAncestor) {
167
167
  return !!this.findParent(parent => parent === maybeAncestor);
168
168
  }
169
169
 
170
- function inType() {
170
+ function inType(...candidateTypes) {
171
171
  let path = this;
172
172
 
173
173
  while (path) {
174
- for (const type of arguments) {
174
+ for (const type of candidateTypes) {
175
175
  if (path.node.type === type) return true;
176
176
  }
177
177
 
@@ -20,18 +20,17 @@ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return
20
20
  function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
21
21
 
22
22
  function toComputedKey() {
23
- const node = this.node;
24
23
  let key;
25
24
 
26
25
  if (this.isMemberExpression()) {
27
- key = node.property;
26
+ key = this.node.property;
28
27
  } else if (this.isProperty() || this.isMethod()) {
29
- key = node.key;
28
+ key = this.node.key;
30
29
  } else {
31
30
  throw new ReferenceError("todo");
32
31
  }
33
32
 
34
- if (!node.computed) {
33
+ if (!this.node.computed) {
35
34
  if (t.isIdentifier(key)) key = t.stringLiteral(key.name);
36
35
  }
37
36
 
@@ -55,9 +55,6 @@ function evaluateCached(path, state) {
55
55
 
56
56
  function _evaluate(path, state) {
57
57
  if (!state.confident) return;
58
- const {
59
- node
60
- } = path;
61
58
 
62
59
  if (path.isSequenceExpression()) {
63
60
  const exprs = path.get("expressions");
@@ -65,7 +62,7 @@ function _evaluate(path, state) {
65
62
  }
66
63
 
67
64
  if (path.isStringLiteral() || path.isNumericLiteral() || path.isBooleanLiteral()) {
68
- return node.value;
65
+ return path.node.value;
69
66
  }
70
67
 
71
68
  if (path.isNullLiteral()) {
@@ -73,7 +70,7 @@ function _evaluate(path, state) {
73
70
  }
74
71
 
75
72
  if (path.isTemplateLiteral()) {
76
- return evaluateQuasis(path, node.quasis, state);
73
+ return evaluateQuasis(path, path.node.quasis, state);
77
74
  }
78
75
 
79
76
  if (path.isTaggedTemplateExpression() && path.get("tag").isMemberExpression()) {
@@ -85,8 +82,8 @@ function _evaluate(path, state) {
85
82
  } = object;
86
83
  const property = path.get("tag.property");
87
84
 
88
- if (object.isIdentifier() && name === "String" && !path.scope.getBinding(name, true) && property.isIdentifier && property.node.name === "raw") {
89
- return evaluateQuasis(path, node.quasi.quasis, state, true);
85
+ if (object.isIdentifier() && name === "String" && !path.scope.getBinding(name) && property.isIdentifier() && property.node.name === "raw") {
86
+ return evaluateQuasis(path, path.node.quasi.quasis, state, true);
90
87
  }
91
88
  }
92
89
 
@@ -106,7 +103,7 @@ function _evaluate(path, state) {
106
103
  }
107
104
 
108
105
  if (path.isMemberExpression() && !path.parentPath.isCallExpression({
109
- callee: node
106
+ callee: path.node
110
107
  })) {
111
108
  const property = path.get("property");
112
109
  const object = path.get("object");
@@ -122,7 +119,7 @@ function _evaluate(path, state) {
122
119
  }
123
120
 
124
121
  if (path.isReferencedIdentifier()) {
125
- const binding = path.scope.getBinding(node.name);
122
+ const binding = path.scope.getBinding(path.node.name);
126
123
 
127
124
  if (binding && binding.constantViolations.length > 0) {
128
125
  return deopt(binding.path, state);
@@ -135,11 +132,11 @@ function _evaluate(path, state) {
135
132
  if (binding == null ? void 0 : binding.hasValue) {
136
133
  return binding.value;
137
134
  } else {
138
- if (node.name === "undefined") {
135
+ if (path.node.name === "undefined") {
139
136
  return binding ? deopt(binding.path, state) : undefined;
140
- } else if (node.name === "Infinity") {
137
+ } else if (path.node.name === "Infinity") {
141
138
  return binding ? deopt(binding.path, state) : Infinity;
142
- } else if (node.name === "NaN") {
139
+ } else if (path.node.name === "NaN") {
143
140
  return binding ? deopt(binding.path, state) : NaN;
144
141
  }
145
142
 
@@ -156,20 +153,20 @@ function _evaluate(path, state) {
156
153
  if (path.isUnaryExpression({
157
154
  prefix: true
158
155
  })) {
159
- if (node.operator === "void") {
156
+ if (path.node.operator === "void") {
160
157
  return undefined;
161
158
  }
162
159
 
163
160
  const argument = path.get("argument");
164
161
 
165
- if (node.operator === "typeof" && (argument.isFunction() || argument.isClass())) {
162
+ if (path.node.operator === "typeof" && (argument.isFunction() || argument.isClass())) {
166
163
  return "function";
167
164
  }
168
165
 
169
166
  const arg = evaluateCached(argument, state);
170
167
  if (!state.confident) return;
171
168
 
172
- switch (node.operator) {
169
+ switch (path.node.operator) {
173
170
  case "!":
174
171
  return !arg;
175
172
 
@@ -252,7 +249,7 @@ function _evaluate(path, state) {
252
249
  const right = evaluateCached(path.get("right"), state);
253
250
  const rightConfident = state.confident;
254
251
 
255
- switch (node.operator) {
252
+ switch (path.node.operator) {
256
253
  case "||":
257
254
  state.confident = leftConfident && (!!left || rightConfident);
258
255
  if (!state.confident) return;
@@ -271,7 +268,7 @@ function _evaluate(path, state) {
271
268
  const right = evaluateCached(path.get("right"), state);
272
269
  if (!state.confident) return;
273
270
 
274
- switch (node.operator) {
271
+ switch (path.node.operator) {
275
272
  case "-":
276
273
  return left - right;
277
274
 
@@ -339,8 +336,8 @@ function _evaluate(path, state) {
339
336
  let context;
340
337
  let func;
341
338
 
342
- if (callee.isIdentifier() && !path.scope.getBinding(callee.node.name, true) && VALID_CALLEES.indexOf(callee.node.name) >= 0) {
343
- func = global[node.callee.name];
339
+ if (callee.isIdentifier() && !path.scope.getBinding(callee.node.name) && VALID_CALLEES.indexOf(callee.node.name) >= 0) {
340
+ func = global[callee.node.name];
344
341
  }
345
342
 
346
343
  if (callee.isMemberExpression()) {
@@ -34,6 +34,8 @@ function getOpposite() {
34
34
  } else if (this.key === "right") {
35
35
  return this.getSibling("left");
36
36
  }
37
+
38
+ return null;
37
39
  }
38
40
 
39
41
  function addCompletionRecords(path, paths) {
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ var t = _interopRequireWildcard(require("@babel/types"));
4
+
5
+ var _index = _interopRequireDefault(require("../index"));
6
+
7
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
+
9
+ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
10
+
11
+ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ var t = _interopRequireWildcard(require("@babel/types"));
4
+
5
+ var _index = _interopRequireDefault(require("../index"));
6
+
7
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
+
9
+ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
10
+
11
+ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+
3
+ var t = _interopRequireWildcard(require("@babel/types"));
4
+
5
+ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
6
+
7
+ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
package/lib/path/index.js CHANGED
@@ -221,7 +221,6 @@ class NodePath {
221
221
 
222
222
  }
223
223
 
224
- exports.default = NodePath;
225
224
  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);
226
225
 
227
226
  for (const type of t.TYPES) {
@@ -247,4 +246,7 @@ for (const type of Object.keys(virtualTypes)) {
247
246
  NodePath.prototype[`is${type}`] = function (opts) {
248
247
  return virtualType.checkPath(this, opts);
249
248
  };
250
- }
249
+ }
250
+
251
+ var _default = NodePath;
252
+ exports.default = _default;
@@ -123,13 +123,15 @@ function couldBeBaseType(name) {
123
123
  }
124
124
  }
125
125
 
126
- function baseTypeStrictlyMatches(right) {
126
+ function baseTypeStrictlyMatches(rightArg) {
127
127
  const left = this.getTypeAnnotation();
128
- right = right.getTypeAnnotation();
128
+ const right = rightArg.getTypeAnnotation();
129
129
 
130
130
  if (!t.isAnyTypeAnnotation(left) && t.isFlowBaseAnnotation(left)) {
131
131
  return right.type === left.type;
132
132
  }
133
+
134
+ return false;
133
135
  }
134
136
 
135
137
  function isGenericType(genericName) {
@@ -132,7 +132,9 @@ function referencesImport(moduleSource, importName) {
132
132
  return true;
133
133
  }
134
134
 
135
- if (path.isImportSpecifier() && path.node.imported.name === importName) {
135
+ if (path.isImportSpecifier() && t.isIdentifier(path.node.imported, {
136
+ name: importName
137
+ })) {
136
138
  return true;
137
139
  }
138
140
 
@@ -377,7 +379,7 @@ function isConstantExpression() {
377
379
  }
378
380
 
379
381
  if (this.isUnaryExpression()) {
380
- if (this.get("operator").node !== "void") {
382
+ if (this.node.operator !== "void") {
381
383
  return false;
382
384
  }
383
385
 
@@ -404,12 +406,9 @@ function isInStrictMode() {
404
406
  return false;
405
407
  }
406
408
 
407
- let {
408
- node
409
- } = path;
410
- if (path.isFunction()) node = node.body;
409
+ const body = path.isFunction() ? path.node.body : path.node;
411
410
 
412
- for (const directive of node.directives) {
411
+ for (const directive of body.directives) {
413
412
  if (directive.value.value === "use strict") {
414
413
  return true;
415
414
  }
@@ -48,6 +48,13 @@ const referenceVisitor = {
48
48
 
49
49
  class PathHoister {
50
50
  constructor(path, scope) {
51
+ this.breakOnScopePaths = void 0;
52
+ this.bindings = void 0;
53
+ this.mutableBinding = void 0;
54
+ this.scopes = void 0;
55
+ this.scope = void 0;
56
+ this.path = void 0;
57
+ this.attachAfter = void 0;
51
58
  this.breakOnScopePaths = [];
52
59
  this.bindings = {};
53
60
  this.mutableBinding = false;
@@ -181,7 +188,7 @@ class PathHoister {
181
188
  const parent = this.path.parentPath;
182
189
 
183
190
  if (parent.isJSXElement() && this.path.container === parent.node.children) {
184
- uid = t.JSXExpressionContainer(uid);
191
+ uid = t.jsxExpressionContainer(uid);
185
192
  }
186
193
 
187
194
  this.path.replaceWith(t.cloneNode(uid));
@@ -28,10 +28,11 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
28
28
 
29
29
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
30
30
 
31
- function insertBefore(nodes) {
31
+ function insertBefore(nodes_) {
32
32
  this._assertUnremoved();
33
33
 
34
- nodes = this._verifyNodeList(nodes);
34
+ const nodes = this._verifyNodeList(nodes_);
35
+
35
36
  const {
36
37
  parentPath
37
38
  } = this;
@@ -44,8 +45,9 @@ function insertBefore(nodes) {
44
45
  } else if (Array.isArray(this.container)) {
45
46
  return this._containerInsertBefore(nodes);
46
47
  } else if (this.isStatementOrBlock()) {
47
- const shouldInsertCurrentNode = this.node && (!this.isExpressionStatement() || this.node.expression != null);
48
- this.replaceWith(t.blockStatement(shouldInsertCurrentNode ? [this.node] : []));
48
+ const node = this.node;
49
+ const shouldInsertCurrentNode = node && (!this.isExpressionStatement() || node.expression != null);
50
+ this.replaceWith(t.blockStatement(shouldInsertCurrentNode ? [node] : []));
49
51
  return this.unshiftContainer("body", nodes);
50
52
  } else {
51
53
  throw new Error("We don't know what to do with this node type. " + "We were previously a Statement but we can't fit in here?");
@@ -89,10 +91,11 @@ function _containerInsertAfter(nodes) {
89
91
  return this._containerInsert(this.key + 1, nodes);
90
92
  }
91
93
 
92
- function insertAfter(nodes) {
94
+ function insertAfter(nodes_) {
93
95
  this._assertUnremoved();
94
96
 
95
- nodes = this._verifyNodeList(nodes);
97
+ const nodes = this._verifyNodeList(nodes_);
98
+
96
99
  const {
97
100
  parentPath
98
101
  } = this;
@@ -103,19 +106,27 @@ function insertAfter(nodes) {
103
106
  }));
104
107
  } else if (this.isNodeType("Expression") && !this.isJSXElement() && !parentPath.isJSXElement() || parentPath.isForStatement() && this.key === "init") {
105
108
  if (this.node) {
109
+ const node = this.node;
106
110
  let {
107
111
  scope
108
112
  } = this;
109
113
 
114
+ if (scope.path.isPattern()) {
115
+ t.assertExpression(node);
116
+ this.replaceWith(t.callExpression(t.arrowFunctionExpression([], node), []));
117
+ this.get("callee.body").insertAfter(nodes);
118
+ return [this];
119
+ }
120
+
110
121
  if (parentPath.isMethod({
111
122
  computed: true,
112
- key: this.node
123
+ key: node
113
124
  })) {
114
125
  scope = scope.parent;
115
126
  }
116
127
 
117
128
  const temp = scope.generateDeclaredUidIdentifier();
118
- nodes.unshift(t.expressionStatement(t.assignmentExpression("=", t.cloneNode(temp), this.node)));
129
+ nodes.unshift(t.expressionStatement(t.assignmentExpression("=", t.cloneNode(temp), node)));
119
130
  nodes.push(t.expressionStatement(t.cloneNode(temp)));
120
131
  }
121
132
 
@@ -123,8 +134,9 @@ function insertAfter(nodes) {
123
134
  } else if (Array.isArray(this.container)) {
124
135
  return this._containerInsertAfter(nodes);
125
136
  } else if (this.isStatementOrBlock()) {
126
- const shouldInsertCurrentNode = this.node && (!this.isExpressionStatement() || this.node.expression != null);
127
- this.replaceWith(t.blockStatement(shouldInsertCurrentNode ? [this.node] : []));
137
+ const node = this.node;
138
+ const shouldInsertCurrentNode = node && (!this.isExpressionStatement() || node.expression != null);
139
+ this.replaceWith(t.blockStatement(shouldInsertCurrentNode ? [node] : []));
128
140
  return this.pushContainer("body", nodes);
129
141
  } else {
130
142
  throw new Error("We don't know what to do with this node type. " + "We were previously a Statement but we can't fit in here?");
@@ -148,7 +160,7 @@ function _verifyNodeList(nodes) {
148
160
  return [];
149
161
  }
150
162
 
151
- if (nodes.constructor !== Array) {
163
+ if (!Array.isArray(nodes)) {
152
164
  nodes = [nodes];
153
165
  }
154
166
 
@@ -186,7 +198,7 @@ function unshiftContainer(listKey, nodes) {
186
198
  container: this.node[listKey],
187
199
  listKey,
188
200
  key: 0
189
- });
201
+ }).setContext(this.context);
190
202
 
191
203
  return path._containerInsertBefore(nodes);
192
204
  }
@@ -194,7 +206,8 @@ function unshiftContainer(listKey, nodes) {
194
206
  function pushContainer(listKey, nodes) {
195
207
  this._assertUnremoved();
196
208
 
197
- nodes = this._verifyNodeList(nodes);
209
+ const verifiedNodes = this._verifyNodeList(nodes);
210
+
198
211
  const container = this.node[listKey];
199
212
 
200
213
  const path = _index.default.get({
@@ -203,9 +216,9 @@ function pushContainer(listKey, nodes) {
203
216
  container: container,
204
217
  listKey,
205
218
  key: container.length
206
- });
219
+ }).setContext(this.context);
207
220
 
208
- return path.replaceWithMultiple(nodes);
221
+ return path.replaceWithMultiple(verifiedNodes);
209
222
  }
210
223
 
211
224
  function hoist(scope = this.scope) {
@@ -14,7 +14,11 @@ var _removalHooks = require("./lib/removal-hooks");
14
14
 
15
15
  var _cache = require("../cache");
16
16
 
17
- var _index = require("./index");
17
+ var _index = _interopRequireWildcard(require("./index"));
18
+
19
+ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
20
+
21
+ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
18
22
 
19
23
  function remove() {
20
24
  var _this$opts;
@@ -57,13 +57,13 @@ const hoistVariablesVisitor = {
57
57
  };
58
58
 
59
59
  function replaceWithMultiple(nodes) {
60
+ var _pathCache$get;
61
+
60
62
  this.resync();
61
63
  nodes = this._verifyNodeList(nodes);
62
64
  t.inheritLeadingComments(nodes[0], this.node);
63
65
  t.inheritTrailingComments(nodes[nodes.length - 1], this.node);
64
-
65
- _cache.path.get(this.parent).delete(this.node);
66
-
66
+ (_pathCache$get = _cache.path.get(this.parent)) == null ? void 0 : _pathCache$get.delete(this.node);
67
67
  this.node = this.container[this.key] = null;
68
68
  const paths = this.insertAfter(nodes);
69
69
 
@@ -167,6 +167,8 @@ function replaceWith(replacement) {
167
167
  }
168
168
 
169
169
  function _replaceWith(node) {
170
+ var _pathCache$get2;
171
+
170
172
  if (!this.container) {
171
173
  throw new ReferenceError("Container is falsy");
172
174
  }
@@ -178,6 +180,7 @@ function _replaceWith(node) {
178
180
  }
179
181
 
180
182
  this.debug(`Replace with ${node == null ? void 0 : node.type}`);
183
+ (_pathCache$get2 = _cache.path.get(this.parent)) == null ? void 0 : _pathCache$get2.set(node, this).delete(this.node);
181
184
  this.node = this.container[this.key] = node;
182
185
  }
183
186
 
@@ -12,6 +12,10 @@ class Binding {
12
12
  path,
13
13
  kind
14
14
  }) {
15
+ this.identifier = void 0;
16
+ this.scope = void 0;
17
+ this.path = void 0;
18
+ this.kind = void 0;
15
19
  this.constantViolations = [];
16
20
  this.constant = true;
17
21
  this.referencePaths = [];
@@ -27,11 +27,11 @@ function gatherNodeParts(node, parts) {
27
27
  switch (node == null ? void 0 : node.type) {
28
28
  default:
29
29
  if (t.isModuleDeclaration(node)) {
30
- if (node.source) {
30
+ if ((t.isExportAllDeclaration(node) || t.isExportNamedDeclaration(node) || t.isImportDeclaration(node)) && node.source) {
31
31
  gatherNodeParts(node.source, parts);
32
- } else if (node.specifiers && node.specifiers.length) {
32
+ } else if ((t.isExportNamedDeclaration(node) || t.isImportDeclaration(node)) && node.specifiers && node.specifiers.length) {
33
33
  for (const e of node.specifiers) gatherNodeParts(e, parts);
34
- } else if (node.declaration) {
34
+ } else if ((t.isExportDefaultDeclaration(node) || t.isExportNamedDeclaration(node)) && node.declaration) {
35
35
  gatherNodeParts(node.declaration, parts);
36
36
  }
37
37
  } else if (t.isModuleSpecifier(node)) {
@@ -293,6 +293,17 @@ let uid = 0;
293
293
 
294
294
  class Scope {
295
295
  constructor(path) {
296
+ this.uid = void 0;
297
+ this.path = void 0;
298
+ this.block = void 0;
299
+ this.labels = void 0;
300
+ this.inited = void 0;
301
+ this.bindings = void 0;
302
+ this.references = void 0;
303
+ this.globals = void 0;
304
+ this.uids = void 0;
305
+ this.data = void 0;
306
+ this.crawling = void 0;
296
307
  const {
297
308
  node
298
309
  } = path;
@@ -848,10 +859,10 @@ class Scope {
848
859
  return ids;
849
860
  }
850
861
 
851
- getAllBindingsOfKind() {
862
+ getAllBindingsOfKind(...kinds) {
852
863
  const ids = Object.create(null);
853
864
 
854
- for (const kind of arguments) {
865
+ for (const kind of kinds) {
855
866
  let scope = this;
856
867
 
857
868
  do {
@@ -104,7 +104,15 @@ class Renamer {
104
104
  }
105
105
  }
106
106
 
107
- scope.traverse(block || scope.block, renameVisitor, this);
107
+ const blockToTraverse = block || scope.block;
108
+
109
+ if ((blockToTraverse == null ? void 0 : blockToTraverse.type) === "SwitchStatement") {
110
+ blockToTraverse.cases.forEach(c => {
111
+ scope.traverse(c, renameVisitor, this);
112
+ });
113
+ } else {
114
+ scope.traverse(blockToTraverse, renameVisitor, this);
115
+ }
108
116
 
109
117
  if (!block) {
110
118
  scope.removeOwnBinding(oldName);
@@ -112,8 +120,6 @@ class Renamer {
112
120
  this.binding.identifier.name = newName;
113
121
  }
114
122
 
115
- if (binding.type === "hoisted") {}
116
-
117
123
  if (parentDeclar) {
118
124
  this.maybeConvertFromClassFunctionDeclaration(parentDeclar);
119
125
  this.maybeConvertFromClassFunctionExpression(parentDeclar);
package/lib/types.js ADDED
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ var t = _interopRequireWildcard(require("@babel/types"));
4
+
5
+ var _index = require("./index");
6
+
7
+ var _virtualTypes = require("./path/generated/virtual-types");
8
+
9
+ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
10
+
11
+ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@babel/traverse",
3
- "version": "7.12.8",
3
+ "version": "7.12.13",
4
4
  "description": "The Babel Traverse module maintains the overall tree state, and is responsible for replacing, removing, and adding nodes",
5
5
  "author": "Sebastian McKenzie <sebmck@gmail.com>",
6
- "homepage": "https://babeljs.io/",
6
+ "homepage": "https://babel.dev/docs/en/next/babel-traverse",
7
+ "bugs": "https://github.com/babel/babel/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3A%22pkg%3A%20traverse%22+is%3Aopen",
7
8
  "license": "MIT",
8
9
  "publishConfig": {
9
10
  "access": "public"
@@ -15,17 +16,17 @@
15
16
  },
16
17
  "main": "lib/index.js",
17
18
  "dependencies": {
18
- "@babel/code-frame": "^7.10.4",
19
- "@babel/generator": "^7.12.5",
20
- "@babel/helper-function-name": "^7.10.4",
21
- "@babel/helper-split-export-declaration": "^7.11.0",
22
- "@babel/parser": "^7.12.7",
23
- "@babel/types": "^7.12.7",
19
+ "@babel/code-frame": "^7.12.13",
20
+ "@babel/generator": "^7.12.13",
21
+ "@babel/helper-function-name": "^7.12.13",
22
+ "@babel/helper-split-export-declaration": "^7.12.13",
23
+ "@babel/parser": "^7.12.13",
24
+ "@babel/types": "^7.12.13",
24
25
  "debug": "^4.1.0",
25
26
  "globals": "^11.1.0",
26
27
  "lodash": "^4.17.19"
27
28
  },
28
29
  "devDependencies": {
29
- "@babel/helper-plugin-test-runner": "7.10.4"
30
+ "@babel/helper-plugin-test-runner": "7.12.13"
30
31
  }
31
32
  }
@@ -0,0 +1,25 @@
1
+ import t from "@babel/types";
2
+
3
+ export default function generateAsserts() {
4
+ let output = `/*
5
+ * This file is auto-generated! Do not modify it directly.
6
+ * To re-generate run 'make build'
7
+ */
8
+ import * as t from "@babel/types";
9
+ import NodePath from "../index";
10
+
11
+
12
+ export interface NodePathAssetions {`;
13
+
14
+ for (const type of [...t.TYPES].sort()) {
15
+ output += `
16
+ assert${type}(
17
+ opts?: object,
18
+ ): asserts this is NodePath<t.${type}>;`;
19
+ }
20
+
21
+ output += `
22
+ }`;
23
+
24
+ return output;
25
+ }
@@ -0,0 +1,34 @@
1
+ import t from "@babel/types";
2
+ import virtualTypes from "../../lib/path/lib/virtual-types.js";
3
+ import definitions from "@babel/types/lib/definitions/index.js";
4
+
5
+ export default function generateValidators() {
6
+ let output = `/*
7
+ * This file is auto-generated! Do not modify it directly.
8
+ * To re-generate run 'make build'
9
+ */
10
+ import * as t from "@babel/types";
11
+ import NodePath from "../index";
12
+
13
+ export interface NodePathValidators {
14
+ `;
15
+
16
+ for (const type of [...t.TYPES].sort()) {
17
+ output += `is${type}(opts?: object): this is NodePath<t.${type}>;`;
18
+ }
19
+
20
+ for (const type of Object.keys(virtualTypes)) {
21
+ if (type[0] === "_") continue;
22
+ if (definitions.NODE_FIELDS[type] || definitions.FLIPPED_ALIAS_KEYS[type]) {
23
+ output += `is${type}(opts?: object): this is NodePath<t.${type}>;`;
24
+ } else {
25
+ output += `is${type}(opts?: object): boolean;`;
26
+ }
27
+ }
28
+
29
+ output += `
30
+ }
31
+ `;
32
+
33
+ return output;
34
+ }
@@ -0,0 +1,24 @@
1
+ import virtualTypes from "../../lib/path/lib/virtual-types.js";
2
+
3
+ export default function generateValidators() {
4
+ let output = `/*
5
+ * This file is auto-generated! Do not modify it directly.
6
+ * To re-generate run 'make build'
7
+ */
8
+ import * as t from "@babel/types";
9
+
10
+ export interface VirtualTypeAliases {
11
+ `;
12
+
13
+ for (const type of Object.keys(virtualTypes)) {
14
+ output += ` ${type}: ${(virtualTypes[type].types || ["Node"])
15
+ .map(t => `t.${t}`)
16
+ .join(" | ")};`;
17
+ }
18
+
19
+ output += `
20
+ }
21
+ `;
22
+
23
+ return output;
24
+ }
@@ -0,0 +1 @@
1
+ { "type": "module" }