@babel/traverse 7.0.0-beta.40 → 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.
- package/lib/cache.js +3 -1
- package/lib/context.js +27 -18
- package/lib/hub.js +3 -1
- package/lib/index.js +48 -18
- package/lib/path/ancestry.js +13 -3
- package/lib/path/comments.js +14 -4
- package/lib/path/context.js +9 -9
- package/lib/path/conversion.js +56 -38
- package/lib/path/evaluation.js +18 -18
- package/lib/path/family.js +15 -5
- package/lib/path/index.js +51 -19
- package/lib/path/inference/index.js +29 -19
- package/lib/path/inference/inferer-reference.js +19 -9
- package/lib/path/inference/inferers.js +54 -41
- package/lib/path/introspection.js +34 -16
- package/lib/path/lib/hoister.js +21 -7
- package/lib/path/lib/removal-hooks.js +3 -1
- package/lib/path/lib/virtual-types.js +31 -21
- package/lib/path/modification.js +18 -9
- package/lib/path/removal.js +3 -1
- package/lib/path/replacement.js +53 -28
- package/lib/scope/binding.js +3 -1
- package/lib/scope/index.js +120 -85
- package/lib/scope/lib/renamer.js +34 -30
- package/lib/visitors.js +53 -33
- package/package.json +9 -8
package/lib/scope/index.js
CHANGED
@@ -1,23 +1,65 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
exports
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
4
6
|
exports.default = void 0;
|
5
7
|
|
6
|
-
|
8
|
+
function _includes() {
|
9
|
+
var data = _interopRequireDefault(require("lodash/includes"));
|
7
10
|
|
8
|
-
|
11
|
+
_includes = function _includes() {
|
12
|
+
return data;
|
13
|
+
};
|
14
|
+
|
15
|
+
return data;
|
16
|
+
}
|
17
|
+
|
18
|
+
function _repeat() {
|
19
|
+
var data = _interopRequireDefault(require("lodash/repeat"));
|
20
|
+
|
21
|
+
_repeat = function _repeat() {
|
22
|
+
return data;
|
23
|
+
};
|
24
|
+
|
25
|
+
return data;
|
26
|
+
}
|
9
27
|
|
10
28
|
var _renamer = _interopRequireDefault(require("./lib/renamer"));
|
11
29
|
|
12
30
|
var _index = _interopRequireDefault(require("../index"));
|
13
31
|
|
14
|
-
|
32
|
+
function _defaults() {
|
33
|
+
var data = _interopRequireDefault(require("lodash/defaults"));
|
34
|
+
|
35
|
+
_defaults = function _defaults() {
|
36
|
+
return data;
|
37
|
+
};
|
38
|
+
|
39
|
+
return data;
|
40
|
+
}
|
15
41
|
|
16
42
|
var _binding2 = _interopRequireDefault(require("./binding"));
|
17
43
|
|
18
|
-
|
44
|
+
function _globals() {
|
45
|
+
var data = _interopRequireDefault(require("globals"));
|
46
|
+
|
47
|
+
_globals = function _globals() {
|
48
|
+
return data;
|
49
|
+
};
|
50
|
+
|
51
|
+
return data;
|
52
|
+
}
|
53
|
+
|
54
|
+
function t() {
|
55
|
+
var data = _interopRequireWildcard(require("@babel/types"));
|
56
|
+
|
57
|
+
t = function t() {
|
58
|
+
return data;
|
59
|
+
};
|
19
60
|
|
20
|
-
|
61
|
+
return data;
|
62
|
+
}
|
21
63
|
|
22
64
|
var _cache = require("../cache");
|
23
65
|
|
@@ -30,7 +72,7 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
|
|
30
72
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
31
73
|
|
32
74
|
function gatherNodeParts(node, parts) {
|
33
|
-
if (t.isModuleDeclaration(node)) {
|
75
|
+
if (t().isModuleDeclaration(node)) {
|
34
76
|
if (node.source) {
|
35
77
|
gatherNodeParts(node.source, parts);
|
36
78
|
} else if (node.specifiers && node.specifiers.length) {
|
@@ -43,18 +85,18 @@ function gatherNodeParts(node, parts) {
|
|
43
85
|
} else if (node.declaration) {
|
44
86
|
gatherNodeParts(node.declaration, parts);
|
45
87
|
}
|
46
|
-
} else if (t.isModuleSpecifier(node)) {
|
88
|
+
} else if (t().isModuleSpecifier(node)) {
|
47
89
|
gatherNodeParts(node.local, parts);
|
48
|
-
} else if (t.isMemberExpression(node)) {
|
90
|
+
} else if (t().isMemberExpression(node)) {
|
49
91
|
gatherNodeParts(node.object, parts);
|
50
92
|
gatherNodeParts(node.property, parts);
|
51
|
-
} else if (t.isIdentifier(node)) {
|
93
|
+
} else if (t().isIdentifier(node)) {
|
52
94
|
parts.push(node.name);
|
53
|
-
} else if (t.isLiteral(node)) {
|
95
|
+
} else if (t().isLiteral(node)) {
|
54
96
|
parts.push(node.value);
|
55
|
-
} else if (t.isCallExpression(node)) {
|
97
|
+
} else if (t().isCallExpression(node)) {
|
56
98
|
gatherNodeParts(node.callee, parts);
|
57
|
-
} else if (t.isObjectExpression(node) || t.isObjectPattern(node)) {
|
99
|
+
} else if (t().isObjectExpression(node) || t().isObjectPattern(node)) {
|
58
100
|
var _arr2 = node.properties;
|
59
101
|
|
60
102
|
for (var _i2 = 0; _i2 < _arr2.length; _i2++) {
|
@@ -66,7 +108,7 @@ function gatherNodeParts(node, parts) {
|
|
66
108
|
|
67
109
|
var collectorVisitor = {
|
68
110
|
For: function For(path) {
|
69
|
-
var _arr3 = t.FOR_INIT_KEYS;
|
111
|
+
var _arr3 = t().FOR_INIT_KEYS;
|
70
112
|
|
71
113
|
for (var _i3 = 0; _i3 < _arr3.length; _i3++) {
|
72
114
|
var key = _arr3[_i3];
|
@@ -104,17 +146,17 @@ var collectorVisitor = {
|
|
104
146
|
scope = path.scope;
|
105
147
|
var declar = node.declaration;
|
106
148
|
|
107
|
-
if (t.isClassDeclaration(declar) || t.isFunctionDeclaration(declar)) {
|
149
|
+
if (t().isClassDeclaration(declar) || t().isFunctionDeclaration(declar)) {
|
108
150
|
var _id = declar.id;
|
109
151
|
if (!_id) return;
|
110
152
|
var binding = scope.getBinding(_id.name);
|
111
153
|
if (binding) binding.reference(path);
|
112
|
-
} else if (t.isVariableDeclaration(declar)) {
|
154
|
+
} else if (t().isVariableDeclaration(declar)) {
|
113
155
|
var _arr4 = declar.declarations;
|
114
156
|
|
115
157
|
for (var _i4 = 0; _i4 < _arr4.length; _i4++) {
|
116
158
|
var decl = _arr4[_i4];
|
117
|
-
var ids = t.getBindingIdentifiers(decl);
|
159
|
+
var ids = t().getBindingIdentifiers(decl);
|
118
160
|
|
119
161
|
for (var name in ids) {
|
120
162
|
var _binding = scope.getBinding(name);
|
@@ -191,23 +233,15 @@ var Scope = function () {
|
|
191
233
|
};
|
192
234
|
|
193
235
|
_proto.generateDeclaredUidIdentifier = function generateDeclaredUidIdentifier(name) {
|
194
|
-
if (name === void 0) {
|
195
|
-
name = "temp";
|
196
|
-
}
|
197
|
-
|
198
236
|
var id = this.generateUidIdentifier(name);
|
199
237
|
this.push({
|
200
238
|
id: id
|
201
239
|
});
|
202
|
-
return t.cloneNode(id);
|
240
|
+
return t().cloneNode(id);
|
203
241
|
};
|
204
242
|
|
205
243
|
_proto.generateUidIdentifier = function generateUidIdentifier(name) {
|
206
|
-
|
207
|
-
name = "temp";
|
208
|
-
}
|
209
|
-
|
210
|
-
return t.identifier(this.generateUid(name));
|
244
|
+
return t().identifier(this.generateUid(name));
|
211
245
|
};
|
212
246
|
|
213
247
|
_proto.generateUid = function generateUid(name) {
|
@@ -215,7 +249,7 @@ var Scope = function () {
|
|
215
249
|
name = "temp";
|
216
250
|
}
|
217
251
|
|
218
|
-
name = t.toIdentifier(name).replace(/^_+/, "").replace(/[0-9]+$/g, "");
|
252
|
+
name = t().toIdentifier(name).replace(/^_+/, "").replace(/[0-9]+$/g, "");
|
219
253
|
var uid;
|
220
254
|
var i = 0;
|
221
255
|
|
@@ -239,11 +273,11 @@ var Scope = function () {
|
|
239
273
|
_proto.generateUidBasedOnNode = function generateUidBasedOnNode(parent, defaultName) {
|
240
274
|
var node = parent;
|
241
275
|
|
242
|
-
if (t.isAssignmentExpression(parent)) {
|
276
|
+
if (t().isAssignmentExpression(parent)) {
|
243
277
|
node = parent.left;
|
244
|
-
} else if (t.isVariableDeclarator(parent)) {
|
278
|
+
} else if (t().isVariableDeclarator(parent)) {
|
245
279
|
node = parent.id;
|
246
|
-
} else if (t.isObjectProperty(node) || t.isObjectMethod(node)) {
|
280
|
+
} else if (t().isObjectProperty(node) || t().isObjectMethod(node)) {
|
247
281
|
node = node.key;
|
248
282
|
}
|
249
283
|
|
@@ -255,15 +289,15 @@ var Scope = function () {
|
|
255
289
|
};
|
256
290
|
|
257
291
|
_proto.generateUidIdentifierBasedOnNode = function generateUidIdentifierBasedOnNode(parent, defaultName) {
|
258
|
-
return t.identifier(this.generateUidBasedOnNode(parent, defaultName));
|
292
|
+
return t().identifier(this.generateUidBasedOnNode(parent, defaultName));
|
259
293
|
};
|
260
294
|
|
261
295
|
_proto.isStatic = function isStatic(node) {
|
262
|
-
if (t.isThisExpression(node) || t.isSuper(node)) {
|
296
|
+
if (t().isThisExpression(node) || t().isSuper(node)) {
|
263
297
|
return true;
|
264
298
|
}
|
265
299
|
|
266
|
-
if (t.isIdentifier(node)) {
|
300
|
+
if (t().isIdentifier(node)) {
|
267
301
|
var binding = this.getBinding(node.name);
|
268
302
|
|
269
303
|
if (binding) {
|
@@ -286,7 +320,7 @@ var Scope = function () {
|
|
286
320
|
this.push({
|
287
321
|
id: _id2
|
288
322
|
});
|
289
|
-
return t.cloneNode(_id2);
|
323
|
+
return t().cloneNode(_id2);
|
290
324
|
}
|
291
325
|
|
292
326
|
return _id2;
|
@@ -321,7 +355,7 @@ var Scope = function () {
|
|
321
355
|
};
|
322
356
|
|
323
357
|
_proto.dump = function dump() {
|
324
|
-
var sep = (0, _repeat.default)("-", 60);
|
358
|
+
var sep = (0, _repeat().default)("-", 60);
|
325
359
|
console.log(sep);
|
326
360
|
var scope = this;
|
327
361
|
|
@@ -345,7 +379,7 @@ var Scope = function () {
|
|
345
379
|
_proto.toArray = function toArray(node, i) {
|
346
380
|
var file = this.hub.file;
|
347
381
|
|
348
|
-
if (t.isIdentifier(node)) {
|
382
|
+
if (t().isIdentifier(node)) {
|
349
383
|
var binding = this.getBinding(node.name);
|
350
384
|
|
351
385
|
if (binding && binding.constant && binding.path.isGenericType("Array")) {
|
@@ -353,27 +387,29 @@ var Scope = function () {
|
|
353
387
|
}
|
354
388
|
}
|
355
389
|
|
356
|
-
if (t.isArrayExpression(node)) {
|
390
|
+
if (t().isArrayExpression(node)) {
|
357
391
|
return node;
|
358
392
|
}
|
359
393
|
|
360
|
-
if (t.isIdentifier(node, {
|
394
|
+
if (t().isIdentifier(node, {
|
361
395
|
name: "arguments"
|
362
396
|
})) {
|
363
|
-
return t.callExpression(t.memberExpression(t.memberExpression(t.memberExpression(t.identifier("Array"), t.identifier("prototype")), t.identifier("slice")), t.identifier("call")), [node]);
|
397
|
+
return t().callExpression(t().memberExpression(t().memberExpression(t().memberExpression(t().identifier("Array"), t().identifier("prototype")), t().identifier("slice")), t().identifier("call")), [node]);
|
364
398
|
}
|
365
399
|
|
366
|
-
var helperName
|
400
|
+
var helperName;
|
367
401
|
var args = [node];
|
368
402
|
|
369
403
|
if (i === true) {
|
370
404
|
helperName = "toConsumableArray";
|
371
405
|
} else if (i) {
|
372
|
-
args.push(t.numericLiteral(i));
|
406
|
+
args.push(t().numericLiteral(i));
|
373
407
|
helperName = "slicedToArray";
|
408
|
+
} else {
|
409
|
+
helperName = "toArray";
|
374
410
|
}
|
375
411
|
|
376
|
-
return t.callExpression(file.addHelper(helperName), args);
|
412
|
+
return t().callExpression(file.addHelper(helperName), args);
|
377
413
|
};
|
378
414
|
|
379
415
|
_proto.hasLabel = function hasLabel(name) {
|
@@ -426,9 +462,9 @@ var Scope = function () {
|
|
426
462
|
|
427
463
|
_proto.buildUndefinedNode = function buildUndefinedNode() {
|
428
464
|
if (this.hasBinding("undefined")) {
|
429
|
-
return t.unaryExpression("void", t.numericLiteral(0), true);
|
465
|
+
return t().unaryExpression("void", t().numericLiteral(0), true);
|
430
466
|
} else {
|
431
|
-
return t.identifier("undefined");
|
467
|
+
return t().identifier("undefined");
|
432
468
|
}
|
433
469
|
};
|
434
470
|
|
@@ -463,8 +499,8 @@ var Scope = function () {
|
|
463
499
|
_ref = _i8.value;
|
464
500
|
}
|
465
501
|
|
466
|
-
var
|
467
|
-
this.registerBinding(kind,
|
502
|
+
var declar = _ref;
|
503
|
+
this.registerBinding(kind, declar);
|
468
504
|
}
|
469
505
|
|
470
506
|
return;
|
@@ -536,18 +572,18 @@ var Scope = function () {
|
|
536
572
|
};
|
537
573
|
|
538
574
|
_proto.isPure = function isPure(node, constantsOnly) {
|
539
|
-
if (t.isIdentifier(node)) {
|
575
|
+
if (t().isIdentifier(node)) {
|
540
576
|
var binding = this.getBinding(node.name);
|
541
577
|
if (!binding) return false;
|
542
578
|
if (constantsOnly) return binding.constant;
|
543
579
|
return true;
|
544
|
-
} else if (t.isClass(node)) {
|
580
|
+
} else if (t().isClass(node)) {
|
545
581
|
if (node.superClass && !this.isPure(node.superClass, constantsOnly)) {
|
546
582
|
return false;
|
547
583
|
}
|
548
584
|
|
549
585
|
return this.isPure(node.body, constantsOnly);
|
550
|
-
} else if (t.isClassBody(node)) {
|
586
|
+
} else if (t().isClassBody(node)) {
|
551
587
|
for (var _iterator2 = node.body, _isArray2 = Array.isArray(_iterator2), _i10 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
|
552
588
|
var _ref2;
|
553
589
|
|
@@ -560,14 +596,14 @@ var Scope = function () {
|
|
560
596
|
_ref2 = _i10.value;
|
561
597
|
}
|
562
598
|
|
563
|
-
var
|
564
|
-
if (!this.isPure(
|
599
|
+
var method = _ref2;
|
600
|
+
if (!this.isPure(method, constantsOnly)) return false;
|
565
601
|
}
|
566
602
|
|
567
603
|
return true;
|
568
|
-
} else if (t.isBinary(node)) {
|
604
|
+
} else if (t().isBinary(node)) {
|
569
605
|
return this.isPure(node.left, constantsOnly) && this.isPure(node.right, constantsOnly);
|
570
|
-
} else if (t.isArrayExpression(node)) {
|
606
|
+
} else if (t().isArrayExpression(node)) {
|
571
607
|
var _arr9 = node.elements;
|
572
608
|
|
573
609
|
for (var _i11 = 0; _i11 < _arr9.length; _i11++) {
|
@@ -576,7 +612,7 @@ var Scope = function () {
|
|
576
612
|
}
|
577
613
|
|
578
614
|
return true;
|
579
|
-
} else if (t.isObjectExpression(node)) {
|
615
|
+
} else if (t().isObjectExpression(node)) {
|
580
616
|
var _arr10 = node.properties;
|
581
617
|
|
582
618
|
for (var _i12 = 0; _i12 < _arr10.length; _i12++) {
|
@@ -585,18 +621,18 @@ var Scope = function () {
|
|
585
621
|
}
|
586
622
|
|
587
623
|
return true;
|
588
|
-
} else if (t.isClassMethod(node)) {
|
624
|
+
} else if (t().isClassMethod(node)) {
|
589
625
|
if (node.computed && !this.isPure(node.key, constantsOnly)) return false;
|
590
626
|
if (node.kind === "get" || node.kind === "set") return false;
|
591
627
|
return true;
|
592
|
-
} else if (t.isClassProperty(node) || t.isObjectProperty(node)) {
|
628
|
+
} else if (t().isClassProperty(node) || t().isObjectProperty(node)) {
|
593
629
|
if (node.computed && !this.isPure(node.key, constantsOnly)) return false;
|
594
630
|
return this.isPure(node.value, constantsOnly);
|
595
|
-
} else if (t.isUnaryExpression(node)) {
|
631
|
+
} else if (t().isUnaryExpression(node)) {
|
596
632
|
return this.isPure(node.argument, constantsOnly);
|
597
|
-
} else if (t.isTaggedTemplateExpression(node)) {
|
598
|
-
return t.matchesPattern(node.tag, "String.raw") && !this.hasBinding("String", true) && this.isPure(node.quasi, constantsOnly);
|
599
|
-
} else if (t.isTemplateLiteral(node)) {
|
633
|
+
} else if (t().isTaggedTemplateExpression(node)) {
|
634
|
+
return t().matchesPattern(node.tag, "String.raw") && !this.hasBinding("String", true) && this.isPure(node.quasi, constantsOnly);
|
635
|
+
} else if (t().isTemplateLiteral(node)) {
|
600
636
|
var _arr11 = node.expressions;
|
601
637
|
|
602
638
|
for (var _i13 = 0; _i13 < _arr11.length; _i13++) {
|
@@ -606,7 +642,7 @@ var Scope = function () {
|
|
606
642
|
|
607
643
|
return true;
|
608
644
|
} else {
|
609
|
-
return t.isPureish(node);
|
645
|
+
return t().isPureish(node);
|
610
646
|
}
|
611
647
|
};
|
612
648
|
|
@@ -645,7 +681,7 @@ var Scope = function () {
|
|
645
681
|
this.data = Object.create(null);
|
646
682
|
|
647
683
|
if (path.isLoop()) {
|
648
|
-
var _arr12 = t.FOR_INIT_KEYS;
|
684
|
+
var _arr12 = t().FOR_INIT_KEYS;
|
649
685
|
|
650
686
|
for (var _i14 = 0; _i14 < _arr12.length; _i14++) {
|
651
687
|
var key = _arr12[_i14];
|
@@ -655,13 +691,13 @@ var Scope = function () {
|
|
655
691
|
}
|
656
692
|
|
657
693
|
if (path.isFunctionExpression() && path.has("id")) {
|
658
|
-
if (!path.get("id").node[t.NOT_LOCAL_BINDING]) {
|
694
|
+
if (!path.get("id").node[t().NOT_LOCAL_BINDING]) {
|
659
695
|
this.registerBinding("local", path.get("id"), path);
|
660
696
|
}
|
661
697
|
}
|
662
698
|
|
663
699
|
if (path.isClassExpression() && path.has("id")) {
|
664
|
-
if (!path.get("id").node[t.NOT_LOCAL_BINDING]) {
|
700
|
+
if (!path.get("id").node[t().NOT_LOCAL_BINDING]) {
|
665
701
|
this.registerBinding("local", path);
|
666
702
|
}
|
667
703
|
}
|
@@ -681,8 +717,8 @@ var Scope = function () {
|
|
681
717
|
_ref3 = _i15.value;
|
682
718
|
}
|
683
719
|
|
684
|
-
var
|
685
|
-
this.registerBinding("param",
|
720
|
+
var param = _ref3;
|
721
|
+
this.registerBinding("param", param);
|
686
722
|
}
|
687
723
|
}
|
688
724
|
|
@@ -713,19 +749,19 @@ var Scope = function () {
|
|
713
749
|
_ref4 = _i16.value;
|
714
750
|
}
|
715
751
|
|
716
|
-
var
|
752
|
+
var _path = _ref4;
|
717
753
|
|
718
|
-
var ids =
|
754
|
+
var ids = _path.getBindingIdentifiers();
|
719
755
|
|
720
756
|
var programParent = void 0;
|
721
757
|
|
722
758
|
for (var name in ids) {
|
723
|
-
if (
|
724
|
-
programParent = programParent ||
|
759
|
+
if (_path.scope.getBinding(name)) continue;
|
760
|
+
programParent = programParent || _path.scope.getProgramParent();
|
725
761
|
programParent.addGlobal(ids[name]);
|
726
762
|
}
|
727
763
|
|
728
|
-
|
764
|
+
_path.scope.registerConstantViolation(_path);
|
729
765
|
}
|
730
766
|
|
731
767
|
for (var _iterator5 = state.references, _isArray5 = Array.isArray(_iterator5), _i17 = 0, _iterator5 = _isArray5 ? _iterator5 : _iterator5[Symbol.iterator]();;) {
|
@@ -740,14 +776,13 @@ var Scope = function () {
|
|
740
776
|
_ref5 = _i17.value;
|
741
777
|
}
|
742
778
|
|
743
|
-
var
|
744
|
-
|
745
|
-
var binding = _ref7.scope.getBinding(_ref7.node.name);
|
779
|
+
var ref = _ref5;
|
780
|
+
var binding = ref.scope.getBinding(ref.node.name);
|
746
781
|
|
747
782
|
if (binding) {
|
748
|
-
binding.reference(
|
783
|
+
binding.reference(ref);
|
749
784
|
} else {
|
750
|
-
|
785
|
+
ref.scope.getProgramParent().addGlobal(ref.node);
|
751
786
|
}
|
752
787
|
}
|
753
788
|
|
@@ -763,9 +798,9 @@ var Scope = function () {
|
|
763
798
|
_ref6 = _i18.value;
|
764
799
|
}
|
765
800
|
|
766
|
-
var
|
801
|
+
var _path2 = _ref6;
|
767
802
|
|
768
|
-
|
803
|
+
_path2.scope.registerConstantViolation(_path2);
|
769
804
|
}
|
770
805
|
};
|
771
806
|
|
@@ -792,7 +827,7 @@ var Scope = function () {
|
|
792
827
|
var declarPath = !unique && path.getData(dataKey);
|
793
828
|
|
794
829
|
if (!declarPath) {
|
795
|
-
var declar = t.variableDeclaration(kind, []);
|
830
|
+
var declar = t().variableDeclaration(kind, []);
|
796
831
|
declar._blockHoist = blockHoist;
|
797
832
|
|
798
833
|
var _path$unshiftContaine = path.unshiftContainer("body", [declar]);
|
@@ -801,7 +836,7 @@ var Scope = function () {
|
|
801
836
|
if (!unique) path.setData(dataKey, declarPath);
|
802
837
|
}
|
803
838
|
|
804
|
-
var declarator = t.variableDeclarator(opts.id, opts.init);
|
839
|
+
var declarator = t().variableDeclarator(opts.id, opts.init);
|
805
840
|
declarPath.node.declarations.push(declarator);
|
806
841
|
this.registerBinding(kind, declarPath.get("declarations").pop());
|
807
842
|
};
|
@@ -847,7 +882,7 @@ var Scope = function () {
|
|
847
882
|
var scope = this;
|
848
883
|
|
849
884
|
do {
|
850
|
-
(0, _defaults.default)(ids, scope.bindings);
|
885
|
+
(0, _defaults().default)(ids, scope.bindings);
|
851
886
|
scope = scope.parent;
|
852
887
|
} while (scope);
|
853
888
|
|
@@ -911,8 +946,8 @@ var Scope = function () {
|
|
911
946
|
if (this.hasOwnBinding(name)) return true;
|
912
947
|
if (this.parentHasBinding(name, noGlobals)) return true;
|
913
948
|
if (this.hasUid(name)) return true;
|
914
|
-
if (!noGlobals && (0, _includes.default)(Scope.globals, name)) return true;
|
915
|
-
if (!noGlobals && (0, _includes.default)(Scope.contextVariables, name)) return true;
|
949
|
+
if (!noGlobals && (0, _includes().default)(Scope.globals, name)) return true;
|
950
|
+
if (!noGlobals && (0, _includes().default)(Scope.contextVariables, name)) return true;
|
916
951
|
return false;
|
917
952
|
};
|
918
953
|
|
@@ -974,5 +1009,5 @@ var Scope = function () {
|
|
974
1009
|
}();
|
975
1010
|
|
976
1011
|
exports.default = Scope;
|
977
|
-
Scope.globals = Object.keys(_globals.default.builtin);
|
1012
|
+
Scope.globals = Object.keys(_globals().default.builtin);
|
978
1013
|
Scope.contextVariables = ["arguments", "undefined", "Infinity", "NaN"];
|
package/lib/scope/lib/renamer.js
CHANGED
@@ -1,11 +1,31 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
exports
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
4
6
|
exports.default = void 0;
|
5
7
|
|
6
8
|
var _binding = _interopRequireDefault(require("../binding"));
|
7
9
|
|
8
|
-
|
10
|
+
function _helperSplitExportDeclaration() {
|
11
|
+
var data = _interopRequireDefault(require("@babel/helper-split-export-declaration"));
|
12
|
+
|
13
|
+
_helperSplitExportDeclaration = function _helperSplitExportDeclaration() {
|
14
|
+
return data;
|
15
|
+
};
|
16
|
+
|
17
|
+
return data;
|
18
|
+
}
|
19
|
+
|
20
|
+
function t() {
|
21
|
+
var data = _interopRequireWildcard(require("@babel/types"));
|
22
|
+
|
23
|
+
t = function t() {
|
24
|
+
return data;
|
25
|
+
};
|
26
|
+
|
27
|
+
return data;
|
28
|
+
}
|
9
29
|
|
10
30
|
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; } }
|
11
31
|
|
@@ -43,53 +63,37 @@ var Renamer = function () {
|
|
43
63
|
var _proto = Renamer.prototype;
|
44
64
|
|
45
65
|
_proto.maybeConvertFromExportDeclaration = function maybeConvertFromExportDeclaration(parentDeclar) {
|
46
|
-
var
|
47
|
-
if (!exportDeclar) return;
|
48
|
-
var isDefault = exportDeclar.isExportDefaultDeclaration();
|
66
|
+
var maybeExportDeclar = parentDeclar.parentPath;
|
49
67
|
|
50
|
-
if (
|
51
|
-
|
68
|
+
if (!maybeExportDeclar.isExportDeclaration()) {
|
69
|
+
return;
|
52
70
|
}
|
53
71
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
for (var name in bindingIdentifiers) {
|
58
|
-
var localName = name === this.oldName ? this.newName : name;
|
59
|
-
var exportedName = isDefault ? "default" : name;
|
60
|
-
specifiers.push(t.exportSpecifier(t.identifier(localName), t.identifier(exportedName)));
|
72
|
+
if (maybeExportDeclar.isExportDefaultDeclaration() && !maybeExportDeclar.get("declaration").node.id) {
|
73
|
+
return;
|
61
74
|
}
|
62
75
|
|
63
|
-
|
64
|
-
var aliasDeclar = t.exportNamedDeclaration(null, specifiers);
|
65
|
-
|
66
|
-
if (parentDeclar.isFunctionDeclaration()) {
|
67
|
-
aliasDeclar._blockHoist = 3;
|
68
|
-
}
|
69
|
-
|
70
|
-
exportDeclar.insertAfter(aliasDeclar);
|
71
|
-
exportDeclar.replaceWith(parentDeclar.node);
|
72
|
-
}
|
76
|
+
(0, _helperSplitExportDeclaration().default)(maybeExportDeclar);
|
73
77
|
};
|
74
78
|
|
75
79
|
_proto.maybeConvertFromClassFunctionDeclaration = function maybeConvertFromClassFunctionDeclaration(path) {
|
76
80
|
return;
|
77
81
|
if (!path.isFunctionDeclaration() && !path.isClassDeclaration()) return;
|
78
82
|
if (this.binding.kind !== "hoisted") return;
|
79
|
-
path.node.id = t.identifier(this.oldName);
|
83
|
+
path.node.id = t().identifier(this.oldName);
|
80
84
|
path.node._blockHoist = 3;
|
81
|
-
path.replaceWith(t.variableDeclaration("let", [t.variableDeclarator(t.identifier(this.newName), t.toExpression(path.node))]));
|
85
|
+
path.replaceWith(t().variableDeclaration("let", [t().variableDeclarator(t().identifier(this.newName), t().toExpression(path.node))]));
|
82
86
|
};
|
83
87
|
|
84
88
|
_proto.maybeConvertFromClassFunctionExpression = function maybeConvertFromClassFunctionExpression(path) {
|
85
89
|
return;
|
86
90
|
if (!path.isFunctionExpression() && !path.isClassExpression()) return;
|
87
91
|
if (this.binding.kind !== "local") return;
|
88
|
-
path.node.id = t.identifier(this.oldName);
|
92
|
+
path.node.id = t().identifier(this.oldName);
|
89
93
|
this.binding.scope.parent.push({
|
90
|
-
id: t.identifier(this.newName)
|
94
|
+
id: t().identifier(this.newName)
|
91
95
|
});
|
92
|
-
path.replaceWith(t.assignmentExpression("=", t.identifier(this.newName), path.node));
|
96
|
+
path.replaceWith(t().assignmentExpression("=", t().identifier(this.newName), path.node));
|
93
97
|
};
|
94
98
|
|
95
99
|
_proto.rename = function rename(block) {
|
@@ -99,7 +103,7 @@ var Renamer = function () {
|
|
99
103
|
var scope = binding.scope,
|
100
104
|
path = binding.path;
|
101
105
|
var parentDeclar = path.find(function (path) {
|
102
|
-
return path.isDeclaration() || path.isFunctionExpression();
|
106
|
+
return path.isDeclaration() || path.isFunctionExpression() || path.isClassExpression();
|
103
107
|
});
|
104
108
|
|
105
109
|
if (parentDeclar) {
|