@babel/traverse 7.15.4 → 7.16.7

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/index.js CHANGED
@@ -3,22 +3,22 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- Object.defineProperty(exports, "NodePath", {
6
+ Object.defineProperty(exports, "Hub", {
7
7
  enumerable: true,
8
8
  get: function () {
9
- return _path.default;
9
+ return _hub.default;
10
10
  }
11
11
  });
12
- Object.defineProperty(exports, "Scope", {
12
+ Object.defineProperty(exports, "NodePath", {
13
13
  enumerable: true,
14
14
  get: function () {
15
- return _scope.default;
15
+ return _path.default;
16
16
  }
17
17
  });
18
- Object.defineProperty(exports, "Hub", {
18
+ Object.defineProperty(exports, "Scope", {
19
19
  enumerable: true,
20
20
  get: function () {
21
- return _hub.default;
21
+ return _scope.default;
22
22
  }
23
23
  });
24
24
  exports.visitors = exports.default = void 0;
@@ -3,16 +3,16 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.findParent = findParent;
7
6
  exports.find = find;
7
+ exports.findParent = findParent;
8
+ exports.getAncestry = getAncestry;
9
+ exports.getDeepestCommonAncestorFrom = getDeepestCommonAncestorFrom;
10
+ exports.getEarliestCommonAncestorFrom = getEarliestCommonAncestorFrom;
8
11
  exports.getFunctionParent = getFunctionParent;
9
12
  exports.getStatementParent = getStatementParent;
10
- exports.getEarliestCommonAncestorFrom = getEarliestCommonAncestorFrom;
11
- exports.getDeepestCommonAncestorFrom = getDeepestCommonAncestorFrom;
12
- exports.getAncestry = getAncestry;
13
+ exports.inType = inType;
13
14
  exports.isAncestor = isAncestor;
14
15
  exports.isDescendant = isDescendant;
15
- exports.inType = inType;
16
16
 
17
17
  var _t = require("@babel/types");
18
18
 
@@ -3,9 +3,9 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.shareCommentsWithSiblings = shareCommentsWithSiblings;
7
6
  exports.addComment = addComment;
8
7
  exports.addComments = addComments;
8
+ exports.shareCommentsWithSiblings = shareCommentsWithSiblings;
9
9
 
10
10
  var _t = require("@babel/types");
11
11
 
@@ -3,26 +3,26 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.call = call;
7
6
  exports._call = _call;
8
- exports.isBlacklisted = exports.isDenylisted = isDenylisted;
9
- exports.visit = visit;
10
- exports.skip = skip;
11
- exports.skipKey = skipKey;
12
- exports.stop = stop;
13
- exports.setScope = setScope;
14
- exports.setContext = setContext;
15
- exports.resync = resync;
16
- exports._resyncParent = _resyncParent;
7
+ exports._getQueueContexts = _getQueueContexts;
17
8
  exports._resyncKey = _resyncKey;
18
9
  exports._resyncList = _resyncList;
10
+ exports._resyncParent = _resyncParent;
19
11
  exports._resyncRemoved = _resyncRemoved;
12
+ exports.call = call;
13
+ exports.isBlacklisted = exports.isDenylisted = isDenylisted;
20
14
  exports.popContext = popContext;
21
15
  exports.pushContext = pushContext;
22
- exports.setup = setup;
23
- exports.setKey = setKey;
24
16
  exports.requeue = requeue;
25
- exports._getQueueContexts = _getQueueContexts;
17
+ exports.resync = resync;
18
+ exports.setContext = setContext;
19
+ exports.setKey = setKey;
20
+ exports.setScope = setScope;
21
+ exports.setup = setup;
22
+ exports.skip = skip;
23
+ exports.skipKey = skipKey;
24
+ exports.stop = stop;
25
+ exports.visit = visit;
26
26
 
27
27
  var _index = require("../index");
28
28
 
@@ -74,6 +74,14 @@ function isDenylisted() {
74
74
  return denylist && denylist.indexOf(this.node.type) > -1;
75
75
  }
76
76
 
77
+ function restoreContext(path, context) {
78
+ if (path.context !== context) {
79
+ path.context = context;
80
+ path.state = context.state;
81
+ path.opts = context.opts;
82
+ }
83
+ }
84
+
77
85
  function visit() {
78
86
  if (!this.node) {
79
87
  return false;
@@ -87,15 +95,19 @@ function visit() {
87
95
  return false;
88
96
  }
89
97
 
90
- if (this.shouldSkip || this.call("enter") || this.shouldSkip) {
98
+ const currentContext = this.context;
99
+
100
+ if (this.shouldSkip || this.call("enter")) {
91
101
  this.debug("Skip...");
92
102
  return this.shouldStop;
93
103
  }
94
104
 
105
+ restoreContext(this, currentContext);
95
106
  this.debug("Recursing into...");
96
107
 
97
108
  _index.default.node(this.node, this.opts, this.scope, this.state, this, this.skipKeys);
98
109
 
110
+ restoreContext(this, currentContext);
99
111
  this.call("exit");
100
112
  return this.shouldStop;
101
113
  }
@@ -3,16 +3,20 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.toComputedKey = toComputedKey;
7
- exports.ensureBlock = ensureBlock;
6
+ exports.arrowFunctionToExpression = arrowFunctionToExpression;
8
7
  exports.arrowFunctionToShadowed = arrowFunctionToShadowed;
8
+ exports.ensureBlock = ensureBlock;
9
+ exports.toComputedKey = toComputedKey;
9
10
  exports.unwrapFunctionEnvironment = unwrapFunctionEnvironment;
10
- exports.arrowFunctionToExpression = arrowFunctionToExpression;
11
11
 
12
12
  var _t = require("@babel/types");
13
13
 
14
+ var _helperEnvironmentVisitor = require("@babel/helper-environment-visitor");
15
+
14
16
  var _helperFunctionName = require("@babel/helper-function-name");
15
17
 
18
+ var _visitors = require("../visitors");
19
+
16
20
  const {
17
21
  arrowFunctionExpression,
18
22
  assignmentExpression,
@@ -35,6 +39,7 @@ const {
35
39
  stringLiteral,
36
40
  super: _super,
37
41
  thisExpression,
42
+ toExpression,
38
43
  unaryExpression
39
44
  } = _t;
40
45
 
@@ -121,35 +126,68 @@ function arrowFunctionToExpression({
121
126
  throw this.buildCodeFrameError("Cannot convert non-arrow function to a function expression.");
122
127
  }
123
128
 
124
- const thisBinding = hoistFunctionEnvironment(this, noNewArrows, allowInsertArrow);
125
- this.ensureBlock();
126
- this.node.type = "FunctionExpression";
129
+ const {
130
+ thisBinding,
131
+ fnPath: fn
132
+ } = hoistFunctionEnvironment(this, noNewArrows, allowInsertArrow);
133
+ fn.ensureBlock();
134
+ fn.node.type = "FunctionExpression";
127
135
 
128
136
  if (!noNewArrows) {
129
- const checkBinding = thisBinding ? null : this.parentPath.scope.generateUidIdentifier("arrowCheckId");
137
+ const checkBinding = thisBinding ? null : fn.scope.generateUidIdentifier("arrowCheckId");
130
138
 
131
139
  if (checkBinding) {
132
- this.parentPath.scope.push({
140
+ fn.parentPath.scope.push({
133
141
  id: checkBinding,
134
142
  init: objectExpression([])
135
143
  });
136
144
  }
137
145
 
138
- this.get("body").unshiftContainer("body", expressionStatement(callExpression(this.hub.addHelper("newArrowCheck"), [thisExpression(), checkBinding ? identifier(checkBinding.name) : identifier(thisBinding)])));
139
- this.replaceWith(callExpression(memberExpression((0, _helperFunctionName.default)(this, true) || this.node, identifier("bind")), [checkBinding ? identifier(checkBinding.name) : thisExpression()]));
146
+ fn.get("body").unshiftContainer("body", expressionStatement(callExpression(this.hub.addHelper("newArrowCheck"), [thisExpression(), checkBinding ? identifier(checkBinding.name) : identifier(thisBinding)])));
147
+ fn.replaceWith(callExpression(memberExpression((0, _helperFunctionName.default)(this, true) || fn.node, identifier("bind")), [checkBinding ? identifier(checkBinding.name) : thisExpression()]));
140
148
  }
141
149
  }
142
150
 
151
+ const getSuperCallsVisitor = (0, _visitors.merge)([{
152
+ CallExpression(child, {
153
+ allSuperCalls
154
+ }) {
155
+ if (!child.get("callee").isSuper()) return;
156
+ allSuperCalls.push(child);
157
+ }
158
+
159
+ }, _helperEnvironmentVisitor.default]);
160
+
143
161
  function hoistFunctionEnvironment(fnPath, noNewArrows = true, allowInsertArrow = true) {
144
- const thisEnvFn = fnPath.findParent(p => {
145
- return p.isFunction() && !p.isArrowFunctionExpression() || p.isProgram() || p.isClassProperty({
162
+ let arrowParent;
163
+ let thisEnvFn = fnPath.findParent(p => {
164
+ if (p.isArrowFunctionExpression()) {
165
+ var _arrowParent;
166
+
167
+ (_arrowParent = arrowParent) != null ? _arrowParent : arrowParent = p;
168
+ return false;
169
+ }
170
+
171
+ return p.isFunction() || p.isProgram() || p.isClassProperty({
172
+ static: false
173
+ }) || p.isClassPrivateProperty({
146
174
  static: false
147
175
  });
148
176
  });
149
- const inConstructor = (thisEnvFn == null ? void 0 : thisEnvFn.node.kind) === "constructor";
177
+ const inConstructor = thisEnvFn.isClassMethod({
178
+ kind: "constructor"
179
+ });
150
180
 
151
- if (thisEnvFn.isClassProperty()) {
152
- throw fnPath.buildCodeFrameError("Unable to transform arrow inside class property");
181
+ if (thisEnvFn.isClassProperty() || thisEnvFn.isClassPrivateProperty()) {
182
+ if (arrowParent) {
183
+ thisEnvFn = arrowParent;
184
+ } else if (allowInsertArrow) {
185
+ fnPath.replaceWith(callExpression(arrowFunctionExpression([], toExpression(fnPath.node)), []));
186
+ thisEnvFn = fnPath.get("callee");
187
+ fnPath = thisEnvFn.get("body");
188
+ } else {
189
+ throw fnPath.buildCodeFrameError("Unable to transform arrow inside class property");
190
+ }
153
191
  }
154
192
 
155
193
  const {
@@ -166,21 +204,8 @@ function hoistFunctionEnvironment(fnPath, noNewArrows = true, allowInsertArrow =
166
204
  }
167
205
 
168
206
  const allSuperCalls = [];
169
- thisEnvFn.traverse({
170
- Function(child) {
171
- if (child.isArrowFunctionExpression()) return;
172
- child.skip();
173
- },
174
-
175
- ClassProperty(child) {
176
- child.skip();
177
- },
178
-
179
- CallExpression(child) {
180
- if (!child.get("callee").isSuper()) return;
181
- allSuperCalls.push(child);
182
- }
183
-
207
+ thisEnvFn.traverse(getSuperCallsVisitor, {
208
+ allSuperCalls
184
209
  });
185
210
  const superBinding = getSuperBinding(thisEnvFn);
186
211
  allSuperCalls.forEach(superCall => {
@@ -271,7 +296,10 @@ function hoistFunctionEnvironment(fnPath, noNewArrows = true, allowInsertArrow =
271
296
  }
272
297
  }
273
298
 
274
- return thisBinding;
299
+ return {
300
+ thisBinding,
301
+ fnPath
302
+ };
275
303
  }
276
304
 
277
305
  function standardizeSuperProperty(superProp) {
@@ -314,27 +342,25 @@ function hasSuperClass(thisEnvFn) {
314
342
  return thisEnvFn.isClassMethod() && !!thisEnvFn.parentPath.parentPath.node.superClass;
315
343
  }
316
344
 
345
+ const assignSuperThisVisitor = (0, _visitors.merge)([{
346
+ CallExpression(child, {
347
+ supers,
348
+ thisBinding
349
+ }) {
350
+ if (!child.get("callee").isSuper()) return;
351
+ if (supers.has(child.node)) return;
352
+ supers.add(child.node);
353
+ child.replaceWithMultiple([child.node, assignmentExpression("=", identifier(thisBinding), identifier("this"))]);
354
+ }
355
+
356
+ }, _helperEnvironmentVisitor.default]);
357
+
317
358
  function getThisBinding(thisEnvFn, inConstructor) {
318
359
  return getBinding(thisEnvFn, "this", thisBinding => {
319
360
  if (!inConstructor || !hasSuperClass(thisEnvFn)) return thisExpression();
320
- const supers = new WeakSet();
321
- thisEnvFn.traverse({
322
- Function(child) {
323
- if (child.isArrowFunctionExpression()) return;
324
- child.skip();
325
- },
326
-
327
- ClassProperty(child) {
328
- child.skip();
329
- },
330
-
331
- CallExpression(child) {
332
- if (!child.get("callee").isSuper()) return;
333
- if (supers.has(child.node)) return;
334
- supers.add(child.node);
335
- child.replaceWithMultiple([child.node, assignmentExpression("=", identifier(thisBinding), identifier("this"))]);
336
- }
337
-
361
+ thisEnvFn.traverse(assignSuperThisVisitor, {
362
+ supers: new WeakSet(),
363
+ thisBinding
338
364
  });
339
365
  });
340
366
  }
@@ -387,76 +413,89 @@ function getBinding(thisEnvFn, key, init) {
387
413
  return data;
388
414
  }
389
415
 
416
+ const getScopeInformationVisitor = (0, _visitors.merge)([{
417
+ ThisExpression(child, {
418
+ thisPaths
419
+ }) {
420
+ thisPaths.push(child);
421
+ },
422
+
423
+ JSXIdentifier(child, {
424
+ thisPaths
425
+ }) {
426
+ if (child.node.name !== "this") return;
427
+
428
+ if (!child.parentPath.isJSXMemberExpression({
429
+ object: child.node
430
+ }) && !child.parentPath.isJSXOpeningElement({
431
+ name: child.node
432
+ })) {
433
+ return;
434
+ }
435
+
436
+ thisPaths.push(child);
437
+ },
438
+
439
+ CallExpression(child, {
440
+ superCalls
441
+ }) {
442
+ if (child.get("callee").isSuper()) superCalls.push(child);
443
+ },
444
+
445
+ MemberExpression(child, {
446
+ superProps
447
+ }) {
448
+ if (child.get("object").isSuper()) superProps.push(child);
449
+ },
450
+
451
+ Identifier(child, {
452
+ argumentsPaths
453
+ }) {
454
+ if (!child.isReferencedIdentifier({
455
+ name: "arguments"
456
+ })) return;
457
+ let curr = child.scope;
458
+
459
+ do {
460
+ if (curr.hasOwnBinding("arguments")) {
461
+ curr.rename("arguments");
462
+ return;
463
+ }
464
+
465
+ if (curr.path.isFunction() && !curr.path.isArrowFunctionExpression()) {
466
+ break;
467
+ }
468
+ } while (curr = curr.parent);
469
+
470
+ argumentsPaths.push(child);
471
+ },
472
+
473
+ MetaProperty(child, {
474
+ newTargetPaths
475
+ }) {
476
+ if (!child.get("meta").isIdentifier({
477
+ name: "new"
478
+ })) return;
479
+ if (!child.get("property").isIdentifier({
480
+ name: "target"
481
+ })) return;
482
+ newTargetPaths.push(child);
483
+ }
484
+
485
+ }, _helperEnvironmentVisitor.default]);
486
+
390
487
  function getScopeInformation(fnPath) {
391
488
  const thisPaths = [];
392
489
  const argumentsPaths = [];
393
490
  const newTargetPaths = [];
394
491
  const superProps = [];
395
492
  const superCalls = [];
396
- fnPath.traverse({
397
- ClassProperty(child) {
398
- child.skip();
399
- },
400
-
401
- Function(child) {
402
- if (child.isArrowFunctionExpression()) return;
403
- child.skip();
404
- },
405
-
406
- ThisExpression(child) {
407
- thisPaths.push(child);
408
- },
409
-
410
- JSXIdentifier(child) {
411
- if (child.node.name !== "this") return;
412
-
413
- if (!child.parentPath.isJSXMemberExpression({
414
- object: child.node
415
- }) && !child.parentPath.isJSXOpeningElement({
416
- name: child.node
417
- })) {
418
- return;
419
- }
420
-
421
- thisPaths.push(child);
422
- },
423
-
424
- CallExpression(child) {
425
- if (child.get("callee").isSuper()) superCalls.push(child);
426
- },
427
-
428
- MemberExpression(child) {
429
- if (child.get("object").isSuper()) superProps.push(child);
430
- },
431
-
432
- ReferencedIdentifier(child) {
433
- if (child.node.name !== "arguments") return;
434
- let curr = child.scope;
435
-
436
- do {
437
- if (curr.hasOwnBinding("arguments")) {
438
- curr.rename("arguments");
439
- return;
440
- }
441
-
442
- if (curr.path.isFunction() && !curr.path.isArrowFunctionExpression()) {
443
- break;
444
- }
445
- } while (curr = curr.parent);
446
-
447
- argumentsPaths.push(child);
448
- },
449
-
450
- MetaProperty(child) {
451
- if (!child.get("meta").isIdentifier({
452
- name: "new"
453
- })) return;
454
- if (!child.get("property").isIdentifier({
455
- name: "target"
456
- })) return;
457
- newTargetPaths.push(child);
458
- }
459
-
493
+ fnPath.traverse(getScopeInformationVisitor, {
494
+ thisPaths,
495
+ argumentsPaths,
496
+ newTargetPaths,
497
+ superProps,
498
+ superCalls
460
499
  });
461
500
  return {
462
501
  thisPaths,
@@ -3,8 +3,8 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.evaluateTruthy = evaluateTruthy;
7
6
  exports.evaluate = evaluate;
7
+ exports.evaluateTruthy = evaluateTruthy;
8
8
  const VALID_CALLEES = ["String", "Number", "Math"];
9
9
  const INVALID_METHODS = ["random"];
10
10
 
@@ -3,20 +3,20 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getOpposite = getOpposite;
7
- exports.getCompletionRecords = getCompletionRecords;
8
- exports.getSibling = getSibling;
9
- exports.getPrevSibling = getPrevSibling;
10
- exports.getNextSibling = getNextSibling;
11
- exports.getAllNextSiblings = getAllNextSiblings;
12
- exports.getAllPrevSiblings = getAllPrevSiblings;
13
- exports.get = get;
14
6
  exports._getKey = _getKey;
15
7
  exports._getPattern = _getPattern;
16
- exports.getBindingIdentifiers = getBindingIdentifiers;
17
- exports.getOuterBindingIdentifiers = getOuterBindingIdentifiers;
8
+ exports.get = get;
9
+ exports.getAllNextSiblings = getAllNextSiblings;
10
+ exports.getAllPrevSiblings = getAllPrevSiblings;
18
11
  exports.getBindingIdentifierPaths = getBindingIdentifierPaths;
12
+ exports.getBindingIdentifiers = getBindingIdentifiers;
13
+ exports.getCompletionRecords = getCompletionRecords;
14
+ exports.getNextSibling = getNextSibling;
15
+ exports.getOpposite = getOpposite;
19
16
  exports.getOuterBindingIdentifierPaths = getOuterBindingIdentifierPaths;
17
+ exports.getOuterBindingIdentifiers = getOuterBindingIdentifiers;
18
+ exports.getPrevSibling = getPrevSibling;
19
+ exports.getSibling = getSibling;
20
20
 
21
21
  var _index = require("./index");
22
22
 
package/lib/path/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = exports.SHOULD_SKIP = exports.SHOULD_STOP = exports.REMOVED = void 0;
6
+ exports.default = exports.SHOULD_STOP = exports.SHOULD_SKIP = exports.REMOVED = void 0;
7
7
 
8
8
  var virtualTypes = require("./lib/virtual-types");
9
9
 
@@ -3,11 +3,11 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getTypeAnnotation = getTypeAnnotation;
7
6
  exports._getTypeAnnotation = _getTypeAnnotation;
8
- exports.isBaseType = isBaseType;
9
- exports.couldBeBaseType = couldBeBaseType;
10
7
  exports.baseTypeStrictlyMatches = baseTypeStrictlyMatches;
8
+ exports.couldBeBaseType = couldBeBaseType;
9
+ exports.getTypeAnnotation = getTypeAnnotation;
10
+ exports.isBaseType = isBaseType;
11
11
  exports.isGenericType = isGenericType;
12
12
 
13
13
  var inferers = require("./inferers");
@@ -3,35 +3,35 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.VariableDeclarator = VariableDeclarator;
7
- exports.TypeCastExpression = TypeCastExpression;
8
- exports.NewExpression = NewExpression;
9
- exports.TemplateLiteral = TemplateLiteral;
10
- exports.UnaryExpression = UnaryExpression;
11
- exports.BinaryExpression = BinaryExpression;
12
- exports.LogicalExpression = LogicalExpression;
13
- exports.ConditionalExpression = ConditionalExpression;
14
- exports.SequenceExpression = SequenceExpression;
15
- exports.ParenthesizedExpression = ParenthesizedExpression;
6
+ exports.ArrayExpression = ArrayExpression;
16
7
  exports.AssignmentExpression = AssignmentExpression;
17
- exports.UpdateExpression = UpdateExpression;
18
- exports.StringLiteral = StringLiteral;
19
- exports.NumericLiteral = NumericLiteral;
8
+ exports.BinaryExpression = BinaryExpression;
20
9
  exports.BooleanLiteral = BooleanLiteral;
21
- exports.NullLiteral = NullLiteral;
22
- exports.RegExpLiteral = RegExpLiteral;
23
- exports.ObjectExpression = ObjectExpression;
24
- exports.ArrayExpression = ArrayExpression;
25
- exports.RestElement = RestElement;
26
- exports.ClassDeclaration = exports.ClassExpression = exports.FunctionDeclaration = exports.ArrowFunctionExpression = exports.FunctionExpression = Func;
27
10
  exports.CallExpression = CallExpression;
28
- exports.TaggedTemplateExpression = TaggedTemplateExpression;
11
+ exports.ConditionalExpression = ConditionalExpression;
12
+ exports.ClassDeclaration = exports.ClassExpression = exports.FunctionDeclaration = exports.ArrowFunctionExpression = exports.FunctionExpression = Func;
29
13
  Object.defineProperty(exports, "Identifier", {
30
14
  enumerable: true,
31
15
  get: function () {
32
16
  return _infererReference.default;
33
17
  }
34
18
  });
19
+ exports.LogicalExpression = LogicalExpression;
20
+ exports.NewExpression = NewExpression;
21
+ exports.NullLiteral = NullLiteral;
22
+ exports.NumericLiteral = NumericLiteral;
23
+ exports.ObjectExpression = ObjectExpression;
24
+ exports.ParenthesizedExpression = ParenthesizedExpression;
25
+ exports.RegExpLiteral = RegExpLiteral;
26
+ exports.RestElement = RestElement;
27
+ exports.SequenceExpression = SequenceExpression;
28
+ exports.StringLiteral = StringLiteral;
29
+ exports.TaggedTemplateExpression = TaggedTemplateExpression;
30
+ exports.TemplateLiteral = TemplateLiteral;
31
+ exports.TypeCastExpression = TypeCastExpression;
32
+ exports.UnaryExpression = UnaryExpression;
33
+ exports.UpdateExpression = UpdateExpression;
34
+ exports.VariableDeclarator = VariableDeclarator;
35
35
 
36
36
  var _t = require("@babel/types");
37
37
 
@@ -3,26 +3,26 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.matchesPattern = matchesPattern;
7
- exports.has = has;
8
- exports.isStatic = isStatic;
9
- exports.isnt = isnt;
10
- exports.equals = equals;
11
- exports.isNodeType = isNodeType;
6
+ exports._guessExecutionStatusRelativeTo = _guessExecutionStatusRelativeTo;
7
+ exports._guessExecutionStatusRelativeToDifferentFunctions = _guessExecutionStatusRelativeToDifferentFunctions;
8
+ exports._resolve = _resolve;
12
9
  exports.canHaveVariableDeclarationOrExpression = canHaveVariableDeclarationOrExpression;
13
10
  exports.canSwapBetweenExpressionAndStatement = canSwapBetweenExpressionAndStatement;
11
+ exports.equals = equals;
12
+ exports.getSource = getSource;
13
+ exports.has = has;
14
+ exports.is = void 0;
14
15
  exports.isCompletionRecord = isCompletionRecord;
16
+ exports.isConstantExpression = isConstantExpression;
17
+ exports.isInStrictMode = isInStrictMode;
18
+ exports.isNodeType = isNodeType;
15
19
  exports.isStatementOrBlock = isStatementOrBlock;
20
+ exports.isStatic = isStatic;
21
+ exports.isnt = isnt;
22
+ exports.matchesPattern = matchesPattern;
16
23
  exports.referencesImport = referencesImport;
17
- exports.getSource = getSource;
18
- exports.willIMaybeExecuteBefore = willIMaybeExecuteBefore;
19
- exports._guessExecutionStatusRelativeTo = _guessExecutionStatusRelativeTo;
20
- exports._guessExecutionStatusRelativeToDifferentFunctions = _guessExecutionStatusRelativeToDifferentFunctions;
21
24
  exports.resolve = resolve;
22
- exports._resolve = _resolve;
23
- exports.isConstantExpression = isConstantExpression;
24
- exports.isInStrictMode = isInStrictMode;
25
- exports.is = void 0;
25
+ exports.willIMaybeExecuteBefore = willIMaybeExecuteBefore;
26
26
 
27
27
  var _t = require("@babel/types");
28
28
 
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.ForAwaitStatement = exports.NumericLiteralTypeAnnotation = exports.ExistentialTypeParam = exports.SpreadProperty = exports.RestProperty = exports.Flow = exports.Pure = exports.Generated = exports.User = exports.Var = exports.BlockScoped = exports.Referenced = exports.Scope = exports.Expression = exports.Statement = exports.BindingIdentifier = exports.ReferencedMemberExpression = exports.ReferencedIdentifier = void 0;
6
+ exports.Var = exports.User = exports.Statement = exports.SpreadProperty = exports.Scope = exports.RestProperty = exports.ReferencedMemberExpression = exports.ReferencedIdentifier = exports.Referenced = exports.Pure = exports.NumericLiteralTypeAnnotation = exports.Generated = exports.ForAwaitStatement = exports.Flow = exports.Expression = exports.ExistentialTypeParam = exports.BlockScoped = exports.BindingIdentifier = void 0;
7
7
 
8
8
  var _t = require("@babel/types");
9
9
 
@@ -3,16 +3,16 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.insertBefore = insertBefore;
7
6
  exports._containerInsert = _containerInsert;
8
- exports._containerInsertBefore = _containerInsertBefore;
9
7
  exports._containerInsertAfter = _containerInsertAfter;
10
- exports.insertAfter = insertAfter;
11
- exports.updateSiblingKeys = updateSiblingKeys;
8
+ exports._containerInsertBefore = _containerInsertBefore;
12
9
  exports._verifyNodeList = _verifyNodeList;
13
- exports.unshiftContainer = unshiftContainer;
14
- exports.pushContainer = pushContainer;
15
10
  exports.hoist = hoist;
11
+ exports.insertAfter = insertAfter;
12
+ exports.insertBefore = insertBefore;
13
+ exports.pushContainer = pushContainer;
14
+ exports.unshiftContainer = unshiftContainer;
15
+ exports.updateSiblingKeys = updateSiblingKeys;
16
16
 
17
17
  var _cache = require("../cache");
18
18
 
@@ -3,12 +3,12 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.remove = remove;
7
- exports._removeFromScope = _removeFromScope;
6
+ exports._assertUnremoved = _assertUnremoved;
8
7
  exports._callRemovalHooks = _callRemovalHooks;
9
- exports._remove = _remove;
10
8
  exports._markRemoved = _markRemoved;
11
- exports._assertUnremoved = _assertUnremoved;
9
+ exports._remove = _remove;
10
+ exports._removeFromScope = _removeFromScope;
11
+ exports.remove = remove;
12
12
 
13
13
  var _removalHooks = require("./lib/removal-hooks");
14
14
 
@@ -3,12 +3,12 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.replaceWithMultiple = replaceWithMultiple;
7
- exports.replaceWithSourceString = replaceWithSourceString;
8
- exports.replaceWith = replaceWith;
9
6
  exports._replaceWith = _replaceWith;
10
7
  exports.replaceExpressionWithStatements = replaceExpressionWithStatements;
11
8
  exports.replaceInline = replaceInline;
9
+ exports.replaceWith = replaceWith;
10
+ exports.replaceWithMultiple = replaceWithMultiple;
11
+ exports.replaceWithSourceString = replaceWithSourceString;
12
12
 
13
13
  var _codeFrame = require("@babel/code-frame");
14
14
 
@@ -303,15 +303,15 @@ const collectorVisitor = {
303
303
  },
304
304
 
305
305
  Function(path) {
306
- if (path.isFunctionExpression() && path.has("id") && !path.get("id").node[NOT_LOCAL_BINDING]) {
307
- path.scope.registerBinding("local", path.get("id"), path);
308
- }
309
-
310
306
  const params = path.get("params");
311
307
 
312
308
  for (const param of params) {
313
309
  path.scope.registerBinding("param", param);
314
310
  }
311
+
312
+ if (path.isFunctionExpression() && path.has("id") && !path.get("id").node[NOT_LOCAL_BINDING]) {
313
+ path.scope.registerBinding("local", path.get("id"), path);
314
+ }
315
315
  },
316
316
 
317
317
  ClassExpression(path) {
@@ -575,6 +575,7 @@ class Scope {
575
575
  this.registerBinding(path.node.kind, declar);
576
576
  }
577
577
  } else if (path.isClassDeclaration()) {
578
+ if (path.node.declare) return;
578
579
  this.registerBinding("let", path);
579
580
  } else if (path.isImportDeclaration()) {
580
581
  const specifiers = path.get("specifiers");
@@ -937,9 +938,11 @@ class Scope {
937
938
  if (binding) {
938
939
  var _previousPath;
939
940
 
940
- if ((_previousPath = previousPath) != null && _previousPath.isPattern() && binding.kind !== "param") {} else {
941
+ if ((_previousPath = previousPath) != null && _previousPath.isPattern() && binding.kind !== "param" && binding.kind !== "local") {} else {
941
942
  return binding;
942
943
  }
944
+ } else if (!binding && name === "arguments" && scope.path.isFunction() && !scope.path.isArrowFunctionExpression()) {
945
+ break;
943
946
  }
944
947
 
945
948
  previousPath = scope.path;
package/lib/visitors.js CHANGED
@@ -4,8 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.explode = explode;
7
- exports.verify = verify;
8
7
  exports.merge = merge;
8
+ exports.verify = verify;
9
9
 
10
10
  var virtualTypes = require("./path/lib/virtual-types");
11
11
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babel/traverse",
3
- "version": "7.15.4",
3
+ "version": "7.16.7",
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",
@@ -16,18 +16,19 @@
16
16
  },
17
17
  "main": "./lib/index.js",
18
18
  "dependencies": {
19
- "@babel/code-frame": "^7.14.5",
20
- "@babel/generator": "^7.15.4",
21
- "@babel/helper-function-name": "^7.15.4",
22
- "@babel/helper-hoist-variables": "^7.15.4",
23
- "@babel/helper-split-export-declaration": "^7.15.4",
24
- "@babel/parser": "^7.15.4",
25
- "@babel/types": "^7.15.4",
19
+ "@babel/code-frame": "^7.16.7",
20
+ "@babel/generator": "^7.16.7",
21
+ "@babel/helper-environment-visitor": "^7.16.7",
22
+ "@babel/helper-function-name": "^7.16.7",
23
+ "@babel/helper-hoist-variables": "^7.16.7",
24
+ "@babel/helper-split-export-declaration": "^7.16.7",
25
+ "@babel/parser": "^7.16.7",
26
+ "@babel/types": "^7.16.7",
26
27
  "debug": "^4.1.0",
27
28
  "globals": "^11.1.0"
28
29
  },
29
30
  "devDependencies": {
30
- "@babel/helper-plugin-test-runner": "7.14.5"
31
+ "@babel/helper-plugin-test-runner": "^7.16.7"
31
32
  },
32
33
  "engines": {
33
34
  "node": ">=6.9.0"
@@ -1,6 +1,5 @@
1
1
  import t from "@babel/types";
2
2
  import virtualTypes from "../../lib/path/lib/virtual-types.js";
3
- import definitions from "@babel/types/lib/definitions/index.js";
4
3
 
5
4
  export default function generateValidators() {
6
5
  let output = `/*
@@ -21,7 +20,7 @@ export interface NodePathValidators {
21
20
  for (const type of Object.keys(virtualTypes)) {
22
21
  const { types } = virtualTypes[type];
23
22
  if (type[0] === "_") continue;
24
- if (definitions.NODE_FIELDS[type] || definitions.FLIPPED_ALIAS_KEYS[type]) {
23
+ if (t.NODE_FIELDS[type] || t.FLIPPED_ALIAS_KEYS[type]) {
25
24
  output += `is${type}(opts?: object): this is NodePath<t.${type}>;`;
26
25
  } else if (types /* in VirtualTypeAliases */) {
27
26
  output += `is${type}(opts?: object): this is NodePath<VirtualTypeAliases["${type}"]>;`;