@babel/traverse 7.0.0-beta.43 → 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.
- package/lib/context.js +40 -4
- package/lib/index.js +18 -6
- package/lib/path/ancestry.js +12 -4
- package/lib/path/comments.js +1 -1
- package/lib/path/context.js +26 -2
- package/lib/path/conversion.js +13 -12
- package/lib/path/evaluation.js +45 -18
- package/lib/path/family.js +5 -2
- package/lib/path/index.js +10 -7
- package/lib/path/inference/index.js +6 -2
- package/lib/path/inference/inferer-reference.js +4 -2
- package/lib/path/inference/inferers.js +3 -5
- package/lib/path/introspection.js +71 -5
- package/lib/path/lib/hoister.js +9 -3
- package/lib/path/lib/virtual-types.js +1 -1
- package/lib/path/modification.js +34 -10
- package/lib/path/removal.js +4 -1
- package/lib/path/replacement.js +20 -5
- package/lib/scope/index.js +146 -33
- package/lib/scope/lib/renamer.js +7 -11
- package/lib/visitors.js +53 -9
- package/package.json +9 -9
package/lib/path/lib/hoister.js
CHANGED
@@ -8,7 +8,7 @@ exports.default = void 0;
|
|
8
8
|
function t() {
|
9
9
|
const data = _interopRequireWildcard(require("@babel/types"));
|
10
10
|
|
11
|
-
t = function () {
|
11
|
+
t = function t() {
|
12
12
|
return data;
|
13
13
|
};
|
14
14
|
|
@@ -105,8 +105,11 @@ class PathHoister {
|
|
105
105
|
if (bindingParentPath.key >= path.key) {
|
106
106
|
this.attachAfter = true;
|
107
107
|
path = binding.path;
|
108
|
+
var _arr = binding.constantViolations;
|
109
|
+
|
110
|
+
for (var _i = 0; _i < _arr.length; _i++) {
|
111
|
+
const violationPath = _arr[_i];
|
108
112
|
|
109
|
-
for (const violationPath of binding.constantViolations) {
|
110
113
|
if (this.getAttachmentParentForPath(violationPath).key > path.key) {
|
111
114
|
path = violationPath;
|
112
115
|
}
|
@@ -172,7 +175,10 @@ class PathHoister {
|
|
172
175
|
let uid = attachTo.scope.generateUidIdentifier("ref");
|
173
176
|
const declarator = t().variableDeclarator(uid, this.path.node);
|
174
177
|
const insertFn = this.attachAfter ? "insertAfter" : "insertBefore";
|
175
|
-
|
178
|
+
|
179
|
+
const _attachTo$insertFn = attachTo[insertFn]([attachTo.isVariableDeclarator() ? declarator : t().variableDeclaration("var", [declarator])]),
|
180
|
+
attached = _attachTo$insertFn[0];
|
181
|
+
|
176
182
|
const parent = this.path.parentPath;
|
177
183
|
|
178
184
|
if (parent.isJSXElement() && this.path.container === parent.node.children) {
|
package/lib/path/modification.js
CHANGED
@@ -23,7 +23,7 @@ var _index = _interopRequireDefault(require("./index"));
|
|
23
23
|
function t() {
|
24
24
|
const data = _interopRequireWildcard(require("@babel/types"));
|
25
25
|
|
26
|
-
t = function () {
|
26
|
+
t = function t() {
|
27
27
|
return data;
|
28
28
|
};
|
29
29
|
|
@@ -38,10 +38,11 @@ function insertBefore(nodes) {
|
|
38
38
|
this._assertUnremoved();
|
39
39
|
|
40
40
|
nodes = this._verifyNodeList(nodes);
|
41
|
+
const parentPath = this.parentPath;
|
41
42
|
|
42
|
-
if (
|
43
|
-
return
|
44
|
-
} else if (this.isNodeType("Expression") && this.listKey !== "params" && this.listKey !== "arguments" ||
|
43
|
+
if (parentPath.isExpressionStatement() || parentPath.isLabeledStatement() || parentPath.isExportNamedDeclaration() || parentPath.isExportDefaultDeclaration() && this.isDeclaration()) {
|
44
|
+
return parentPath.insertBefore(nodes);
|
45
|
+
} else if (this.isNodeType("Expression") && this.listKey !== "params" && this.listKey !== "arguments" || parentPath.isForStatement() && this.key === "init") {
|
45
46
|
if (this.node) nodes.push(this.node);
|
46
47
|
return this.replaceExpressionWithStatements(nodes);
|
47
48
|
} else if (Array.isArray(this.container)) {
|
@@ -72,11 +73,24 @@ function _containerInsert(from, nodes) {
|
|
72
73
|
|
73
74
|
const contexts = this._getQueueContexts();
|
74
75
|
|
75
|
-
for (
|
76
|
+
for (var _i = 0; _i < paths.length; _i++) {
|
77
|
+
const path = paths[_i];
|
76
78
|
path.setScope();
|
77
79
|
path.debug("Inserted.");
|
78
80
|
|
79
|
-
for (
|
81
|
+
for (var _iterator = contexts, _isArray = Array.isArray(_iterator), _i2 = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
82
|
+
var _ref;
|
83
|
+
|
84
|
+
if (_isArray) {
|
85
|
+
if (_i2 >= _iterator.length) break;
|
86
|
+
_ref = _iterator[_i2++];
|
87
|
+
} else {
|
88
|
+
_i2 = _iterator.next();
|
89
|
+
if (_i2.done) break;
|
90
|
+
_ref = _i2.value;
|
91
|
+
}
|
92
|
+
|
93
|
+
const context = _ref;
|
80
94
|
context.maybeQueue(path, true);
|
81
95
|
}
|
82
96
|
}
|
@@ -96,12 +110,22 @@ function insertAfter(nodes) {
|
|
96
110
|
this._assertUnremoved();
|
97
111
|
|
98
112
|
nodes = this._verifyNodeList(nodes);
|
113
|
+
const parentPath = this.parentPath;
|
99
114
|
|
100
|
-
if (
|
101
|
-
return
|
102
|
-
} else if (this.isNodeType("Expression") ||
|
115
|
+
if (parentPath.isExpressionStatement() || parentPath.isLabeledStatement() || parentPath.isExportNamedDeclaration() || parentPath.isExportDefaultDeclaration() && this.isDeclaration()) {
|
116
|
+
return parentPath.insertAfter(nodes);
|
117
|
+
} else if (this.isNodeType("Expression") || parentPath.isForStatement() && this.key === "init") {
|
103
118
|
if (this.node) {
|
104
|
-
|
119
|
+
let scope = this.scope;
|
120
|
+
|
121
|
+
if (parentPath.isMethod({
|
122
|
+
computed: true,
|
123
|
+
key: this.node
|
124
|
+
})) {
|
125
|
+
scope = scope.parent;
|
126
|
+
}
|
127
|
+
|
128
|
+
const temp = scope.generateDeclaredUidIdentifier();
|
105
129
|
nodes.unshift(t().expressionStatement(t().assignmentExpression("=", t().cloneNode(temp), this.node)));
|
106
130
|
nodes.push(t().expressionStatement(t().cloneNode(temp)));
|
107
131
|
}
|
package/lib/path/removal.js
CHANGED
@@ -38,7 +38,10 @@ function _removeFromScope() {
|
|
38
38
|
}
|
39
39
|
|
40
40
|
function _callRemovalHooks() {
|
41
|
-
|
41
|
+
var _arr = _removalHooks.hooks;
|
42
|
+
|
43
|
+
for (var _i = 0; _i < _arr.length; _i++) {
|
44
|
+
const fn = _arr[_i];
|
42
45
|
if (fn(this, this.parentPath)) return true;
|
43
46
|
}
|
44
47
|
}
|
package/lib/path/replacement.js
CHANGED
@@ -13,7 +13,7 @@ exports.replaceInline = replaceInline;
|
|
13
13
|
function _codeFrame() {
|
14
14
|
const data = require("@babel/code-frame");
|
15
15
|
|
16
|
-
_codeFrame = function () {
|
16
|
+
_codeFrame = function _codeFrame() {
|
17
17
|
return data;
|
18
18
|
};
|
19
19
|
|
@@ -27,7 +27,7 @@ var _index2 = _interopRequireDefault(require("./index"));
|
|
27
27
|
function _babylon() {
|
28
28
|
const data = require("babylon");
|
29
29
|
|
30
|
-
_babylon = function () {
|
30
|
+
_babylon = function _babylon() {
|
31
31
|
return data;
|
32
32
|
};
|
33
33
|
|
@@ -37,7 +37,7 @@ function _babylon() {
|
|
37
37
|
function t() {
|
38
38
|
const data = _interopRequireWildcard(require("@babel/types"));
|
39
39
|
|
40
|
-
t = function () {
|
40
|
+
t = function t() {
|
41
41
|
return data;
|
42
42
|
};
|
43
43
|
|
@@ -64,8 +64,11 @@ const hoistVariablesVisitor = {
|
|
64
64
|
}
|
65
65
|
|
66
66
|
const exprs = [];
|
67
|
+
var _arr = path.node.declarations;
|
68
|
+
|
69
|
+
for (var _i = 0; _i < _arr.length; _i++) {
|
70
|
+
const declar = _arr[_i];
|
67
71
|
|
68
|
-
for (const declar of path.node.declarations) {
|
69
72
|
if (declar.init) {
|
70
73
|
exprs.push(t().expressionStatement(t().assignmentExpression("=", declar.id, declar.init)));
|
71
74
|
}
|
@@ -211,7 +214,19 @@ function replaceExpressionWithStatements(nodes) {
|
|
211
214
|
this.traverse(hoistVariablesVisitor);
|
212
215
|
const completionRecords = this.get("callee").getCompletionRecords();
|
213
216
|
|
214
|
-
for (
|
217
|
+
for (var _iterator = completionRecords, _isArray = Array.isArray(_iterator), _i2 = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
218
|
+
var _ref;
|
219
|
+
|
220
|
+
if (_isArray) {
|
221
|
+
if (_i2 >= _iterator.length) break;
|
222
|
+
_ref = _iterator[_i2++];
|
223
|
+
} else {
|
224
|
+
_i2 = _iterator.next();
|
225
|
+
if (_i2.done) break;
|
226
|
+
_ref = _i2.value;
|
227
|
+
}
|
228
|
+
|
229
|
+
const path = _ref;
|
215
230
|
if (!path.isExpressionStatement()) continue;
|
216
231
|
const loop = path.findParent(path => path.isLoop());
|
217
232
|
|
package/lib/scope/index.js
CHANGED
@@ -8,7 +8,7 @@ exports.default = void 0;
|
|
8
8
|
function _includes() {
|
9
9
|
const data = _interopRequireDefault(require("lodash/includes"));
|
10
10
|
|
11
|
-
_includes = function () {
|
11
|
+
_includes = function _includes() {
|
12
12
|
return data;
|
13
13
|
};
|
14
14
|
|
@@ -18,7 +18,7 @@ function _includes() {
|
|
18
18
|
function _repeat() {
|
19
19
|
const data = _interopRequireDefault(require("lodash/repeat"));
|
20
20
|
|
21
|
-
_repeat = function () {
|
21
|
+
_repeat = function _repeat() {
|
22
22
|
return data;
|
23
23
|
};
|
24
24
|
|
@@ -32,7 +32,7 @@ var _index = _interopRequireDefault(require("../index"));
|
|
32
32
|
function _defaults() {
|
33
33
|
const data = _interopRequireDefault(require("lodash/defaults"));
|
34
34
|
|
35
|
-
_defaults = function () {
|
35
|
+
_defaults = function _defaults() {
|
36
36
|
return data;
|
37
37
|
};
|
38
38
|
|
@@ -44,7 +44,7 @@ var _binding = _interopRequireDefault(require("./binding"));
|
|
44
44
|
function _globals() {
|
45
45
|
const data = _interopRequireDefault(require("globals"));
|
46
46
|
|
47
|
-
_globals = function () {
|
47
|
+
_globals = function _globals() {
|
48
48
|
return data;
|
49
49
|
};
|
50
50
|
|
@@ -54,7 +54,7 @@ function _globals() {
|
|
54
54
|
function t() {
|
55
55
|
const data = _interopRequireWildcard(require("@babel/types"));
|
56
56
|
|
57
|
-
t = function () {
|
57
|
+
t = function t() {
|
58
58
|
return data;
|
59
59
|
};
|
60
60
|
|
@@ -72,7 +72,10 @@ function gatherNodeParts(node, parts) {
|
|
72
72
|
if (node.source) {
|
73
73
|
gatherNodeParts(node.source, parts);
|
74
74
|
} else if (node.specifiers && node.specifiers.length) {
|
75
|
-
|
75
|
+
var _arr = node.specifiers;
|
76
|
+
|
77
|
+
for (var _i = 0; _i < _arr.length; _i++) {
|
78
|
+
const specifier = _arr[_i];
|
76
79
|
gatherNodeParts(specifier, parts);
|
77
80
|
}
|
78
81
|
} else if (node.declaration) {
|
@@ -90,15 +93,27 @@ function gatherNodeParts(node, parts) {
|
|
90
93
|
} else if (t().isCallExpression(node)) {
|
91
94
|
gatherNodeParts(node.callee, parts);
|
92
95
|
} else if (t().isObjectExpression(node) || t().isObjectPattern(node)) {
|
93
|
-
|
96
|
+
var _arr2 = node.properties;
|
97
|
+
|
98
|
+
for (var _i2 = 0; _i2 < _arr2.length; _i2++) {
|
99
|
+
const prop = _arr2[_i2];
|
94
100
|
gatherNodeParts(prop.key || prop.argument, parts);
|
95
101
|
}
|
102
|
+
} else if (t().isPrivateName(node)) {
|
103
|
+
gatherNodeParts(node.id, parts);
|
104
|
+
} else if (t().isThisExpression(node)) {
|
105
|
+
parts.push("this");
|
106
|
+
} else if (t().isSuper(node)) {
|
107
|
+
parts.push("super");
|
96
108
|
}
|
97
109
|
}
|
98
110
|
|
99
111
|
const collectorVisitor = {
|
100
112
|
For(path) {
|
101
|
-
|
113
|
+
var _arr3 = t().FOR_INIT_KEYS;
|
114
|
+
|
115
|
+
for (var _i3 = 0; _i3 < _arr3.length; _i3++) {
|
116
|
+
const key = _arr3[_i3];
|
102
117
|
const declar = path.get(key);
|
103
118
|
|
104
119
|
if (declar.isVar()) {
|
@@ -133,10 +148,8 @@ const collectorVisitor = {
|
|
133
148
|
|
134
149
|
ExportDeclaration: {
|
135
150
|
exit(path) {
|
136
|
-
const
|
137
|
-
|
138
|
-
scope
|
139
|
-
} = path;
|
151
|
+
const node = path.node,
|
152
|
+
scope = path.scope;
|
140
153
|
const declar = node.declaration;
|
141
154
|
|
142
155
|
if (t().isClassDeclaration(declar) || t().isFunctionDeclaration(declar)) {
|
@@ -145,7 +158,10 @@ const collectorVisitor = {
|
|
145
158
|
const binding = scope.getBinding(id.name);
|
146
159
|
if (binding) binding.reference(path);
|
147
160
|
} else if (t().isVariableDeclaration(declar)) {
|
148
|
-
|
161
|
+
var _arr4 = declar.declarations;
|
162
|
+
|
163
|
+
for (var _i4 = 0; _i4 < _arr4.length; _i4++) {
|
164
|
+
const decl = _arr4[_i4];
|
149
165
|
const ids = t().getBindingIdentifiers(decl);
|
150
166
|
|
151
167
|
for (const name in ids) {
|
@@ -192,8 +208,11 @@ const collectorVisitor = {
|
|
192
208
|
|
193
209
|
Block(path) {
|
194
210
|
const paths = path.get("body");
|
211
|
+
var _arr5 = paths;
|
212
|
+
|
213
|
+
for (var _i5 = 0; _i5 < _arr5.length; _i5++) {
|
214
|
+
const bodyPath = _arr5[_i5];
|
195
215
|
|
196
|
-
for (const bodyPath of paths) {
|
197
216
|
if (bodyPath.isFunctionDeclaration()) {
|
198
217
|
path.scope.getBlockParent().registerDeclaration(bodyPath);
|
199
218
|
}
|
@@ -205,9 +224,7 @@ let uid = 0;
|
|
205
224
|
|
206
225
|
class Scope {
|
207
226
|
constructor(path) {
|
208
|
-
const
|
209
|
-
node
|
210
|
-
} = path;
|
227
|
+
const node = path.node;
|
211
228
|
|
212
229
|
const cached = _cache.scope.get(node);
|
213
230
|
|
@@ -437,16 +454,20 @@ class Scope {
|
|
437
454
|
this.registerBinding("hoisted", path.get("id"), path);
|
438
455
|
} else if (path.isVariableDeclaration()) {
|
439
456
|
const declarations = path.get("declarations");
|
457
|
+
var _arr6 = declarations;
|
440
458
|
|
441
|
-
for (
|
459
|
+
for (var _i6 = 0; _i6 < _arr6.length; _i6++) {
|
460
|
+
const declar = _arr6[_i6];
|
442
461
|
this.registerBinding(path.node.kind, declar);
|
443
462
|
}
|
444
463
|
} else if (path.isClassDeclaration()) {
|
445
464
|
this.registerBinding("let", path);
|
446
465
|
} else if (path.isImportDeclaration()) {
|
447
466
|
const specifiers = path.get("specifiers");
|
467
|
+
var _arr7 = specifiers;
|
448
468
|
|
449
|
-
for (
|
469
|
+
for (var _i7 = 0; _i7 < _arr7.length; _i7++) {
|
470
|
+
const specifier = _arr7[_i7];
|
450
471
|
this.registerBinding("module", specifier);
|
451
472
|
}
|
452
473
|
} else if (path.isExportDeclaration()) {
|
@@ -483,7 +504,19 @@ class Scope {
|
|
483
504
|
if (path.isVariableDeclaration()) {
|
484
505
|
const declarators = path.get("declarations");
|
485
506
|
|
486
|
-
for (
|
507
|
+
for (var _iterator = declarators, _isArray = Array.isArray(_iterator), _i8 = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
508
|
+
var _ref;
|
509
|
+
|
510
|
+
if (_isArray) {
|
511
|
+
if (_i8 >= _iterator.length) break;
|
512
|
+
_ref = _iterator[_i8++];
|
513
|
+
} else {
|
514
|
+
_i8 = _iterator.next();
|
515
|
+
if (_i8.done) break;
|
516
|
+
_ref = _i8.value;
|
517
|
+
}
|
518
|
+
|
519
|
+
const declar = _ref;
|
487
520
|
this.registerBinding(kind, declar);
|
488
521
|
}
|
489
522
|
|
@@ -494,7 +527,10 @@ class Scope {
|
|
494
527
|
const ids = path.getBindingIdentifiers(true);
|
495
528
|
|
496
529
|
for (const name in ids) {
|
497
|
-
|
530
|
+
var _arr8 = ids[name];
|
531
|
+
|
532
|
+
for (var _i9 = 0; _i9 < _arr8.length; _i9++) {
|
533
|
+
const id = _arr8[_i9];
|
498
534
|
const local = this.getOwnBinding(name);
|
499
535
|
|
500
536
|
if (local) {
|
@@ -565,7 +601,19 @@ class Scope {
|
|
565
601
|
|
566
602
|
return this.isPure(node.body, constantsOnly);
|
567
603
|
} else if (t().isClassBody(node)) {
|
568
|
-
for (
|
604
|
+
for (var _iterator2 = node.body, _isArray2 = Array.isArray(_iterator2), _i10 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
|
605
|
+
var _ref2;
|
606
|
+
|
607
|
+
if (_isArray2) {
|
608
|
+
if (_i10 >= _iterator2.length) break;
|
609
|
+
_ref2 = _iterator2[_i10++];
|
610
|
+
} else {
|
611
|
+
_i10 = _iterator2.next();
|
612
|
+
if (_i10.done) break;
|
613
|
+
_ref2 = _i10.value;
|
614
|
+
}
|
615
|
+
|
616
|
+
const method = _ref2;
|
569
617
|
if (!this.isPure(method, constantsOnly)) return false;
|
570
618
|
}
|
571
619
|
|
@@ -573,13 +621,19 @@ class Scope {
|
|
573
621
|
} else if (t().isBinary(node)) {
|
574
622
|
return this.isPure(node.left, constantsOnly) && this.isPure(node.right, constantsOnly);
|
575
623
|
} else if (t().isArrayExpression(node)) {
|
576
|
-
|
624
|
+
var _arr9 = node.elements;
|
625
|
+
|
626
|
+
for (var _i11 = 0; _i11 < _arr9.length; _i11++) {
|
627
|
+
const elem = _arr9[_i11];
|
577
628
|
if (!this.isPure(elem, constantsOnly)) return false;
|
578
629
|
}
|
579
630
|
|
580
631
|
return true;
|
581
632
|
} else if (t().isObjectExpression(node)) {
|
582
|
-
|
633
|
+
var _arr10 = node.properties;
|
634
|
+
|
635
|
+
for (var _i12 = 0; _i12 < _arr10.length; _i12++) {
|
636
|
+
const prop = _arr10[_i12];
|
583
637
|
if (!this.isPure(prop, constantsOnly)) return false;
|
584
638
|
}
|
585
639
|
|
@@ -588,7 +642,7 @@ class Scope {
|
|
588
642
|
if (node.computed && !this.isPure(node.key, constantsOnly)) return false;
|
589
643
|
if (node.kind === "get" || node.kind === "set") return false;
|
590
644
|
return true;
|
591
|
-
} else if (t().
|
645
|
+
} else if (t().isProperty(node)) {
|
592
646
|
if (node.computed && !this.isPure(node.key, constantsOnly)) return false;
|
593
647
|
return this.isPure(node.value, constantsOnly);
|
594
648
|
} else if (t().isUnaryExpression(node)) {
|
@@ -596,7 +650,10 @@ class Scope {
|
|
596
650
|
} else if (t().isTaggedTemplateExpression(node)) {
|
597
651
|
return t().matchesPattern(node.tag, "String.raw") && !this.hasBinding("String", true) && this.isPure(node.quasi, constantsOnly);
|
598
652
|
} else if (t().isTemplateLiteral(node)) {
|
599
|
-
|
653
|
+
var _arr11 = node.expressions;
|
654
|
+
|
655
|
+
for (var _i13 = 0; _i13 < _arr11.length; _i13++) {
|
656
|
+
const expression = _arr11[_i13];
|
600
657
|
if (!this.isPure(expression, constantsOnly)) return false;
|
601
658
|
}
|
602
659
|
|
@@ -641,7 +698,10 @@ class Scope {
|
|
641
698
|
this.data = Object.create(null);
|
642
699
|
|
643
700
|
if (path.isLoop()) {
|
644
|
-
|
701
|
+
var _arr12 = t().FOR_INIT_KEYS;
|
702
|
+
|
703
|
+
for (var _i14 = 0; _i14 < _arr12.length; _i14++) {
|
704
|
+
const key = _arr12[_i14];
|
645
705
|
const node = path.get(key);
|
646
706
|
if (node.isBlockScoped()) this.registerBinding(node.node.kind, node);
|
647
707
|
}
|
@@ -662,7 +722,19 @@ class Scope {
|
|
662
722
|
if (path.isFunction()) {
|
663
723
|
const params = path.get("params");
|
664
724
|
|
665
|
-
for (
|
725
|
+
for (var _iterator3 = params, _isArray3 = Array.isArray(_iterator3), _i15 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
|
726
|
+
var _ref3;
|
727
|
+
|
728
|
+
if (_isArray3) {
|
729
|
+
if (_i15 >= _iterator3.length) break;
|
730
|
+
_ref3 = _iterator3[_i15++];
|
731
|
+
} else {
|
732
|
+
_i15 = _iterator3.next();
|
733
|
+
if (_i15.done) break;
|
734
|
+
_ref3 = _i15.value;
|
735
|
+
}
|
736
|
+
|
737
|
+
const param = _ref3;
|
666
738
|
this.registerBinding("param", param);
|
667
739
|
}
|
668
740
|
}
|
@@ -682,7 +754,19 @@ class Scope {
|
|
682
754
|
path.traverse(collectorVisitor, state);
|
683
755
|
this.crawling = false;
|
684
756
|
|
685
|
-
for (
|
757
|
+
for (var _iterator4 = state.assignments, _isArray4 = Array.isArray(_iterator4), _i16 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) {
|
758
|
+
var _ref4;
|
759
|
+
|
760
|
+
if (_isArray4) {
|
761
|
+
if (_i16 >= _iterator4.length) break;
|
762
|
+
_ref4 = _iterator4[_i16++];
|
763
|
+
} else {
|
764
|
+
_i16 = _iterator4.next();
|
765
|
+
if (_i16.done) break;
|
766
|
+
_ref4 = _i16.value;
|
767
|
+
}
|
768
|
+
|
769
|
+
const path = _ref4;
|
686
770
|
const ids = path.getBindingIdentifiers();
|
687
771
|
let programParent;
|
688
772
|
|
@@ -695,7 +779,19 @@ class Scope {
|
|
695
779
|
path.scope.registerConstantViolation(path);
|
696
780
|
}
|
697
781
|
|
698
|
-
for (
|
782
|
+
for (var _iterator5 = state.references, _isArray5 = Array.isArray(_iterator5), _i17 = 0, _iterator5 = _isArray5 ? _iterator5 : _iterator5[Symbol.iterator]();;) {
|
783
|
+
var _ref5;
|
784
|
+
|
785
|
+
if (_isArray5) {
|
786
|
+
if (_i17 >= _iterator5.length) break;
|
787
|
+
_ref5 = _iterator5[_i17++];
|
788
|
+
} else {
|
789
|
+
_i17 = _iterator5.next();
|
790
|
+
if (_i17.done) break;
|
791
|
+
_ref5 = _i17.value;
|
792
|
+
}
|
793
|
+
|
794
|
+
const ref = _ref5;
|
699
795
|
const binding = ref.scope.getBinding(ref.node.name);
|
700
796
|
|
701
797
|
if (binding) {
|
@@ -705,7 +801,19 @@ class Scope {
|
|
705
801
|
}
|
706
802
|
}
|
707
803
|
|
708
|
-
for (
|
804
|
+
for (var _iterator6 = state.constantViolations, _isArray6 = Array.isArray(_iterator6), _i18 = 0, _iterator6 = _isArray6 ? _iterator6 : _iterator6[Symbol.iterator]();;) {
|
805
|
+
var _ref6;
|
806
|
+
|
807
|
+
if (_isArray6) {
|
808
|
+
if (_i18 >= _iterator6.length) break;
|
809
|
+
_ref6 = _iterator6[_i18++];
|
810
|
+
} else {
|
811
|
+
_i18 = _iterator6.next();
|
812
|
+
if (_i18.done) break;
|
813
|
+
_ref6 = _i18.value;
|
814
|
+
}
|
815
|
+
|
816
|
+
const path = _ref6;
|
709
817
|
path.scope.registerConstantViolation(path);
|
710
818
|
}
|
711
819
|
}
|
@@ -735,7 +843,10 @@ class Scope {
|
|
735
843
|
if (!declarPath) {
|
736
844
|
const declar = t().variableDeclaration(kind, []);
|
737
845
|
declar._blockHoist = blockHoist;
|
738
|
-
|
846
|
+
|
847
|
+
var _path$unshiftContaine = path.unshiftContainer("body", [declar]);
|
848
|
+
|
849
|
+
declarPath = _path$unshiftContaine[0];
|
739
850
|
if (!unique) path.setData(dataKey, declarPath);
|
740
851
|
}
|
741
852
|
|
@@ -794,8 +905,10 @@ class Scope {
|
|
794
905
|
|
795
906
|
getAllBindingsOfKind() {
|
796
907
|
const ids = Object.create(null);
|
908
|
+
var _arr13 = arguments;
|
797
909
|
|
798
|
-
for (
|
910
|
+
for (var _i19 = 0; _i19 < _arr13.length; _i19++) {
|
911
|
+
const kind = _arr13[_i19];
|
799
912
|
let scope = this;
|
800
913
|
|
801
914
|
do {
|
package/lib/scope/lib/renamer.js
CHANGED
@@ -10,7 +10,7 @@ var _binding = _interopRequireDefault(require("../binding"));
|
|
10
10
|
function _helperSplitExportDeclaration() {
|
11
11
|
const data = _interopRequireDefault(require("@babel/helper-split-export-declaration"));
|
12
12
|
|
13
|
-
_helperSplitExportDeclaration = function () {
|
13
|
+
_helperSplitExportDeclaration = function _helperSplitExportDeclaration() {
|
14
14
|
return data;
|
15
15
|
};
|
16
16
|
|
@@ -20,7 +20,7 @@ function _helperSplitExportDeclaration() {
|
|
20
20
|
function t() {
|
21
21
|
const data = _interopRequireWildcard(require("@babel/types"));
|
22
22
|
|
23
|
-
t = function () {
|
23
|
+
t = function t() {
|
24
24
|
return data;
|
25
25
|
};
|
26
26
|
|
@@ -98,15 +98,11 @@ class Renamer {
|
|
98
98
|
}
|
99
99
|
|
100
100
|
rename(block) {
|
101
|
-
const
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
const {
|
107
|
-
scope,
|
108
|
-
path
|
109
|
-
} = binding;
|
101
|
+
const binding = this.binding,
|
102
|
+
oldName = this.oldName,
|
103
|
+
newName = this.newName;
|
104
|
+
const scope = binding.scope,
|
105
|
+
path = binding.path;
|
110
106
|
const parentDeclar = path.find(path => path.isDeclaration() || path.isFunctionExpression() || path.isClassExpression());
|
111
107
|
|
112
108
|
if (parentDeclar) {
|