@babel/traverse 7.0.0-beta.45 → 7.0.0-beta.49

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.

@@ -6,9 +6,9 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
 
8
8
  function _includes() {
9
- var data = _interopRequireDefault(require("lodash/includes"));
9
+ const data = _interopRequireDefault(require("lodash/includes"));
10
10
 
11
- _includes = function _includes() {
11
+ _includes = function () {
12
12
  return data;
13
13
  };
14
14
 
@@ -16,9 +16,9 @@ function _includes() {
16
16
  }
17
17
 
18
18
  function _repeat() {
19
- var data = _interopRequireDefault(require("lodash/repeat"));
19
+ const data = _interopRequireDefault(require("lodash/repeat"));
20
20
 
21
- _repeat = function _repeat() {
21
+ _repeat = function () {
22
22
  return data;
23
23
  };
24
24
 
@@ -30,21 +30,21 @@ var _renamer = _interopRequireDefault(require("./lib/renamer"));
30
30
  var _index = _interopRequireDefault(require("../index"));
31
31
 
32
32
  function _defaults() {
33
- var data = _interopRequireDefault(require("lodash/defaults"));
33
+ const data = _interopRequireDefault(require("lodash/defaults"));
34
34
 
35
- _defaults = function _defaults() {
35
+ _defaults = function () {
36
36
  return data;
37
37
  };
38
38
 
39
39
  return data;
40
40
  }
41
41
 
42
- var _binding2 = _interopRequireDefault(require("./binding"));
42
+ var _binding = _interopRequireDefault(require("./binding"));
43
43
 
44
44
  function _globals() {
45
- var data = _interopRequireDefault(require("globals"));
45
+ const data = _interopRequireDefault(require("globals"));
46
46
 
47
- _globals = function _globals() {
47
+ _globals = function () {
48
48
  return data;
49
49
  };
50
50
 
@@ -52,9 +52,9 @@ function _globals() {
52
52
  }
53
53
 
54
54
  function t() {
55
- var data = _interopRequireWildcard(require("@babel/types"));
55
+ const data = _interopRequireWildcard(require("@babel/types"));
56
56
 
57
- t = function t() {
57
+ t = function () {
58
58
  return data;
59
59
  };
60
60
 
@@ -67,19 +67,12 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
67
67
 
68
68
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
69
69
 
70
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
71
-
72
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
73
-
74
70
  function gatherNodeParts(node, parts) {
75
71
  if (t().isModuleDeclaration(node)) {
76
72
  if (node.source) {
77
73
  gatherNodeParts(node.source, parts);
78
74
  } else if (node.specifiers && node.specifiers.length) {
79
- var _arr = node.specifiers;
80
-
81
- for (var _i = 0; _i < _arr.length; _i++) {
82
- var specifier = _arr[_i];
75
+ for (const specifier of node.specifiers) {
83
76
  gatherNodeParts(specifier, parts);
84
77
  }
85
78
  } else if (node.declaration) {
@@ -97,10 +90,7 @@ function gatherNodeParts(node, parts) {
97
90
  } else if (t().isCallExpression(node)) {
98
91
  gatherNodeParts(node.callee, parts);
99
92
  } else if (t().isObjectExpression(node) || t().isObjectPattern(node)) {
100
- var _arr2 = node.properties;
101
-
102
- for (var _i2 = 0; _i2 < _arr2.length; _i2++) {
103
- var prop = _arr2[_i2];
93
+ for (const prop of node.properties) {
104
94
  gatherNodeParts(prop.key || prop.argument, parts);
105
95
  }
106
96
  } else if (t().isPrivateName(node)) {
@@ -112,113 +102,120 @@ function gatherNodeParts(node, parts) {
112
102
  }
113
103
  }
114
104
 
115
- var collectorVisitor = {
116
- For: function For(path) {
117
- var _arr3 = t().FOR_INIT_KEYS;
118
-
119
- for (var _i3 = 0; _i3 < _arr3.length; _i3++) {
120
- var key = _arr3[_i3];
121
- var declar = path.get(key);
105
+ const collectorVisitor = {
106
+ For(path) {
107
+ for (const key of t().FOR_INIT_KEYS) {
108
+ const declar = path.get(key);
122
109
 
123
110
  if (declar.isVar()) {
124
- var parentScope = path.scope.getFunctionParent() || path.scope.getProgramParent();
111
+ const parentScope = path.scope.getFunctionParent() || path.scope.getProgramParent();
125
112
  parentScope.registerBinding("var", declar);
126
113
  }
127
114
  }
128
115
  },
129
- Declaration: function Declaration(path) {
116
+
117
+ Declaration(path) {
130
118
  if (path.isBlockScoped()) return;
131
119
 
132
120
  if (path.isExportDeclaration() && path.get("declaration").isDeclaration()) {
133
121
  return;
134
122
  }
135
123
 
136
- var parent = path.scope.getFunctionParent() || path.scope.getProgramParent();
124
+ const parent = path.scope.getFunctionParent() || path.scope.getProgramParent();
137
125
  parent.registerDeclaration(path);
138
126
  },
139
- ReferencedIdentifier: function ReferencedIdentifier(path, state) {
127
+
128
+ ReferencedIdentifier(path, state) {
140
129
  state.references.push(path);
141
130
  },
142
- ForXStatement: function ForXStatement(path, state) {
143
- var left = path.get("left");
131
+
132
+ ForXStatement(path, state) {
133
+ const left = path.get("left");
144
134
 
145
135
  if (left.isPattern() || left.isIdentifier()) {
146
136
  state.constantViolations.push(path);
147
137
  }
148
138
  },
139
+
149
140
  ExportDeclaration: {
150
- exit: function exit(path) {
151
- var node = path.node,
152
- scope = path.scope;
153
- var declar = node.declaration;
141
+ exit(path) {
142
+ const {
143
+ node,
144
+ scope
145
+ } = path;
146
+ const declar = node.declaration;
154
147
 
155
148
  if (t().isClassDeclaration(declar) || t().isFunctionDeclaration(declar)) {
156
- var _id = declar.id;
157
- if (!_id) return;
158
- var binding = scope.getBinding(_id.name);
149
+ const id = declar.id;
150
+ if (!id) return;
151
+ const binding = scope.getBinding(id.name);
159
152
  if (binding) binding.reference(path);
160
153
  } else if (t().isVariableDeclaration(declar)) {
161
- var _arr4 = declar.declarations;
162
-
163
- for (var _i4 = 0; _i4 < _arr4.length; _i4++) {
164
- var decl = _arr4[_i4];
165
- var ids = t().getBindingIdentifiers(decl);
166
-
167
- for (var name in ids) {
168
- var _binding = scope.getBinding(name);
154
+ for (const decl of declar.declarations) {
155
+ const ids = t().getBindingIdentifiers(decl);
169
156
 
170
- if (_binding) _binding.reference(path);
157
+ for (const name in ids) {
158
+ const binding = scope.getBinding(name);
159
+ if (binding) binding.reference(path);
171
160
  }
172
161
  }
173
162
  }
174
163
  }
164
+
175
165
  },
176
- LabeledStatement: function LabeledStatement(path) {
166
+
167
+ LabeledStatement(path) {
177
168
  path.scope.getProgramParent().addGlobal(path.node);
178
169
  path.scope.getBlockParent().registerDeclaration(path);
179
170
  },
180
- AssignmentExpression: function AssignmentExpression(path, state) {
171
+
172
+ AssignmentExpression(path, state) {
181
173
  state.assignments.push(path);
182
174
  },
183
- UpdateExpression: function UpdateExpression(path, state) {
175
+
176
+ UpdateExpression(path, state) {
184
177
  state.constantViolations.push(path);
185
178
  },
186
- UnaryExpression: function UnaryExpression(path, state) {
179
+
180
+ UnaryExpression(path, state) {
187
181
  if (path.node.operator === "delete") {
188
182
  state.constantViolations.push(path);
189
183
  }
190
184
  },
191
- BlockScoped: function BlockScoped(path) {
192
- var scope = path.scope;
185
+
186
+ BlockScoped(path) {
187
+ let scope = path.scope;
193
188
  if (scope.path === path) scope = scope.parent;
194
189
  scope.getBlockParent().registerDeclaration(path);
195
190
  },
196
- ClassDeclaration: function ClassDeclaration(path) {
197
- var id = path.node.id;
191
+
192
+ ClassDeclaration(path) {
193
+ const id = path.node.id;
198
194
  if (!id) return;
199
- var name = id.name;
195
+ const name = id.name;
200
196
  path.scope.bindings[name] = path.scope.getBinding(name);
201
197
  },
202
- Block: function Block(path) {
203
- var paths = path.get("body");
204
- var _arr5 = paths;
205
198
 
206
- for (var _i5 = 0; _i5 < _arr5.length; _i5++) {
207
- var bodyPath = _arr5[_i5];
199
+ Block(path) {
200
+ const paths = path.get("body");
208
201
 
202
+ for (const bodyPath of paths) {
209
203
  if (bodyPath.isFunctionDeclaration()) {
210
204
  path.scope.getBlockParent().registerDeclaration(bodyPath);
211
205
  }
212
206
  }
213
207
  }
208
+
214
209
  };
215
- var uid = 0;
210
+ let uid = 0;
216
211
 
217
- var Scope = function () {
218
- function Scope(path) {
219
- var node = path.node;
212
+ class Scope {
213
+ constructor(path) {
214
+ const {
215
+ node
216
+ } = path;
220
217
 
221
- var cached = _cache.scope.get(node);
218
+ const cached = _cache.scope.get(node);
222
219
 
223
220
  if (cached && cached.path === path) {
224
221
  return cached;
@@ -232,52 +229,59 @@ var Scope = function () {
232
229
  this.labels = new Map();
233
230
  }
234
231
 
235
- var _proto = Scope.prototype;
232
+ get parent() {
233
+ const parent = this.path.findParent(p => p.isScope());
234
+ return parent && parent.scope;
235
+ }
236
236
 
237
- _proto.traverse = function traverse(node, opts, state) {
237
+ get parentBlock() {
238
+ return this.path.parent;
239
+ }
240
+
241
+ get hub() {
242
+ return this.path.hub;
243
+ }
244
+
245
+ traverse(node, opts, state) {
238
246
  (0, _index.default)(node, opts, this, state, this.path);
239
- };
247
+ }
240
248
 
241
- _proto.generateDeclaredUidIdentifier = function generateDeclaredUidIdentifier(name) {
242
- var id = this.generateUidIdentifier(name);
249
+ generateDeclaredUidIdentifier(name) {
250
+ const id = this.generateUidIdentifier(name);
243
251
  this.push({
244
- id: id
252
+ id
245
253
  });
246
254
  return t().cloneNode(id);
247
- };
255
+ }
248
256
 
249
- _proto.generateUidIdentifier = function generateUidIdentifier(name) {
257
+ generateUidIdentifier(name) {
250
258
  return t().identifier(this.generateUid(name));
251
- };
252
-
253
- _proto.generateUid = function generateUid(name) {
254
- if (name === void 0) {
255
- name = "temp";
256
- }
259
+ }
257
260
 
261
+ generateUid(name = "temp") {
258
262
  name = t().toIdentifier(name).replace(/^_+/, "").replace(/[0-9]+$/g, "");
259
- var uid;
260
- var i = 0;
263
+ let uid;
264
+ let i = 0;
261
265
 
262
266
  do {
263
267
  uid = this._generateUid(name, i);
264
268
  i++;
265
269
  } while (this.hasLabel(uid) || this.hasBinding(uid) || this.hasGlobal(uid) || this.hasReference(uid));
266
270
 
267
- var program = this.getProgramParent();
271
+ const program = this.getProgramParent();
268
272
  program.references[uid] = true;
269
273
  program.uids[uid] = true;
270
274
  return uid;
271
- };
275
+ }
272
276
 
273
- _proto._generateUid = function _generateUid(name, i) {
274
- var id = name;
277
+ _generateUid(name, i) {
278
+ let id = name;
275
279
  if (i > 1) id += i;
276
- return "_" + id;
277
- };
280
+ return `_${id}`;
281
+ }
278
282
 
279
- _proto.generateUidBasedOnNode = function generateUidBasedOnNode(parent, defaultName) {
280
- var node = parent;
283
+ generateUidBasedOnNode(parent, defaultName) {
284
+ let node = parent;
281
285
 
282
286
  if (t().isAssignmentExpression(parent)) {
283
287
  node = parent.left;
@@ -287,24 +291,24 @@ var Scope = function () {
287
291
  node = node.key;
288
292
  }
289
293
 
290
- var parts = [];
294
+ const parts = [];
291
295
  gatherNodeParts(node, parts);
292
- var id = parts.join("$");
296
+ let id = parts.join("$");
293
297
  id = id.replace(/^_/, "") || defaultName || "ref";
294
298
  return this.generateUid(id.slice(0, 20));
295
- };
299
+ }
296
300
 
297
- _proto.generateUidIdentifierBasedOnNode = function generateUidIdentifierBasedOnNode(parent, defaultName) {
301
+ generateUidIdentifierBasedOnNode(parent, defaultName) {
298
302
  return t().identifier(this.generateUidBasedOnNode(parent, defaultName));
299
- };
303
+ }
300
304
 
301
- _proto.isStatic = function isStatic(node) {
305
+ isStatic(node) {
302
306
  if (t().isThisExpression(node) || t().isSuper(node)) {
303
307
  return true;
304
308
  }
305
309
 
306
310
  if (t().isIdentifier(node)) {
307
- var binding = this.getBinding(node.name);
311
+ const binding = this.getBinding(node.name);
308
312
 
309
313
  if (binding) {
310
314
  return binding.constant;
@@ -314,62 +318,62 @@ var Scope = function () {
314
318
  }
315
319
 
316
320
  return false;
317
- };
321
+ }
318
322
 
319
- _proto.maybeGenerateMemoised = function maybeGenerateMemoised(node, dontPush) {
323
+ maybeGenerateMemoised(node, dontPush) {
320
324
  if (this.isStatic(node)) {
321
325
  return null;
322
326
  } else {
323
- var _id2 = this.generateUidIdentifierBasedOnNode(node);
327
+ const id = this.generateUidIdentifierBasedOnNode(node);
324
328
 
325
329
  if (!dontPush) {
326
330
  this.push({
327
- id: _id2
331
+ id
328
332
  });
329
- return t().cloneNode(_id2);
333
+ return t().cloneNode(id);
330
334
  }
331
335
 
332
- return _id2;
336
+ return id;
333
337
  }
334
- };
338
+ }
335
339
 
336
- _proto.checkBlockScopedCollisions = function checkBlockScopedCollisions(local, kind, name, id) {
340
+ checkBlockScopedCollisions(local, kind, name, id) {
337
341
  if (kind === "param") return;
338
342
  if (local.kind === "local") return;
339
343
  if (kind === "hoisted" && local.kind === "let") return;
340
- var duplicate = kind === "let" || local.kind === "let" || local.kind === "const" || local.kind === "module" || local.kind === "param" && (kind === "let" || kind === "const");
344
+ const duplicate = kind === "let" || local.kind === "let" || local.kind === "const" || local.kind === "module" || local.kind === "param" && (kind === "let" || kind === "const");
341
345
 
342
346
  if (duplicate) {
343
- throw this.hub.file.buildCodeFrameError(id, "Duplicate declaration \"" + name + "\"", TypeError);
347
+ throw this.hub.file.buildCodeFrameError(id, `Duplicate declaration "${name}"`, TypeError);
344
348
  }
345
- };
349
+ }
346
350
 
347
- _proto.rename = function rename(oldName, newName, block) {
348
- var binding = this.getBinding(oldName);
351
+ rename(oldName, newName, block) {
352
+ const binding = this.getBinding(oldName);
349
353
 
350
354
  if (binding) {
351
355
  newName = newName || this.generateUidIdentifier(oldName).name;
352
356
  return new _renamer.default(binding, oldName, newName).rename(block);
353
357
  }
354
- };
358
+ }
355
359
 
356
- _proto._renameFromMap = function _renameFromMap(map, oldName, newName, value) {
360
+ _renameFromMap(map, oldName, newName, value) {
357
361
  if (map[oldName]) {
358
362
  map[newName] = value;
359
363
  map[oldName] = null;
360
364
  }
361
- };
365
+ }
362
366
 
363
- _proto.dump = function dump() {
364
- var sep = (0, _repeat().default)("-", 60);
367
+ dump() {
368
+ const sep = (0, _repeat().default)("-", 60);
365
369
  console.log(sep);
366
- var scope = this;
370
+ let scope = this;
367
371
 
368
372
  do {
369
373
  console.log("#", scope.block.type);
370
374
 
371
- for (var name in scope.bindings) {
372
- var binding = scope.bindings[name];
375
+ for (const name in scope.bindings) {
376
+ const binding = scope.bindings[name];
373
377
  console.log(" -", name, {
374
378
  constant: binding.constant,
375
379
  references: binding.references,
@@ -380,13 +384,13 @@ var Scope = function () {
380
384
  } while (scope = scope.parent);
381
385
 
382
386
  console.log(sep);
383
- };
387
+ }
384
388
 
385
- _proto.toArray = function toArray(node, i) {
386
- var file = this.hub.file;
389
+ toArray(node, i) {
390
+ const file = this.hub.file;
387
391
 
388
392
  if (t().isIdentifier(node)) {
389
- var binding = this.getBinding(node.name);
393
+ const binding = this.getBinding(node.name);
390
394
 
391
395
  if (binding && binding.constant && binding.path.isGenericType("Array")) {
392
396
  return node;
@@ -403,8 +407,8 @@ var Scope = function () {
403
407
  return t().callExpression(t().memberExpression(t().memberExpression(t().memberExpression(t().identifier("Array"), t().identifier("prototype")), t().identifier("slice")), t().identifier("call")), [node]);
404
408
  }
405
409
 
406
- var helperName;
407
- var args = [node];
410
+ let helperName;
411
+ const args = [node];
408
412
 
409
413
  if (i === true) {
410
414
  helperName = "toConsumableArray";
@@ -416,115 +420,90 @@ var Scope = function () {
416
420
  }
417
421
 
418
422
  return t().callExpression(file.addHelper(helperName), args);
419
- };
423
+ }
420
424
 
421
- _proto.hasLabel = function hasLabel(name) {
425
+ hasLabel(name) {
422
426
  return !!this.getLabel(name);
423
- };
427
+ }
424
428
 
425
- _proto.getLabel = function getLabel(name) {
429
+ getLabel(name) {
426
430
  return this.labels.get(name);
427
- };
431
+ }
428
432
 
429
- _proto.registerLabel = function registerLabel(path) {
433
+ registerLabel(path) {
430
434
  this.labels.set(path.node.label.name, path);
431
- };
432
-
433
- _proto.registerDeclaration = function registerDeclaration(path) {
434
- if (path.isFlow()) return;
435
+ }
435
436
 
437
+ registerDeclaration(path) {
436
438
  if (path.isLabeledStatement()) {
437
439
  this.registerLabel(path);
438
440
  } else if (path.isFunctionDeclaration()) {
439
441
  this.registerBinding("hoisted", path.get("id"), path);
440
442
  } else if (path.isVariableDeclaration()) {
441
- var declarations = path.get("declarations");
442
- var _arr6 = declarations;
443
+ const declarations = path.get("declarations");
443
444
 
444
- for (var _i6 = 0; _i6 < _arr6.length; _i6++) {
445
- var declar = _arr6[_i6];
445
+ for (const declar of declarations) {
446
446
  this.registerBinding(path.node.kind, declar);
447
447
  }
448
448
  } else if (path.isClassDeclaration()) {
449
449
  this.registerBinding("let", path);
450
450
  } else if (path.isImportDeclaration()) {
451
- var specifiers = path.get("specifiers");
452
- var _arr7 = specifiers;
451
+ const specifiers = path.get("specifiers");
453
452
 
454
- for (var _i7 = 0; _i7 < _arr7.length; _i7++) {
455
- var specifier = _arr7[_i7];
453
+ for (const specifier of specifiers) {
456
454
  this.registerBinding("module", specifier);
457
455
  }
458
456
  } else if (path.isExportDeclaration()) {
459
- var _declar = path.get("declaration");
457
+ const declar = path.get("declaration");
460
458
 
461
- if (_declar.isClassDeclaration() || _declar.isFunctionDeclaration() || _declar.isVariableDeclaration()) {
462
- this.registerDeclaration(_declar);
459
+ if (declar.isClassDeclaration() || declar.isFunctionDeclaration() || declar.isVariableDeclaration()) {
460
+ this.registerDeclaration(declar);
463
461
  }
464
462
  } else {
465
463
  this.registerBinding("unknown", path);
466
464
  }
467
- };
465
+ }
468
466
 
469
- _proto.buildUndefinedNode = function buildUndefinedNode() {
467
+ buildUndefinedNode() {
470
468
  if (this.hasBinding("undefined")) {
471
469
  return t().unaryExpression("void", t().numericLiteral(0), true);
472
470
  } else {
473
471
  return t().identifier("undefined");
474
472
  }
475
- };
473
+ }
476
474
 
477
- _proto.registerConstantViolation = function registerConstantViolation(path) {
478
- var ids = path.getBindingIdentifiers();
475
+ registerConstantViolation(path) {
476
+ const ids = path.getBindingIdentifiers();
479
477
 
480
- for (var name in ids) {
481
- var binding = this.getBinding(name);
478
+ for (const name in ids) {
479
+ const binding = this.getBinding(name);
482
480
  if (binding) binding.reassign(path);
483
481
  }
484
- };
485
-
486
- _proto.registerBinding = function registerBinding(kind, path, bindingPath) {
487
- if (bindingPath === void 0) {
488
- bindingPath = path;
489
- }
482
+ }
490
483
 
484
+ registerBinding(kind, path, bindingPath = path) {
491
485
  if (!kind) throw new ReferenceError("no `kind`");
492
486
 
493
487
  if (path.isVariableDeclaration()) {
494
- var declarators = path.get("declarations");
495
-
496
- for (var _iterator = declarators, _isArray = Array.isArray(_iterator), _i8 = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
497
- var _ref;
498
-
499
- if (_isArray) {
500
- if (_i8 >= _iterator.length) break;
501
- _ref = _iterator[_i8++];
502
- } else {
503
- _i8 = _iterator.next();
504
- if (_i8.done) break;
505
- _ref = _i8.value;
506
- }
488
+ const declarators = path.get("declarations");
507
489
 
508
- var declar = _ref;
490
+ for (const declar of declarators) {
509
491
  this.registerBinding(kind, declar);
510
492
  }
511
493
 
512
494
  return;
513
495
  }
514
496
 
515
- var parent = this.getProgramParent();
516
- var ids = path.getBindingIdentifiers(true);
517
-
518
- for (var name in ids) {
519
- var _arr8 = ids[name];
497
+ const parent = this.getProgramParent();
498
+ const ids = path.getBindingIdentifiers(true);
520
499
 
521
- for (var _i9 = 0; _i9 < _arr8.length; _i9++) {
522
- var _id3 = _arr8[_i9];
523
- var local = this.getOwnBinding(name);
500
+ for (const name in ids) {
501
+ for (const id of ids[name]) {
502
+ const local = this.getOwnBinding(name);
524
503
 
525
504
  if (local) {
526
- if (local.identifier === _id3) continue;
527
- this.checkBlockScopedCollisions(local, kind, name, _id3);
505
+ if (local.identifier === id) continue;
506
+ this.checkBlockScopedCollisions(local, kind, name, id);
528
507
  }
529
508
 
530
509
  parent.references[name] = true;
@@ -532,8 +511,8 @@ var Scope = function () {
532
511
  if (local) {
533
512
  this.registerConstantViolation(bindingPath);
534
513
  } else {
535
- this.bindings[name] = new _binding2.default({
536
- identifier: _id3,
514
+ this.bindings[name] = new _binding.default({
515
+ identifier: id,
537
516
  scope: this,
538
517
  path: bindingPath,
539
518
  kind: kind
@@ -541,45 +520,45 @@ var Scope = function () {
541
520
  }
542
521
  }
543
522
  }
544
- };
523
+ }
545
524
 
546
- _proto.addGlobal = function addGlobal(node) {
525
+ addGlobal(node) {
547
526
  this.globals[node.name] = node;
548
- };
527
+ }
549
528
 
550
- _proto.hasUid = function hasUid(name) {
551
- var scope = this;
529
+ hasUid(name) {
530
+ let scope = this;
552
531
 
553
532
  do {
554
533
  if (scope.uids[name]) return true;
555
534
  } while (scope = scope.parent);
556
535
 
557
536
  return false;
558
- };
537
+ }
559
538
 
560
- _proto.hasGlobal = function hasGlobal(name) {
561
- var scope = this;
539
+ hasGlobal(name) {
540
+ let scope = this;
562
541
 
563
542
  do {
564
543
  if (scope.globals[name]) return true;
565
544
  } while (scope = scope.parent);
566
545
 
567
546
  return false;
568
- };
547
+ }
569
548
 
570
- _proto.hasReference = function hasReference(name) {
571
- var scope = this;
549
+ hasReference(name) {
550
+ let scope = this;
572
551
 
573
552
  do {
574
553
  if (scope.references[name]) return true;
575
554
  } while (scope = scope.parent);
576
555
 
577
556
  return false;
578
- };
557
+ }
579
558
 
580
- _proto.isPure = function isPure(node, constantsOnly) {
559
+ isPure(node, constantsOnly) {
581
560
  if (t().isIdentifier(node)) {
582
- var binding = this.getBinding(node.name);
561
+ const binding = this.getBinding(node.name);
583
562
  if (!binding) return false;
584
563
  if (constantsOnly) return binding.constant;
585
564
  return true;
@@ -590,19 +569,7 @@ var Scope = function () {
590
569
 
591
570
  return this.isPure(node.body, constantsOnly);
592
571
  } else if (t().isClassBody(node)) {
593
- for (var _iterator2 = node.body, _isArray2 = Array.isArray(_iterator2), _i10 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
594
- var _ref2;
595
-
596
- if (_isArray2) {
597
- if (_i10 >= _iterator2.length) break;
598
- _ref2 = _iterator2[_i10++];
599
- } else {
600
- _i10 = _iterator2.next();
601
- if (_i10.done) break;
602
- _ref2 = _i10.value;
603
- }
604
-
605
- var method = _ref2;
572
+ for (const method of node.body) {
606
573
  if (!this.isPure(method, constantsOnly)) return false;
607
574
  }
608
575
 
@@ -610,19 +577,13 @@ var Scope = function () {
610
577
  } else if (t().isBinary(node)) {
611
578
  return this.isPure(node.left, constantsOnly) && this.isPure(node.right, constantsOnly);
612
579
  } else if (t().isArrayExpression(node)) {
613
- var _arr9 = node.elements;
614
-
615
- for (var _i11 = 0; _i11 < _arr9.length; _i11++) {
616
- var elem = _arr9[_i11];
580
+ for (const elem of node.elements) {
617
581
  if (!this.isPure(elem, constantsOnly)) return false;
618
582
  }
619
583
 
620
584
  return true;
621
585
  } else if (t().isObjectExpression(node)) {
622
- var _arr10 = node.properties;
623
-
624
- for (var _i12 = 0; _i12 < _arr10.length; _i12++) {
625
- var prop = _arr10[_i12];
586
+ for (const prop of node.properties) {
626
587
  if (!this.isPure(prop, constantsOnly)) return false;
627
588
  }
628
589
 
@@ -639,10 +600,7 @@ var Scope = function () {
639
600
  } else if (t().isTaggedTemplateExpression(node)) {
640
601
  return t().matchesPattern(node.tag, "String.raw") && !this.hasBinding("String", true) && this.isPure(node.quasi, constantsOnly);
641
602
  } else if (t().isTemplateLiteral(node)) {
642
- var _arr11 = node.expressions;
643
-
644
- for (var _i13 = 0; _i13 < _arr11.length; _i13++) {
645
- var expression = _arr11[_i13];
603
+ for (const expression of node.expressions) {
646
604
  if (!this.isPure(expression, constantsOnly)) return false;
647
605
  }
648
606
 
@@ -650,36 +608,36 @@ var Scope = function () {
650
608
  } else {
651
609
  return t().isPureish(node);
652
610
  }
653
- };
611
+ }
654
612
 
655
- _proto.setData = function setData(key, val) {
613
+ setData(key, val) {
656
614
  return this.data[key] = val;
657
- };
615
+ }
658
616
 
659
- _proto.getData = function getData(key) {
660
- var scope = this;
617
+ getData(key) {
618
+ let scope = this;
661
619
 
662
620
  do {
663
- var data = scope.data[key];
621
+ const data = scope.data[key];
664
622
  if (data != null) return data;
665
623
  } while (scope = scope.parent);
666
- };
624
+ }
667
625
 
668
- _proto.removeData = function removeData(key) {
669
- var scope = this;
626
+ removeData(key) {
627
+ let scope = this;
670
628
 
671
629
  do {
672
- var data = scope.data[key];
630
+ const data = scope.data[key];
673
631
  if (data != null) scope.data[key] = null;
674
632
  } while (scope = scope.parent);
675
- };
633
+ }
676
634
 
677
- _proto.init = function init() {
635
+ init() {
678
636
  if (!this.references) this.crawl();
679
- };
637
+ }
680
638
 
681
- _proto.crawl = function crawl() {
682
- var path = this.path;
639
+ crawl() {
640
+ const path = this.path;
683
641
  this.references = Object.create(null);
684
642
  this.bindings = Object.create(null);
685
643
  this.globals = Object.create(null);
@@ -687,11 +645,8 @@ var Scope = function () {
687
645
  this.data = Object.create(null);
688
646
 
689
647
  if (path.isLoop()) {
690
- var _arr12 = t().FOR_INIT_KEYS;
691
-
692
- for (var _i14 = 0; _i14 < _arr12.length; _i14++) {
693
- var key = _arr12[_i14];
694
- var node = path.get(key);
648
+ for (const key of t().FOR_INIT_KEYS) {
649
+ const node = path.get(key);
695
650
  if (node.isBlockScoped()) this.registerBinding(node.node.kind, node);
696
651
  }
697
652
  }
@@ -709,21 +664,9 @@ var Scope = function () {
709
664
  }
710
665
 
711
666
  if (path.isFunction()) {
712
- var params = path.get("params");
713
-
714
- for (var _iterator3 = params, _isArray3 = Array.isArray(_iterator3), _i15 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
715
- var _ref3;
667
+ const params = path.get("params");
716
668
 
717
- if (_isArray3) {
718
- if (_i15 >= _iterator3.length) break;
719
- _ref3 = _iterator3[_i15++];
720
- } else {
721
- _i15 = _iterator3.next();
722
- if (_i15.done) break;
723
- _ref3 = _i15.value;
724
- }
725
-
726
- var param = _ref3;
669
+ for (const param of params) {
727
670
  this.registerBinding("param", param);
728
671
  }
729
672
  }
@@ -732,9 +675,9 @@ var Scope = function () {
732
675
  this.registerBinding("let", path);
733
676
  }
734
677
 
735
- var parent = this.getProgramParent();
678
+ const parent = this.getProgramParent();
736
679
  if (parent.crawling) return;
737
- var state = {
680
+ const state = {
738
681
  references: [],
739
682
  constantViolations: [],
740
683
  assignments: []
@@ -743,47 +686,21 @@ var Scope = function () {
743
686
  path.traverse(collectorVisitor, state);
744
687
  this.crawling = false;
745
688
 
746
- for (var _iterator4 = state.assignments, _isArray4 = Array.isArray(_iterator4), _i16 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) {
747
- var _ref4;
748
-
749
- if (_isArray4) {
750
- if (_i16 >= _iterator4.length) break;
751
- _ref4 = _iterator4[_i16++];
752
- } else {
753
- _i16 = _iterator4.next();
754
- if (_i16.done) break;
755
- _ref4 = _i16.value;
756
- }
757
-
758
- var _path = _ref4;
759
-
760
- var ids = _path.getBindingIdentifiers();
689
+ for (const path of state.assignments) {
690
+ const ids = path.getBindingIdentifiers();
691
+ let programParent;
761
692
 
762
- var programParent = void 0;
763
-
764
- for (var name in ids) {
765
- if (_path.scope.getBinding(name)) continue;
766
- programParent = programParent || _path.scope.getProgramParent();
693
+ for (const name in ids) {
694
+ if (path.scope.getBinding(name)) continue;
695
+ programParent = programParent || path.scope.getProgramParent();
767
696
  programParent.addGlobal(ids[name]);
768
697
  }
769
698
 
770
- _path.scope.registerConstantViolation(_path);
699
+ path.scope.registerConstantViolation(path);
771
700
  }
772
701
 
773
- for (var _iterator5 = state.references, _isArray5 = Array.isArray(_iterator5), _i17 = 0, _iterator5 = _isArray5 ? _iterator5 : _iterator5[Symbol.iterator]();;) {
774
- var _ref5;
775
-
776
- if (_isArray5) {
777
- if (_i17 >= _iterator5.length) break;
778
- _ref5 = _iterator5[_i17++];
779
- } else {
780
- _i17 = _iterator5.next();
781
- if (_i17.done) break;
782
- _ref5 = _i17.value;
783
- }
784
-
785
- var ref = _ref5;
786
- var binding = ref.scope.getBinding(ref.node.name);
702
+ for (const ref of state.references) {
703
+ const binding = ref.scope.getBinding(ref.node.name);
787
704
 
788
705
  if (binding) {
789
706
  binding.reference(ref);
@@ -792,26 +709,13 @@ var Scope = function () {
792
709
  }
793
710
  }
794
711
 
795
- for (var _iterator6 = state.constantViolations, _isArray6 = Array.isArray(_iterator6), _i18 = 0, _iterator6 = _isArray6 ? _iterator6 : _iterator6[Symbol.iterator]();;) {
796
- var _ref6;
797
-
798
- if (_isArray6) {
799
- if (_i18 >= _iterator6.length) break;
800
- _ref6 = _iterator6[_i18++];
801
- } else {
802
- _i18 = _iterator6.next();
803
- if (_i18.done) break;
804
- _ref6 = _i18.value;
805
- }
806
-
807
- var _path2 = _ref6;
808
-
809
- _path2.scope.registerConstantViolation(_path2);
712
+ for (const path of state.constantViolations) {
713
+ path.scope.registerConstantViolation(path);
810
714
  }
811
- };
715
+ }
812
716
 
813
- _proto.push = function push(opts) {
814
- var path = this.path;
717
+ push(opts) {
718
+ let path = this.path;
815
719
 
816
720
  if (!path.isBlockStatement() && !path.isProgram()) {
817
721
  path = this.getBlockParent().path;
@@ -826,29 +730,26 @@ var Scope = function () {
826
730
  path = path.get("body");
827
731
  }
828
732
 
829
- var unique = opts.unique;
830
- var kind = opts.kind || "var";
831
- var blockHoist = opts._blockHoist == null ? 2 : opts._blockHoist;
832
- var dataKey = "declaration:" + kind + ":" + blockHoist;
833
- var declarPath = !unique && path.getData(dataKey);
733
+ const unique = opts.unique;
734
+ const kind = opts.kind || "var";
735
+ const blockHoist = opts._blockHoist == null ? 2 : opts._blockHoist;
736
+ const dataKey = `declaration:${kind}:${blockHoist}`;
737
+ let declarPath = !unique && path.getData(dataKey);
834
738
 
835
739
  if (!declarPath) {
836
- var declar = t().variableDeclaration(kind, []);
740
+ const declar = t().variableDeclaration(kind, []);
837
741
  declar._blockHoist = blockHoist;
838
-
839
- var _path$unshiftContaine = path.unshiftContainer("body", [declar]);
840
-
841
- declarPath = _path$unshiftContaine[0];
742
+ [declarPath] = path.unshiftContainer("body", [declar]);
842
743
  if (!unique) path.setData(dataKey, declarPath);
843
744
  }
844
745
 
845
- var declarator = t().variableDeclarator(opts.id, opts.init);
746
+ const declarator = t().variableDeclarator(opts.id, opts.init);
846
747
  declarPath.node.declarations.push(declarator);
847
748
  this.registerBinding(kind, declarPath.get("declarations").pop());
848
- };
749
+ }
849
750
 
850
- _proto.getProgramParent = function getProgramParent() {
851
- var scope = this;
751
+ getProgramParent() {
752
+ let scope = this;
852
753
 
853
754
  do {
854
755
  if (scope.path.isProgram()) {
@@ -857,10 +758,10 @@ var Scope = function () {
857
758
  } while (scope = scope.parent);
858
759
 
859
760
  throw new Error("Couldn't find a Program");
860
- };
761
+ }
861
762
 
862
- _proto.getFunctionParent = function getFunctionParent() {
863
- var scope = this;
763
+ getFunctionParent() {
764
+ let scope = this;
864
765
 
865
766
  do {
866
767
  if (scope.path.isFunctionParent()) {
@@ -869,10 +770,10 @@ var Scope = function () {
869
770
  } while (scope = scope.parent);
870
771
 
871
772
  return null;
872
- };
773
+ }
873
774
 
874
- _proto.getBlockParent = function getBlockParent() {
875
- var scope = this;
775
+ getBlockParent() {
776
+ let scope = this;
876
777
 
877
778
  do {
878
779
  if (scope.path.isBlockParent()) {
@@ -881,11 +782,11 @@ var Scope = function () {
881
782
  } while (scope = scope.parent);
882
783
 
883
784
  throw new Error("We couldn't find a BlockStatement, For, Switch, Function, Loop or Program...");
884
- };
785
+ }
885
786
 
886
- _proto.getAllBindings = function getAllBindings() {
887
- var ids = Object.create(null);
888
- var scope = this;
787
+ getAllBindings() {
788
+ const ids = Object.create(null);
789
+ let scope = this;
889
790
 
890
791
  do {
891
792
  (0, _defaults().default)(ids, scope.bindings);
@@ -893,19 +794,17 @@ var Scope = function () {
893
794
  } while (scope);
894
795
 
895
796
  return ids;
896
- };
797
+ }
897
798
 
898
- _proto.getAllBindingsOfKind = function getAllBindingsOfKind() {
899
- var ids = Object.create(null);
900
- var _arr13 = arguments;
799
+ getAllBindingsOfKind() {
800
+ const ids = Object.create(null);
901
801
 
902
- for (var _i19 = 0; _i19 < _arr13.length; _i19++) {
903
- var kind = _arr13[_i19];
904
- var scope = this;
802
+ for (const kind of arguments) {
803
+ let scope = this;
905
804
 
906
805
  do {
907
- for (var name in scope.bindings) {
908
- var binding = scope.bindings[name];
806
+ for (const name in scope.bindings) {
807
+ const binding = scope.bindings[name];
909
808
  if (binding.kind === kind) ids[name] = binding;
910
809
  }
911
810
 
@@ -914,40 +813,40 @@ var Scope = function () {
914
813
  }
915
814
 
916
815
  return ids;
917
- };
816
+ }
918
817
 
919
- _proto.bindingIdentifierEquals = function bindingIdentifierEquals(name, node) {
818
+ bindingIdentifierEquals(name, node) {
920
819
  return this.getBindingIdentifier(name) === node;
921
- };
820
+ }
922
821
 
923
- _proto.getBinding = function getBinding(name) {
924
- var scope = this;
822
+ getBinding(name) {
823
+ let scope = this;
925
824
 
926
825
  do {
927
- var binding = scope.getOwnBinding(name);
826
+ const binding = scope.getOwnBinding(name);
928
827
  if (binding) return binding;
929
828
  } while (scope = scope.parent);
930
- };
829
+ }
931
830
 
932
- _proto.getOwnBinding = function getOwnBinding(name) {
831
+ getOwnBinding(name) {
933
832
  return this.bindings[name];
934
- };
833
+ }
935
834
 
936
- _proto.getBindingIdentifier = function getBindingIdentifier(name) {
937
- var info = this.getBinding(name);
835
+ getBindingIdentifier(name) {
836
+ const info = this.getBinding(name);
938
837
  return info && info.identifier;
939
- };
838
+ }
940
839
 
941
- _proto.getOwnBindingIdentifier = function getOwnBindingIdentifier(name) {
942
- var binding = this.bindings[name];
840
+ getOwnBindingIdentifier(name) {
841
+ const binding = this.bindings[name];
943
842
  return binding && binding.identifier;
944
- };
843
+ }
945
844
 
946
- _proto.hasOwnBinding = function hasOwnBinding(name) {
845
+ hasOwnBinding(name) {
947
846
  return !!this.getOwnBinding(name);
948
- };
847
+ }
949
848
 
950
- _proto.hasBinding = function hasBinding(name, noGlobals) {
849
+ hasBinding(name, noGlobals) {
951
850
  if (!name) return false;
952
851
  if (this.hasOwnBinding(name)) return true;
953
852
  if (this.parentHasBinding(name, noGlobals)) return true;
@@ -955,64 +854,43 @@ var Scope = function () {
955
854
  if (!noGlobals && (0, _includes().default)(Scope.globals, name)) return true;
956
855
  if (!noGlobals && (0, _includes().default)(Scope.contextVariables, name)) return true;
957
856
  return false;
958
- };
857
+ }
959
858
 
960
- _proto.parentHasBinding = function parentHasBinding(name, noGlobals) {
859
+ parentHasBinding(name, noGlobals) {
961
860
  return this.parent && this.parent.hasBinding(name, noGlobals);
962
- };
861
+ }
963
862
 
964
- _proto.moveBindingTo = function moveBindingTo(name, scope) {
965
- var info = this.getBinding(name);
863
+ moveBindingTo(name, scope) {
864
+ const info = this.getBinding(name);
966
865
 
967
866
  if (info) {
968
867
  info.scope.removeOwnBinding(name);
969
868
  info.scope = scope;
970
869
  scope.bindings[name] = info;
971
870
  }
972
- };
871
+ }
973
872
 
974
- _proto.removeOwnBinding = function removeOwnBinding(name) {
873
+ removeOwnBinding(name) {
975
874
  delete this.bindings[name];
976
- };
875
+ }
977
876
 
978
- _proto.removeBinding = function removeBinding(name) {
979
- var info = this.getBinding(name);
877
+ removeBinding(name) {
878
+ const info = this.getBinding(name);
980
879
 
981
880
  if (info) {
982
881
  info.scope.removeOwnBinding(name);
983
882
  }
984
883
 
985
- var scope = this;
884
+ let scope = this;
986
885
 
987
886
  do {
988
887
  if (scope.uids[name]) {
989
888
  scope.uids[name] = false;
990
889
  }
991
890
  } while (scope = scope.parent);
992
- };
993
-
994
- _createClass(Scope, [{
995
- key: "parent",
996
- get: function get() {
997
- var parent = this.path.findParent(function (p) {
998
- return p.isScope();
999
- });
1000
- return parent && parent.scope;
1001
- }
1002
- }, {
1003
- key: "parentBlock",
1004
- get: function get() {
1005
- return this.path.parent;
1006
- }
1007
- }, {
1008
- key: "hub",
1009
- get: function get() {
1010
- return this.path.hub;
1011
- }
1012
- }]);
891
+ }
1013
892
 
1014
- return Scope;
1015
- }();
893
+ }
1016
894
 
1017
895
  exports.default = Scope;
1018
896
  Scope.globals = Object.keys(_globals().default.builtin);