@babel/traverse 7.0.0-beta.43 → 7.0.0-beta.44

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.

@@ -5,11 +5,11 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.evaluateTruthy = evaluateTruthy;
7
7
  exports.evaluate = evaluate;
8
- const VALID_CALLEES = ["String", "Number", "Math"];
9
- const INVALID_METHODS = ["random"];
8
+ var VALID_CALLEES = ["String", "Number", "Math"];
9
+ var INVALID_METHODS = ["random"];
10
10
 
11
11
  function evaluateTruthy() {
12
- const res = this.evaluate();
12
+ var res = this.evaluate();
13
13
  if (res.confident) return !!res.value;
14
14
  }
15
15
 
@@ -20,15 +20,11 @@ function deopt(path, state) {
20
20
  }
21
21
 
22
22
  function evaluateCached(path, state) {
23
- const {
24
- node
25
- } = path;
26
- const {
27
- seen
28
- } = state;
23
+ var node = path.node;
24
+ var seen = state.seen;
29
25
 
30
26
  if (seen.has(node)) {
31
- const existing = seen.get(node);
27
+ var existing = seen.get(node);
32
28
 
33
29
  if (existing.resolved) {
34
30
  return existing.value;
@@ -37,12 +33,12 @@ function evaluateCached(path, state) {
37
33
  return;
38
34
  }
39
35
  } else {
40
- const item = {
36
+ var item = {
41
37
  resolved: false
42
38
  };
43
39
  seen.set(node, item);
44
40
 
45
- const val = _evaluate(path, state);
41
+ var val = _evaluate(path, state);
46
42
 
47
43
  if (state.confident) {
48
44
  item.resolved = true;
@@ -55,12 +51,10 @@ function evaluateCached(path, state) {
55
51
 
56
52
  function _evaluate(path, state) {
57
53
  if (!state.confident) return;
58
- const {
59
- node
60
- } = path;
54
+ var node = path.node;
61
55
 
62
56
  if (path.isSequenceExpression()) {
63
- const exprs = path.get("expressions");
57
+ var exprs = path.get("expressions");
64
58
  return evaluateCached(exprs[exprs.length - 1], state);
65
59
  }
66
60
 
@@ -77,13 +71,9 @@ function _evaluate(path, state) {
77
71
  }
78
72
 
79
73
  if (path.isTaggedTemplateExpression() && path.get("tag").isMemberExpression()) {
80
- const object = path.get("tag.object");
81
- const {
82
- node: {
83
- name
84
- }
85
- } = object;
86
- const property = path.get("tag.property");
74
+ var object = path.get("tag.object");
75
+ var name = object.node.name;
76
+ var property = path.get("tag.property");
87
77
 
88
78
  if (object.isIdentifier() && name === "String" && !path.scope.getBinding(name, true) && property.isIdentifier && property.node.name === "raw") {
89
79
  return evaluateQuasis(path, node.quasi.quasis, state, true);
@@ -91,7 +81,7 @@ function _evaluate(path, state) {
91
81
  }
92
82
 
93
83
  if (path.isConditionalExpression()) {
94
- const testResult = evaluateCached(path.get("test"), state);
84
+ var testResult = evaluateCached(path.get("test"), state);
95
85
  if (!state.confident) return;
96
86
 
97
87
  if (testResult) {
@@ -108,21 +98,22 @@ function _evaluate(path, state) {
108
98
  if (path.isMemberExpression() && !path.parentPath.isCallExpression({
109
99
  callee: node
110
100
  })) {
111
- const property = path.get("property");
112
- const object = path.get("object");
101
+ var _property = path.get("property");
102
+
103
+ var _object = path.get("object");
113
104
 
114
- if (object.isLiteral() && property.isIdentifier()) {
115
- const value = object.node.value;
116
- const type = typeof value;
105
+ if (_object.isLiteral() && _property.isIdentifier()) {
106
+ var value = _object.node.value;
107
+ var type = typeof value;
117
108
 
118
109
  if (type === "number" || type === "string") {
119
- return value[property.node.name];
110
+ return value[_property.node.name];
120
111
  }
121
112
  }
122
113
  }
123
114
 
124
115
  if (path.isReferencedIdentifier()) {
125
- const binding = path.scope.getBinding(node.name);
116
+ var binding = path.scope.getBinding(node.name);
126
117
 
127
118
  if (binding && binding.constantViolations.length > 0) {
128
119
  return deopt(binding.path, state);
@@ -143,7 +134,7 @@ function _evaluate(path, state) {
143
134
  return binding ? deopt(binding.path, state) : NaN;
144
135
  }
145
136
 
146
- const resolved = path.resolve();
137
+ var resolved = path.resolve();
147
138
 
148
139
  if (resolved === path) {
149
140
  return deopt(path, state);
@@ -160,13 +151,13 @@ function _evaluate(path, state) {
160
151
  return undefined;
161
152
  }
162
153
 
163
- const argument = path.get("argument");
154
+ var argument = path.get("argument");
164
155
 
165
156
  if (node.operator === "typeof" && (argument.isFunction() || argument.isClass())) {
166
157
  return "function";
167
158
  }
168
159
 
169
- const arg = evaluateCached(argument, state);
160
+ var arg = evaluateCached(argument, state);
170
161
  if (!state.confident) return;
171
162
 
172
163
  switch (node.operator) {
@@ -188,11 +179,23 @@ function _evaluate(path, state) {
188
179
  }
189
180
 
190
181
  if (path.isArrayExpression()) {
191
- const arr = [];
192
- const elems = path.get("elements");
182
+ var arr = [];
183
+ var elems = path.get("elements");
184
+
185
+ for (var _iterator = elems, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
186
+ var _ref;
187
+
188
+ if (_isArray) {
189
+ if (_i >= _iterator.length) break;
190
+ _ref = _iterator[_i++];
191
+ } else {
192
+ _i = _iterator.next();
193
+ if (_i.done) break;
194
+ _ref = _i.value;
195
+ }
193
196
 
194
- for (const elem of elems) {
195
- const elemValue = elem.evaluate();
197
+ var elem = _ref;
198
+ var elemValue = elem.evaluate();
196
199
 
197
200
  if (elemValue.confident) {
198
201
  arr.push(elemValue.value);
@@ -205,16 +208,29 @@ function _evaluate(path, state) {
205
208
  }
206
209
 
207
210
  if (path.isObjectExpression()) {
208
- const obj = {};
209
- const props = path.get("properties");
211
+ var obj = {};
212
+ var props = path.get("properties");
213
+
214
+ for (var _iterator2 = props, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
215
+ var _ref2;
216
+
217
+ if (_isArray2) {
218
+ if (_i2 >= _iterator2.length) break;
219
+ _ref2 = _iterator2[_i2++];
220
+ } else {
221
+ _i2 = _iterator2.next();
222
+ if (_i2.done) break;
223
+ _ref2 = _i2.value;
224
+ }
225
+
226
+ var prop = _ref2;
210
227
 
211
- for (const prop of props) {
212
228
  if (prop.isObjectMethod() || prop.isSpreadElement()) {
213
229
  return deopt(prop, state);
214
230
  }
215
231
 
216
- const keyPath = prop.get("key");
217
- let key = keyPath;
232
+ var keyPath = prop.get("key");
233
+ var key = keyPath;
218
234
 
219
235
  if (prop.node.computed) {
220
236
  key = key.evaluate();
@@ -230,27 +246,28 @@ function _evaluate(path, state) {
230
246
  key = key.node.value;
231
247
  }
232
248
 
233
- const valuePath = prop.get("value");
234
- let value = valuePath.evaluate();
249
+ var valuePath = prop.get("value");
235
250
 
236
- if (!value.confident) {
251
+ var _value = valuePath.evaluate();
252
+
253
+ if (!_value.confident) {
237
254
  return deopt(valuePath, state);
238
255
  }
239
256
 
240
- value = value.value;
241
- obj[key] = value;
257
+ _value = _value.value;
258
+ obj[key] = _value;
242
259
  }
243
260
 
244
261
  return obj;
245
262
  }
246
263
 
247
264
  if (path.isLogicalExpression()) {
248
- const wasConfident = state.confident;
249
- const left = evaluateCached(path.get("left"), state);
250
- const leftConfident = state.confident;
265
+ var wasConfident = state.confident;
266
+ var left = evaluateCached(path.get("left"), state);
267
+ var leftConfident = state.confident;
251
268
  state.confident = wasConfident;
252
- const right = evaluateCached(path.get("right"), state);
253
- const rightConfident = state.confident;
269
+ var right = evaluateCached(path.get("right"), state);
270
+ var rightConfident = state.confident;
254
271
  state.confident = leftConfident && rightConfident;
255
272
 
256
273
  switch (node.operator) {
@@ -274,104 +291,110 @@ function _evaluate(path, state) {
274
291
  }
275
292
 
276
293
  if (path.isBinaryExpression()) {
277
- const left = evaluateCached(path.get("left"), state);
294
+ var _left = evaluateCached(path.get("left"), state);
295
+
278
296
  if (!state.confident) return;
279
- const right = evaluateCached(path.get("right"), state);
297
+
298
+ var _right = evaluateCached(path.get("right"), state);
299
+
280
300
  if (!state.confident) return;
281
301
 
282
302
  switch (node.operator) {
283
303
  case "-":
284
- return left - right;
304
+ return _left - _right;
285
305
 
286
306
  case "+":
287
- return left + right;
307
+ return _left + _right;
288
308
 
289
309
  case "/":
290
- return left / right;
310
+ return _left / _right;
291
311
 
292
312
  case "*":
293
- return left * right;
313
+ return _left * _right;
294
314
 
295
315
  case "%":
296
- return left % right;
316
+ return _left % _right;
297
317
 
298
318
  case "**":
299
- return left ** right;
319
+ return Math.pow(_left, _right);
300
320
 
301
321
  case "<":
302
- return left < right;
322
+ return _left < _right;
303
323
 
304
324
  case ">":
305
- return left > right;
325
+ return _left > _right;
306
326
 
307
327
  case "<=":
308
- return left <= right;
328
+ return _left <= _right;
309
329
 
310
330
  case ">=":
311
- return left >= right;
331
+ return _left >= _right;
312
332
 
313
333
  case "==":
314
- return left == right;
334
+ return _left == _right;
315
335
 
316
336
  case "!=":
317
- return left != right;
337
+ return _left != _right;
318
338
 
319
339
  case "===":
320
- return left === right;
340
+ return _left === _right;
321
341
 
322
342
  case "!==":
323
- return left !== right;
343
+ return _left !== _right;
324
344
 
325
345
  case "|":
326
- return left | right;
346
+ return _left | _right;
327
347
 
328
348
  case "&":
329
- return left & right;
349
+ return _left & _right;
330
350
 
331
351
  case "^":
332
- return left ^ right;
352
+ return _left ^ _right;
333
353
 
334
354
  case "<<":
335
- return left << right;
355
+ return _left << _right;
336
356
 
337
357
  case ">>":
338
- return left >> right;
358
+ return _left >> _right;
339
359
 
340
360
  case ">>>":
341
- return left >>> right;
361
+ return _left >>> _right;
342
362
  }
343
363
  }
344
364
 
345
365
  if (path.isCallExpression()) {
346
- const callee = path.get("callee");
347
- let context;
348
- let func;
366
+ var callee = path.get("callee");
367
+ var context;
368
+ var func;
349
369
 
350
370
  if (callee.isIdentifier() && !path.scope.getBinding(callee.node.name, true) && VALID_CALLEES.indexOf(callee.node.name) >= 0) {
351
371
  func = global[node.callee.name];
352
372
  }
353
373
 
354
374
  if (callee.isMemberExpression()) {
355
- const object = callee.get("object");
356
- const property = callee.get("property");
375
+ var _object2 = callee.get("object");
376
+
377
+ var _property2 = callee.get("property");
357
378
 
358
- if (object.isIdentifier() && property.isIdentifier() && VALID_CALLEES.indexOf(object.node.name) >= 0 && INVALID_METHODS.indexOf(property.node.name) < 0) {
359
- context = global[object.node.name];
360
- func = context[property.node.name];
379
+ if (_object2.isIdentifier() && _property2.isIdentifier() && VALID_CALLEES.indexOf(_object2.node.name) >= 0 && INVALID_METHODS.indexOf(_property2.node.name) < 0) {
380
+ context = global[_object2.node.name];
381
+ func = context[_property2.node.name];
361
382
  }
362
383
 
363
- if (object.isLiteral() && property.isIdentifier()) {
364
- const type = typeof object.node.value;
384
+ if (_object2.isLiteral() && _property2.isIdentifier()) {
385
+ var _type = typeof _object2.node.value;
365
386
 
366
- if (type === "string" || type === "number") {
367
- context = object.node.value;
368
- func = context[property.node.name];
387
+ if (_type === "string" || _type === "number") {
388
+ context = _object2.node.value;
389
+ func = context[_property2.node.name];
369
390
  }
370
391
  }
371
392
  }
372
393
 
373
394
  if (func) {
374
- const args = path.get("arguments").map(arg => evaluateCached(arg, state));
395
+ var args = path.get("arguments").map(function (arg) {
396
+ return evaluateCached(arg, state);
397
+ });
375
398
  if (!state.confident) return;
376
399
  return func.apply(context, args);
377
400
  }
@@ -380,15 +403,31 @@ function _evaluate(path, state) {
380
403
  deopt(path, state);
381
404
  }
382
405
 
383
- function evaluateQuasis(path, quasis, state, raw = false) {
384
- let str = "";
385
- let i = 0;
386
- const exprs = path.get("expressions");
406
+ function evaluateQuasis(path, quasis, state, raw) {
407
+ if (raw === void 0) {
408
+ raw = false;
409
+ }
410
+
411
+ var str = "";
412
+ var i = 0;
413
+ var exprs = path.get("expressions");
414
+
415
+ for (var _iterator3 = quasis, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
416
+ var _ref3;
417
+
418
+ if (_isArray3) {
419
+ if (_i3 >= _iterator3.length) break;
420
+ _ref3 = _iterator3[_i3++];
421
+ } else {
422
+ _i3 = _iterator3.next();
423
+ if (_i3.done) break;
424
+ _ref3 = _i3.value;
425
+ }
387
426
 
388
- for (const elem of quasis) {
427
+ var elem = _ref3;
389
428
  if (!state.confident) break;
390
429
  str += raw ? elem.value.raw : elem.value.cooked;
391
- const expr = exprs[i++];
430
+ var expr = exprs[i++];
392
431
  if (expr) str += String(evaluateCached(expr, state));
393
432
  }
394
433
 
@@ -397,12 +436,12 @@ function evaluateQuasis(path, quasis, state, raw = false) {
397
436
  }
398
437
 
399
438
  function evaluate() {
400
- const state = {
439
+ var state = {
401
440
  confident: true,
402
441
  deoptPath: null,
403
442
  seen: new Map()
404
443
  };
405
- let value = evaluateCached(this, state);
444
+ var value = evaluateCached(this, state);
406
445
  if (!state.confident) value = undefined;
407
446
  return {
408
447
  confident: state.confident,
@@ -21,9 +21,9 @@ exports.getOuterBindingIdentifierPaths = getOuterBindingIdentifierPaths;
21
21
  var _index = _interopRequireDefault(require("./index"));
22
22
 
23
23
  function t() {
24
- const data = _interopRequireWildcard(require("@babel/types"));
24
+ var data = _interopRequireWildcard(require("@babel/types"));
25
25
 
26
- t = function () {
26
+ t = function t() {
27
27
  return data;
28
28
  };
29
29
 
@@ -48,7 +48,7 @@ function addCompletionRecords(path, paths) {
48
48
  }
49
49
 
50
50
  function getCompletionRecords() {
51
- let paths = [];
51
+ var paths = [];
52
52
 
53
53
  if (this.isIfStatement()) {
54
54
  paths = addCompletionRecords(this.get("consequent"), paths);
@@ -91,9 +91,9 @@ function getNextSibling() {
91
91
  }
92
92
 
93
93
  function getAllNextSiblings() {
94
- let _key = this.key;
95
- let sibling = this.getSibling(++_key);
96
- const siblings = [];
94
+ var _key = this.key;
95
+ var sibling = this.getSibling(++_key);
96
+ var siblings = [];
97
97
 
98
98
  while (sibling.node) {
99
99
  siblings.push(sibling);
@@ -104,9 +104,9 @@ function getAllNextSiblings() {
104
104
  }
105
105
 
106
106
  function getAllPrevSiblings() {
107
- let _key = this.key;
108
- let sibling = this.getSibling(--_key);
109
- const siblings = [];
107
+ var _key = this.key;
108
+ var sibling = this.getSibling(--_key);
109
+ var siblings = [];
110
110
 
111
111
  while (sibling.node) {
112
112
  siblings.push(sibling);
@@ -118,7 +118,7 @@ function getAllPrevSiblings() {
118
118
 
119
119
  function get(key, context) {
120
120
  if (context === true) context = this.context;
121
- const parts = key.split(".");
121
+ var parts = key.split(".");
122
122
 
123
123
  if (parts.length === 1) {
124
124
  return this._getKey(key, context);
@@ -128,14 +128,16 @@ function get(key, context) {
128
128
  }
129
129
 
130
130
  function _getKey(key, context) {
131
- const node = this.node;
132
- const container = node[key];
131
+ var _this = this;
132
+
133
+ var node = this.node;
134
+ var container = node[key];
133
135
 
134
136
  if (Array.isArray(container)) {
135
- return container.map((_, i) => {
137
+ return container.map(function (_, i) {
136
138
  return _index.default.get({
137
139
  listKey: key,
138
- parentPath: this,
140
+ parentPath: _this,
139
141
  parent: node,
140
142
  container: container,
141
143
  key: i
@@ -152,9 +154,12 @@ function _getKey(key, context) {
152
154
  }
153
155
 
154
156
  function _getPattern(parts, context) {
155
- let path = this;
157
+ var path = this;
158
+ var _arr = parts;
159
+
160
+ for (var _i = 0; _i < _arr.length; _i++) {
161
+ var part = _arr[_i];
156
162
 
157
- for (const part of parts) {
158
163
  if (part === ".") {
159
164
  path = path.parentPath;
160
165
  } else {
@@ -177,20 +182,28 @@ function getOuterBindingIdentifiers(duplicates) {
177
182
  return t().getOuterBindingIdentifiers(this.node, duplicates);
178
183
  }
179
184
 
180
- function getBindingIdentifierPaths(duplicates = false, outerOnly = false) {
181
- const path = this;
182
- let search = [].concat(path);
183
- const ids = Object.create(null);
185
+ function getBindingIdentifierPaths(duplicates, outerOnly) {
186
+ if (duplicates === void 0) {
187
+ duplicates = false;
188
+ }
189
+
190
+ if (outerOnly === void 0) {
191
+ outerOnly = false;
192
+ }
193
+
194
+ var path = this;
195
+ var search = [].concat(path);
196
+ var ids = Object.create(null);
184
197
 
185
198
  while (search.length) {
186
- const id = search.shift();
199
+ var id = search.shift();
187
200
  if (!id) continue;
188
201
  if (!id.node) continue;
189
- const keys = t().getBindingIdentifiers.keys[id.node.type];
202
+ var keys = t().getBindingIdentifiers.keys[id.node.type];
190
203
 
191
204
  if (id.isIdentifier()) {
192
205
  if (duplicates) {
193
- const _ids = ids[id.node.name] = ids[id.node.name] || [];
206
+ var _ids = ids[id.node.name] = ids[id.node.name] || [];
194
207
 
195
208
  _ids.push(id);
196
209
  } else {
@@ -201,7 +214,7 @@ function getBindingIdentifierPaths(duplicates = false, outerOnly = false) {
201
214
  }
202
215
 
203
216
  if (id.isExportDeclaration()) {
204
- const declaration = id.get("declaration");
217
+ var declaration = id.get("declaration");
205
218
 
206
219
  if (declaration.isDeclaration()) {
207
220
  search.push(declaration);
@@ -222,9 +235,9 @@ function getBindingIdentifierPaths(duplicates = false, outerOnly = false) {
222
235
  }
223
236
 
224
237
  if (keys) {
225
- for (let i = 0; i < keys.length; i++) {
226
- const key = keys[i];
227
- const child = id.get(key);
238
+ for (var i = 0; i < keys.length; i++) {
239
+ var key = keys[i];
240
+ var child = id.get(key);
228
241
 
229
242
  if (Array.isArray(child) || child.node) {
230
243
  search = search.concat(child);