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