@babel/traverse 7.14.8 → 7.16.0

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.

@@ -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
 
@@ -20,7 +20,18 @@ var _hoister = require("./lib/hoister");
20
20
 
21
21
  var _index = require("./index");
22
22
 
23
- var t = require("@babel/types");
23
+ var _t = require("@babel/types");
24
+
25
+ const {
26
+ arrowFunctionExpression,
27
+ assertExpression,
28
+ assignmentExpression,
29
+ blockStatement,
30
+ callExpression,
31
+ cloneNode,
32
+ expressionStatement,
33
+ isExpression
34
+ } = _t;
24
35
 
25
36
  function insertBefore(nodes_) {
26
37
  this._assertUnremoved();
@@ -41,7 +52,7 @@ function insertBefore(nodes_) {
41
52
  } else if (this.isStatementOrBlock()) {
42
53
  const node = this.node;
43
54
  const shouldInsertCurrentNode = node && (!this.isExpressionStatement() || node.expression != null);
44
- this.replaceWith(t.blockStatement(shouldInsertCurrentNode ? [node] : []));
55
+ this.replaceWith(blockStatement(shouldInsertCurrentNode ? [node] : []));
45
56
  return this.unshiftContainer("body", nodes);
46
57
  } else {
47
58
  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?");
@@ -96,7 +107,7 @@ function insertAfter(nodes_) {
96
107
 
97
108
  if (parentPath.isExpressionStatement() || parentPath.isLabeledStatement() || parentPath.isExportNamedDeclaration() || parentPath.isExportDefaultDeclaration() && this.isDeclaration()) {
98
109
  return parentPath.insertAfter(nodes.map(node => {
99
- return t.isExpression(node) ? t.expressionStatement(node) : node;
110
+ return isExpression(node) ? expressionStatement(node) : node;
100
111
  }));
101
112
  } else if (this.isNodeType("Expression") && !this.isJSXElement() && !parentPath.isJSXElement() || parentPath.isForStatement() && this.key === "init") {
102
113
  if (this.node) {
@@ -106,8 +117,8 @@ function insertAfter(nodes_) {
106
117
  } = this;
107
118
 
108
119
  if (scope.path.isPattern()) {
109
- t.assertExpression(node);
110
- this.replaceWith(t.callExpression(t.arrowFunctionExpression([], node), []));
120
+ assertExpression(node);
121
+ this.replaceWith(callExpression(arrowFunctionExpression([], node), []));
111
122
  this.get("callee.body").insertAfter(nodes);
112
123
  return [this];
113
124
  }
@@ -120,8 +131,8 @@ function insertAfter(nodes_) {
120
131
  }
121
132
 
122
133
  const temp = scope.generateDeclaredUidIdentifier();
123
- nodes.unshift(t.expressionStatement(t.assignmentExpression("=", t.cloneNode(temp), node)));
124
- nodes.push(t.expressionStatement(t.cloneNode(temp)));
134
+ nodes.unshift(expressionStatement(assignmentExpression("=", cloneNode(temp), node)));
135
+ nodes.push(expressionStatement(cloneNode(temp)));
125
136
  }
126
137
 
127
138
  return this.replaceExpressionWithStatements(nodes);
@@ -130,7 +141,7 @@ function insertAfter(nodes_) {
130
141
  } else if (this.isStatementOrBlock()) {
131
142
  const node = this.node;
132
143
  const shouldInsertCurrentNode = node && (!this.isExpressionStatement() || node.expression != null);
133
- this.replaceWith(t.blockStatement(shouldInsertCurrentNode ? [node] : []));
144
+ this.replaceWith(blockStatement(shouldInsertCurrentNode ? [node] : []));
134
145
  return this.pushContainer("body", nodes);
135
146
  } else {
136
147
  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?");
@@ -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
 
@@ -20,17 +20,40 @@ var _cache = require("../cache");
20
20
 
21
21
  var _parser = require("@babel/parser");
22
22
 
23
- var t = require("@babel/types");
23
+ var _t = require("@babel/types");
24
24
 
25
25
  var _helperHoistVariables = require("@babel/helper-hoist-variables");
26
26
 
27
+ const {
28
+ FUNCTION_TYPES,
29
+ arrowFunctionExpression,
30
+ assignmentExpression,
31
+ awaitExpression,
32
+ blockStatement,
33
+ callExpression,
34
+ cloneNode,
35
+ expressionStatement,
36
+ identifier,
37
+ inheritLeadingComments,
38
+ inheritTrailingComments,
39
+ inheritsComments,
40
+ isExpression,
41
+ isProgram,
42
+ isStatement,
43
+ removeComments,
44
+ returnStatement,
45
+ toSequenceExpression,
46
+ validate,
47
+ yieldExpression
48
+ } = _t;
49
+
27
50
  function replaceWithMultiple(nodes) {
28
51
  var _pathCache$get;
29
52
 
30
53
  this.resync();
31
54
  nodes = this._verifyNodeList(nodes);
32
- t.inheritLeadingComments(nodes[0], this.node);
33
- t.inheritTrailingComments(nodes[nodes.length - 1], this.node);
55
+ inheritLeadingComments(nodes[0], this.node);
56
+ inheritTrailingComments(nodes[nodes.length - 1], this.node);
34
57
  (_pathCache$get = _cache.path.get(this.parent)) == null ? void 0 : _pathCache$get.delete(this.node);
35
58
  this.node = this.container[this.key] = null;
36
59
  const paths = this.insertAfter(nodes);
@@ -92,7 +115,7 @@ function replaceWith(replacement) {
92
115
  return [this];
93
116
  }
94
117
 
95
- if (this.isProgram() && !t.isProgram(replacement)) {
118
+ if (this.isProgram() && !isProgram(replacement)) {
96
119
  throw new Error("You can only replace a Program root node with another Program node");
97
120
  }
98
121
 
@@ -106,14 +129,14 @@ function replaceWith(replacement) {
106
129
 
107
130
  let nodePath = "";
108
131
 
109
- if (this.isNodeType("Statement") && t.isExpression(replacement)) {
132
+ if (this.isNodeType("Statement") && isExpression(replacement)) {
110
133
  if (!this.canHaveVariableDeclarationOrExpression() && !this.canSwapBetweenExpressionAndStatement(replacement) && !this.parentPath.isExportDefaultDeclaration()) {
111
- replacement = t.expressionStatement(replacement);
134
+ replacement = expressionStatement(replacement);
112
135
  nodePath = "expression";
113
136
  }
114
137
  }
115
138
 
116
- if (this.isNodeType("Expression") && t.isStatement(replacement)) {
139
+ if (this.isNodeType("Expression") && isStatement(replacement)) {
117
140
  if (!this.canHaveVariableDeclarationOrExpression() && !this.canSwapBetweenExpressionAndStatement(replacement)) {
118
141
  return this.replaceExpressionWithStatements([replacement]);
119
142
  }
@@ -122,8 +145,8 @@ function replaceWith(replacement) {
122
145
  const oldNode = this.node;
123
146
 
124
147
  if (oldNode) {
125
- t.inheritsComments(replacement, oldNode);
126
- t.removeComments(oldNode);
148
+ inheritsComments(replacement, oldNode);
149
+ removeComments(oldNode);
127
150
  }
128
151
 
129
152
  this._replaceWith(replacement);
@@ -142,9 +165,9 @@ function _replaceWith(node) {
142
165
  }
143
166
 
144
167
  if (this.inList) {
145
- t.validate(this.parent, this.key, [node]);
168
+ validate(this.parent, this.key, [node]);
146
169
  } else {
147
- t.validate(this.parent, this.key, node);
170
+ validate(this.parent, this.key, node);
148
171
  }
149
172
 
150
173
  this.debug(`Replace with ${node == null ? void 0 : node.type}`);
@@ -154,17 +177,17 @@ function _replaceWith(node) {
154
177
 
155
178
  function replaceExpressionWithStatements(nodes) {
156
179
  this.resync();
157
- const toSequenceExpression = t.toSequenceExpression(nodes, this.scope);
180
+ const nodesAsSequenceExpression = toSequenceExpression(nodes, this.scope);
158
181
 
159
- if (toSequenceExpression) {
160
- return this.replaceWith(toSequenceExpression)[0].get("expressions");
182
+ if (nodesAsSequenceExpression) {
183
+ return this.replaceWith(nodesAsSequenceExpression)[0].get("expressions");
161
184
  }
162
185
 
163
186
  const functionParent = this.getFunctionParent();
164
187
  const isParentAsync = functionParent == null ? void 0 : functionParent.is("async");
165
188
  const isParentGenerator = functionParent == null ? void 0 : functionParent.is("generator");
166
- const container = t.arrowFunctionExpression([], t.blockStatement(nodes));
167
- this.replaceWith(t.callExpression(container, []));
189
+ const container = arrowFunctionExpression([], blockStatement(nodes));
190
+ this.replaceWith(callExpression(container, []));
168
191
  const callee = this.get("callee");
169
192
  (0, _helperHoistVariables.default)(callee.get("body"), id => {
170
193
  this.scope.push({
@@ -182,36 +205,36 @@ function replaceExpressionWithStatements(nodes) {
182
205
 
183
206
  if (!uid) {
184
207
  uid = callee.scope.generateDeclaredUidIdentifier("ret");
185
- callee.get("body").pushContainer("body", t.returnStatement(t.cloneNode(uid)));
208
+ callee.get("body").pushContainer("body", returnStatement(cloneNode(uid)));
186
209
  loop.setData("expressionReplacementReturnUid", uid);
187
210
  } else {
188
- uid = t.identifier(uid.name);
211
+ uid = identifier(uid.name);
189
212
  }
190
213
 
191
- path.get("expression").replaceWith(t.assignmentExpression("=", t.cloneNode(uid), path.node.expression));
214
+ path.get("expression").replaceWith(assignmentExpression("=", cloneNode(uid), path.node.expression));
192
215
  } else {
193
- path.replaceWith(t.returnStatement(path.node.expression));
216
+ path.replaceWith(returnStatement(path.node.expression));
194
217
  }
195
218
  }
196
219
 
197
220
  callee.arrowFunctionToExpression();
198
221
  const newCallee = callee;
199
222
 
200
- const needToAwaitFunction = isParentAsync && _index.default.hasType(this.get("callee.body").node, "AwaitExpression", t.FUNCTION_TYPES);
223
+ const needToAwaitFunction = isParentAsync && _index.default.hasType(this.get("callee.body").node, "AwaitExpression", FUNCTION_TYPES);
201
224
 
202
- const needToYieldFunction = isParentGenerator && _index.default.hasType(this.get("callee.body").node, "YieldExpression", t.FUNCTION_TYPES);
225
+ const needToYieldFunction = isParentGenerator && _index.default.hasType(this.get("callee.body").node, "YieldExpression", FUNCTION_TYPES);
203
226
 
204
227
  if (needToAwaitFunction) {
205
228
  newCallee.set("async", true);
206
229
 
207
230
  if (!needToYieldFunction) {
208
- this.replaceWith(t.awaitExpression(this.node));
231
+ this.replaceWith(awaitExpression(this.node));
209
232
  }
210
233
  }
211
234
 
212
235
  if (needToYieldFunction) {
213
236
  newCallee.set("generator", true);
214
- this.replaceWith(t.yieldExpression(this.node, true));
237
+ this.replaceWith(yieldExpression(this.node, true));
215
238
  }
216
239
 
217
240
  return newCallee.get("body.body");
@@ -13,24 +13,63 @@ var _binding = require("./binding");
13
13
 
14
14
  var _globals = require("globals");
15
15
 
16
- var t = require("@babel/types");
16
+ var _t = require("@babel/types");
17
17
 
18
18
  var _cache = require("../cache");
19
19
 
20
+ const {
21
+ NOT_LOCAL_BINDING,
22
+ callExpression,
23
+ cloneNode,
24
+ getBindingIdentifiers,
25
+ identifier,
26
+ isArrayExpression,
27
+ isBinary,
28
+ isClass,
29
+ isClassBody,
30
+ isClassDeclaration,
31
+ isExportAllDeclaration,
32
+ isExportDefaultDeclaration,
33
+ isExportNamedDeclaration,
34
+ isFunctionDeclaration,
35
+ isIdentifier,
36
+ isImportDeclaration,
37
+ isLiteral,
38
+ isMethod,
39
+ isModuleDeclaration,
40
+ isModuleSpecifier,
41
+ isObjectExpression,
42
+ isProperty,
43
+ isPureish,
44
+ isSuper,
45
+ isTaggedTemplateExpression,
46
+ isTemplateLiteral,
47
+ isThisExpression,
48
+ isUnaryExpression,
49
+ isVariableDeclaration,
50
+ matchesPattern,
51
+ memberExpression,
52
+ numericLiteral,
53
+ toIdentifier,
54
+ unaryExpression,
55
+ variableDeclaration,
56
+ variableDeclarator
57
+ } = _t;
58
+
20
59
  function gatherNodeParts(node, parts) {
21
60
  switch (node == null ? void 0 : node.type) {
22
61
  default:
23
- if (t.isModuleDeclaration(node)) {
24
- if ((t.isExportAllDeclaration(node) || t.isExportNamedDeclaration(node) || t.isImportDeclaration(node)) && node.source) {
62
+ if (isModuleDeclaration(node)) {
63
+ if ((isExportAllDeclaration(node) || isExportNamedDeclaration(node) || isImportDeclaration(node)) && node.source) {
25
64
  gatherNodeParts(node.source, parts);
26
- } else if ((t.isExportNamedDeclaration(node) || t.isImportDeclaration(node)) && node.specifiers && node.specifiers.length) {
65
+ } else if ((isExportNamedDeclaration(node) || isImportDeclaration(node)) && node.specifiers && node.specifiers.length) {
27
66
  for (const e of node.specifiers) gatherNodeParts(e, parts);
28
- } else if ((t.isExportDefaultDeclaration(node) || t.isExportNamedDeclaration(node)) && node.declaration) {
67
+ } else if ((isExportDefaultDeclaration(node) || isExportNamedDeclaration(node)) && node.declaration) {
29
68
  gatherNodeParts(node.declaration, parts);
30
69
  }
31
- } else if (t.isModuleSpecifier(node)) {
70
+ } else if (isModuleSpecifier(node)) {
32
71
  gatherNodeParts(node.local, parts);
33
- } else if (t.isLiteral(node)) {
72
+ } else if (isLiteral(node)) {
34
73
  parts.push(node.value);
35
74
  }
36
75
 
@@ -159,14 +198,15 @@ function gatherNodeParts(node, parts) {
159
198
  }
160
199
 
161
200
  const collectorVisitor = {
162
- For(path) {
163
- for (const key of t.FOR_INIT_KEYS) {
164
- const declar = path.get(key);
201
+ ForStatement(path) {
202
+ const declar = path.get("init");
165
203
 
166
- if (declar.isVar()) {
167
- const parentScope = path.scope.getFunctionParent() || path.scope.getProgramParent();
168
- parentScope.registerBinding("var", declar);
169
- }
204
+ if (declar.isVar()) {
205
+ const {
206
+ scope
207
+ } = path;
208
+ const parentScope = scope.getFunctionParent() || scope.getProgramParent();
209
+ parentScope.registerBinding("var", declar);
170
210
  }
171
211
  },
172
212
 
@@ -192,6 +232,12 @@ const collectorVisitor = {
192
232
 
193
233
  if (left.isPattern() || left.isIdentifier()) {
194
234
  state.constantViolations.push(path);
235
+ } else if (left.isVar()) {
236
+ const {
237
+ scope
238
+ } = path;
239
+ const parentScope = scope.getFunctionParent() || scope.getProgramParent();
240
+ parentScope.registerBinding("var", left);
195
241
  }
196
242
  },
197
243
 
@@ -201,19 +247,19 @@ const collectorVisitor = {
201
247
  node,
202
248
  scope
203
249
  } = path;
204
- if (t.isExportAllDeclaration(node)) return;
250
+ if (isExportAllDeclaration(node)) return;
205
251
  const declar = node.declaration;
206
252
 
207
- if (t.isClassDeclaration(declar) || t.isFunctionDeclaration(declar)) {
253
+ if (isClassDeclaration(declar) || isFunctionDeclaration(declar)) {
208
254
  const id = declar.id;
209
255
  if (!id) return;
210
256
  const binding = scope.getBinding(id.name);
211
- if (binding) binding.reference(path);
212
- } else if (t.isVariableDeclaration(declar)) {
257
+ binding == null ? void 0 : binding.reference(path);
258
+ } else if (isVariableDeclaration(declar)) {
213
259
  for (const decl of declar.declarations) {
214
- for (const name of Object.keys(t.getBindingIdentifiers(decl))) {
260
+ for (const name of Object.keys(getBindingIdentifiers(decl))) {
215
261
  const binding = scope.getBinding(name);
216
- if (binding) binding.reference(path);
262
+ binding == null ? void 0 : binding.reference(path);
217
263
  }
218
264
  }
219
265
  }
@@ -257,19 +303,19 @@ const collectorVisitor = {
257
303
  },
258
304
 
259
305
  Function(path) {
260
- if (path.isFunctionExpression() && path.has("id") && !path.get("id").node[t.NOT_LOCAL_BINDING]) {
261
- path.scope.registerBinding("local", path.get("id"), path);
262
- }
263
-
264
306
  const params = path.get("params");
265
307
 
266
308
  for (const param of params) {
267
309
  path.scope.registerBinding("param", param);
268
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
+ }
269
315
  },
270
316
 
271
317
  ClassExpression(path) {
272
- if (path.has("id") && !path.get("id").node[t.NOT_LOCAL_BINDING]) {
318
+ if (path.has("id") && !path.get("id").node[NOT_LOCAL_BINDING]) {
273
319
  path.scope.registerBinding("local", path);
274
320
  }
275
321
  }
@@ -342,15 +388,15 @@ class Scope {
342
388
  this.push({
343
389
  id
344
390
  });
345
- return t.cloneNode(id);
391
+ return cloneNode(id);
346
392
  }
347
393
 
348
394
  generateUidIdentifier(name) {
349
- return t.identifier(this.generateUid(name));
395
+ return identifier(this.generateUid(name));
350
396
  }
351
397
 
352
398
  generateUid(name = "temp") {
353
- name = t.toIdentifier(name).replace(/^_+/, "").replace(/[0-9]+$/g, "");
399
+ name = toIdentifier(name).replace(/^_+/, "").replace(/[0-9]+$/g, "");
354
400
  let uid;
355
401
  let i = 1;
356
402
 
@@ -380,15 +426,15 @@ class Scope {
380
426
  }
381
427
 
382
428
  generateUidIdentifierBasedOnNode(node, defaultName) {
383
- return t.identifier(this.generateUidBasedOnNode(node, defaultName));
429
+ return identifier(this.generateUidBasedOnNode(node, defaultName));
384
430
  }
385
431
 
386
432
  isStatic(node) {
387
- if (t.isThisExpression(node) || t.isSuper(node)) {
433
+ if (isThisExpression(node) || isSuper(node)) {
388
434
  return true;
389
435
  }
390
436
 
391
- if (t.isIdentifier(node)) {
437
+ if (isIdentifier(node)) {
392
438
  const binding = this.getBinding(node.name);
393
439
 
394
440
  if (binding) {
@@ -411,7 +457,7 @@ class Scope {
411
457
  this.push({
412
458
  id
413
459
  });
414
- return t.cloneNode(id);
460
+ return cloneNode(id);
415
461
  }
416
462
 
417
463
  return id;
@@ -467,7 +513,7 @@ class Scope {
467
513
  }
468
514
 
469
515
  toArray(node, i, arrayLikeIsIterable) {
470
- if (t.isIdentifier(node)) {
516
+ if (isIdentifier(node)) {
471
517
  const binding = this.getBinding(node.name);
472
518
 
473
519
  if (binding != null && binding.constant && binding.path.isGenericType("Array")) {
@@ -475,14 +521,14 @@ class Scope {
475
521
  }
476
522
  }
477
523
 
478
- if (t.isArrayExpression(node)) {
524
+ if (isArrayExpression(node)) {
479
525
  return node;
480
526
  }
481
527
 
482
- if (t.isIdentifier(node, {
528
+ if (isIdentifier(node, {
483
529
  name: "arguments"
484
530
  })) {
485
- return t.callExpression(t.memberExpression(t.memberExpression(t.memberExpression(t.identifier("Array"), t.identifier("prototype")), t.identifier("slice")), t.identifier("call")), [node]);
531
+ return callExpression(memberExpression(memberExpression(memberExpression(identifier("Array"), identifier("prototype")), identifier("slice")), identifier("call")), [node]);
486
532
  }
487
533
 
488
534
  let helperName;
@@ -491,7 +537,7 @@ class Scope {
491
537
  if (i === true) {
492
538
  helperName = "toConsumableArray";
493
539
  } else if (i) {
494
- args.push(t.numericLiteral(i));
540
+ args.push(numericLiteral(i));
495
541
  helperName = "slicedToArray";
496
542
  } else {
497
543
  helperName = "toArray";
@@ -502,7 +548,7 @@ class Scope {
502
548
  helperName = "maybeArrayLike";
503
549
  }
504
550
 
505
- return t.callExpression(this.hub.addHelper(helperName), args);
551
+ return callExpression(this.hub.addHelper(helperName), args);
506
552
  }
507
553
 
508
554
  hasLabel(name) {
@@ -548,7 +594,7 @@ class Scope {
548
594
  }
549
595
 
550
596
  buildUndefinedNode() {
551
- return t.unaryExpression("void", t.numericLiteral(0), true);
597
+ return unaryExpression("void", numericLiteral(0), true);
552
598
  }
553
599
 
554
600
  registerConstantViolation(path) {
@@ -630,56 +676,56 @@ class Scope {
630
676
  }
631
677
 
632
678
  isPure(node, constantsOnly) {
633
- if (t.isIdentifier(node)) {
679
+ if (isIdentifier(node)) {
634
680
  const binding = this.getBinding(node.name);
635
681
  if (!binding) return false;
636
682
  if (constantsOnly) return binding.constant;
637
683
  return true;
638
- } else if (t.isClass(node)) {
684
+ } else if (isClass(node)) {
639
685
  if (node.superClass && !this.isPure(node.superClass, constantsOnly)) {
640
686
  return false;
641
687
  }
642
688
 
643
689
  return this.isPure(node.body, constantsOnly);
644
- } else if (t.isClassBody(node)) {
690
+ } else if (isClassBody(node)) {
645
691
  for (const method of node.body) {
646
692
  if (!this.isPure(method, constantsOnly)) return false;
647
693
  }
648
694
 
649
695
  return true;
650
- } else if (t.isBinary(node)) {
696
+ } else if (isBinary(node)) {
651
697
  return this.isPure(node.left, constantsOnly) && this.isPure(node.right, constantsOnly);
652
- } else if (t.isArrayExpression(node)) {
698
+ } else if (isArrayExpression(node)) {
653
699
  for (const elem of node.elements) {
654
700
  if (!this.isPure(elem, constantsOnly)) return false;
655
701
  }
656
702
 
657
703
  return true;
658
- } else if (t.isObjectExpression(node)) {
704
+ } else if (isObjectExpression(node)) {
659
705
  for (const prop of node.properties) {
660
706
  if (!this.isPure(prop, constantsOnly)) return false;
661
707
  }
662
708
 
663
709
  return true;
664
- } else if (t.isMethod(node)) {
710
+ } else if (isMethod(node)) {
665
711
  if (node.computed && !this.isPure(node.key, constantsOnly)) return false;
666
712
  if (node.kind === "get" || node.kind === "set") return false;
667
713
  return true;
668
- } else if (t.isProperty(node)) {
714
+ } else if (isProperty(node)) {
669
715
  if (node.computed && !this.isPure(node.key, constantsOnly)) return false;
670
716
  return this.isPure(node.value, constantsOnly);
671
- } else if (t.isUnaryExpression(node)) {
717
+ } else if (isUnaryExpression(node)) {
672
718
  return this.isPure(node.argument, constantsOnly);
673
- } else if (t.isTaggedTemplateExpression(node)) {
674
- return t.matchesPattern(node.tag, "String.raw") && !this.hasBinding("String", true) && this.isPure(node.quasi, constantsOnly);
675
- } else if (t.isTemplateLiteral(node)) {
719
+ } else if (isTaggedTemplateExpression(node)) {
720
+ return matchesPattern(node.tag, "String.raw") && !this.hasBinding("String", true) && this.isPure(node.quasi, constantsOnly);
721
+ } else if (isTemplateLiteral(node)) {
676
722
  for (const expression of node.expressions) {
677
723
  if (!this.isPure(expression, constantsOnly)) return false;
678
724
  }
679
725
 
680
726
  return true;
681
727
  } else {
682
- return t.isPureish(node);
728
+ return isPureish(node);
683
729
  }
684
730
  }
685
731
 
@@ -794,13 +840,13 @@ class Scope {
794
840
  let declarPath = !unique && path.getData(dataKey);
795
841
 
796
842
  if (!declarPath) {
797
- const declar = t.variableDeclaration(kind, []);
843
+ const declar = variableDeclaration(kind, []);
798
844
  declar._blockHoist = blockHoist;
799
845
  [declarPath] = path.unshiftContainer("body", [declar]);
800
846
  if (!unique) path.setData(dataKey, declarPath);
801
847
  }
802
848
 
803
- const declarator = t.variableDeclarator(opts.id, opts.init);
849
+ const declarator = variableDeclarator(opts.id, opts.init);
804
850
  declarPath.node.declarations.push(declarator);
805
851
  this.registerBinding(kind, declarPath.get("declarations").pop());
806
852
  }
@@ -891,7 +937,7 @@ class Scope {
891
937
  if (binding) {
892
938
  var _previousPath;
893
939
 
894
- if ((_previousPath = previousPath) != null && _previousPath.isPattern() && binding.kind !== "param") {} else {
940
+ if ((_previousPath = previousPath) != null && _previousPath.isPattern() && binding.kind !== "param" && binding.kind !== "local") {} else {
895
941
  return binding;
896
942
  }
897
943
  }
@@ -9,8 +9,16 @@ var _binding = require("../binding");
9
9
 
10
10
  var _helperSplitExportDeclaration = require("@babel/helper-split-export-declaration");
11
11
 
12
- var t = require("@babel/types");
13
-
12
+ var _t = require("@babel/types");
13
+
14
+ const {
15
+ VISITOR_KEYS,
16
+ assignmentExpression,
17
+ identifier,
18
+ toExpression,
19
+ variableDeclaration,
20
+ variableDeclarator
21
+ } = _t;
14
22
  const renameVisitor = {
15
23
  ReferencedIdentifier({
16
24
  node
@@ -62,20 +70,20 @@ class Renamer {
62
70
  return;
63
71
  if (!path.isFunctionDeclaration() && !path.isClassDeclaration()) return;
64
72
  if (this.binding.kind !== "hoisted") return;
65
- path.node.id = t.identifier(this.oldName);
73
+ path.node.id = identifier(this.oldName);
66
74
  path.node._blockHoist = 3;
67
- path.replaceWith(t.variableDeclaration("let", [t.variableDeclarator(t.identifier(this.newName), t.toExpression(path.node))]));
75
+ path.replaceWith(variableDeclaration("let", [variableDeclarator(identifier(this.newName), toExpression(path.node))]));
68
76
  }
69
77
 
70
78
  maybeConvertFromClassFunctionExpression(path) {
71
79
  return;
72
80
  if (!path.isFunctionExpression() && !path.isClassExpression()) return;
73
81
  if (this.binding.kind !== "local") return;
74
- path.node.id = t.identifier(this.oldName);
82
+ path.node.id = identifier(this.oldName);
75
83
  this.binding.scope.parent.push({
76
- id: t.identifier(this.newName)
84
+ id: identifier(this.newName)
77
85
  });
78
- path.replaceWith(t.assignmentExpression("=", t.identifier(this.newName), path.node));
86
+ path.replaceWith(assignmentExpression("=", identifier(this.newName), path.node));
79
87
  }
80
88
 
81
89
  rename(block) {
@@ -130,7 +138,7 @@ function skipAllButComputedMethodKey(path) {
130
138
  return;
131
139
  }
132
140
 
133
- const keys = t.VISITOR_KEYS[path.type];
141
+ const keys = VISITOR_KEYS[path.type];
134
142
 
135
143
  for (const key of keys) {
136
144
  if (key !== "key") path.skipKey(key);