@babel/traverse 7.0.0-beta.46 → 7.0.0-beta.47

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