@babel/traverse 7.6.2 → 7.6.3
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 +2 -10
- package/lib/index.js +7 -23
- package/lib/path/ancestry.js +2 -10
- package/lib/path/comments.js +3 -11
- package/lib/path/conversion.js +37 -53
- package/lib/path/family.js +4 -12
- package/lib/path/index.js +9 -33
- package/lib/path/inference/index.js +18 -26
- package/lib/path/inference/inferer-reference.js +8 -16
- package/lib/path/inference/inferers.js +37 -45
- package/lib/path/introspection.js +10 -26
- package/lib/path/lib/hoister.js +17 -14
- package/lib/path/lib/virtual-types.js +20 -28
- package/lib/path/modification.js +6 -14
- package/lib/path/replacement.js +25 -49
- package/lib/scope/index.js +59 -99
- package/lib/scope/lib/renamer.js +8 -24
- package/lib/visitors.js +6 -22
- package/package.json +5 -5
package/lib/path/replacement.js
CHANGED
@@ -10,39 +10,15 @@ exports._replaceWith = _replaceWith;
|
|
10
10
|
exports.replaceExpressionWithStatements = replaceExpressionWithStatements;
|
11
11
|
exports.replaceInline = replaceInline;
|
12
12
|
|
13
|
-
|
14
|
-
const data = require("@babel/code-frame");
|
15
|
-
|
16
|
-
_codeFrame = function () {
|
17
|
-
return data;
|
18
|
-
};
|
19
|
-
|
20
|
-
return data;
|
21
|
-
}
|
13
|
+
var _codeFrame = require("@babel/code-frame");
|
22
14
|
|
23
15
|
var _index = _interopRequireDefault(require("../index"));
|
24
16
|
|
25
17
|
var _index2 = _interopRequireDefault(require("./index"));
|
26
18
|
|
27
|
-
|
28
|
-
const data = require("@babel/parser");
|
19
|
+
var _parser = require("@babel/parser");
|
29
20
|
|
30
|
-
|
31
|
-
return data;
|
32
|
-
};
|
33
|
-
|
34
|
-
return data;
|
35
|
-
}
|
36
|
-
|
37
|
-
function t() {
|
38
|
-
const data = _interopRequireWildcard(require("@babel/types"));
|
39
|
-
|
40
|
-
t = function () {
|
41
|
-
return data;
|
42
|
-
};
|
43
|
-
|
44
|
-
return data;
|
45
|
-
}
|
21
|
+
var t = _interopRequireWildcard(require("@babel/types"));
|
46
22
|
|
47
23
|
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
48
24
|
|
@@ -69,7 +45,7 @@ const hoistVariablesVisitor = {
|
|
69
45
|
|
70
46
|
for (const declar of path.node.declarations) {
|
71
47
|
if (declar.init) {
|
72
|
-
exprs.push(t
|
48
|
+
exprs.push(t.expressionStatement(t.assignmentExpression("=", declar.id, declar.init)));
|
73
49
|
}
|
74
50
|
}
|
75
51
|
|
@@ -81,8 +57,8 @@ const hoistVariablesVisitor = {
|
|
81
57
|
function replaceWithMultiple(nodes) {
|
82
58
|
this.resync();
|
83
59
|
nodes = this._verifyNodeList(nodes);
|
84
|
-
t
|
85
|
-
t
|
60
|
+
t.inheritLeadingComments(nodes[0], this.node);
|
61
|
+
t.inheritTrailingComments(nodes[nodes.length - 1], this.node);
|
86
62
|
this.node = this.container[this.key] = null;
|
87
63
|
const paths = this.insertAfter(nodes);
|
88
64
|
|
@@ -100,12 +76,12 @@ function replaceWithSourceString(replacement) {
|
|
100
76
|
|
101
77
|
try {
|
102
78
|
replacement = `(${replacement})`;
|
103
|
-
replacement = (0, _parser
|
79
|
+
replacement = (0, _parser.parse)(replacement);
|
104
80
|
} catch (err) {
|
105
81
|
const loc = err.loc;
|
106
82
|
|
107
83
|
if (loc) {
|
108
|
-
err.message += " - make sure this is an expression.\n" + (0, _codeFrame
|
84
|
+
err.message += " - make sure this is an expression.\n" + (0, _codeFrame.codeFrameColumns)(replacement, {
|
109
85
|
start: {
|
110
86
|
line: loc.line,
|
111
87
|
column: loc.column + 1
|
@@ -143,7 +119,7 @@ function replaceWith(replacement) {
|
|
143
119
|
return [this];
|
144
120
|
}
|
145
121
|
|
146
|
-
if (this.isProgram() && !t
|
122
|
+
if (this.isProgram() && !t.isProgram(replacement)) {
|
147
123
|
throw new Error("You can only replace a Program root node with another Program node");
|
148
124
|
}
|
149
125
|
|
@@ -157,14 +133,14 @@ function replaceWith(replacement) {
|
|
157
133
|
|
158
134
|
let nodePath = "";
|
159
135
|
|
160
|
-
if (this.isNodeType("Statement") && t
|
136
|
+
if (this.isNodeType("Statement") && t.isExpression(replacement)) {
|
161
137
|
if (!this.canHaveVariableDeclarationOrExpression() && !this.canSwapBetweenExpressionAndStatement(replacement) && !this.parentPath.isExportDefaultDeclaration()) {
|
162
|
-
replacement = t
|
138
|
+
replacement = t.expressionStatement(replacement);
|
163
139
|
nodePath = "expression";
|
164
140
|
}
|
165
141
|
}
|
166
142
|
|
167
|
-
if (this.isNodeType("Expression") && t
|
143
|
+
if (this.isNodeType("Expression") && t.isStatement(replacement)) {
|
168
144
|
if (!this.canHaveVariableDeclarationOrExpression() && !this.canSwapBetweenExpressionAndStatement(replacement)) {
|
169
145
|
return this.replaceExpressionWithStatements([replacement]);
|
170
146
|
}
|
@@ -173,8 +149,8 @@ function replaceWith(replacement) {
|
|
173
149
|
const oldNode = this.node;
|
174
150
|
|
175
151
|
if (oldNode) {
|
176
|
-
t
|
177
|
-
t
|
152
|
+
t.inheritsComments(replacement, oldNode);
|
153
|
+
t.removeComments(oldNode);
|
178
154
|
}
|
179
155
|
|
180
156
|
this._replaceWith(replacement);
|
@@ -191,9 +167,9 @@ function _replaceWith(node) {
|
|
191
167
|
}
|
192
168
|
|
193
169
|
if (this.inList) {
|
194
|
-
t
|
170
|
+
t.validate(this.parent, this.key, [node]);
|
195
171
|
} else {
|
196
|
-
t
|
172
|
+
t.validate(this.parent, this.key, node);
|
197
173
|
}
|
198
174
|
|
199
175
|
this.debug(`Replace with ${node && node.type}`);
|
@@ -202,7 +178,7 @@ function _replaceWith(node) {
|
|
202
178
|
|
203
179
|
function replaceExpressionWithStatements(nodes) {
|
204
180
|
this.resync();
|
205
|
-
const toSequenceExpression = t
|
181
|
+
const toSequenceExpression = t.toSequenceExpression(nodes, this.scope);
|
206
182
|
|
207
183
|
if (toSequenceExpression) {
|
208
184
|
return this.replaceWith(toSequenceExpression)[0].get("expressions");
|
@@ -210,8 +186,8 @@ function replaceExpressionWithStatements(nodes) {
|
|
210
186
|
|
211
187
|
const functionParent = this.getFunctionParent();
|
212
188
|
const isParentAsync = functionParent && functionParent.is("async");
|
213
|
-
const container = t
|
214
|
-
this.replaceWith(t
|
189
|
+
const container = t.arrowFunctionExpression([], t.blockStatement(nodes));
|
190
|
+
this.replaceWith(t.callExpression(container, []));
|
215
191
|
this.traverse(hoistVariablesVisitor);
|
216
192
|
const completionRecords = this.get("callee").getCompletionRecords();
|
217
193
|
|
@@ -225,24 +201,24 @@ function replaceExpressionWithStatements(nodes) {
|
|
225
201
|
if (!uid) {
|
226
202
|
const callee = this.get("callee");
|
227
203
|
uid = callee.scope.generateDeclaredUidIdentifier("ret");
|
228
|
-
callee.get("body").pushContainer("body", t
|
204
|
+
callee.get("body").pushContainer("body", t.returnStatement(t.cloneNode(uid)));
|
229
205
|
loop.setData("expressionReplacementReturnUid", uid);
|
230
206
|
} else {
|
231
|
-
uid = t
|
207
|
+
uid = t.identifier(uid.name);
|
232
208
|
}
|
233
209
|
|
234
|
-
path.get("expression").replaceWith(t
|
210
|
+
path.get("expression").replaceWith(t.assignmentExpression("=", t.cloneNode(uid), path.node.expression));
|
235
211
|
} else {
|
236
|
-
path.replaceWith(t
|
212
|
+
path.replaceWith(t.returnStatement(path.node.expression));
|
237
213
|
}
|
238
214
|
}
|
239
215
|
|
240
216
|
const callee = this.get("callee");
|
241
217
|
callee.arrowFunctionToExpression();
|
242
218
|
|
243
|
-
if (isParentAsync && _index.default.hasType(this.get("callee.body").node, "AwaitExpression", t
|
219
|
+
if (isParentAsync && _index.default.hasType(this.get("callee.body").node, "AwaitExpression", t.FUNCTION_TYPES)) {
|
244
220
|
callee.set("async", true);
|
245
|
-
this.replaceWith(t
|
221
|
+
this.replaceWith(t.awaitExpression(this.node));
|
246
222
|
}
|
247
223
|
|
248
224
|
return callee.get("body.body");
|
package/lib/scope/index.js
CHANGED
@@ -5,61 +5,21 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.default = void 0;
|
7
7
|
|
8
|
-
|
9
|
-
const data = _interopRequireDefault(require("lodash/includes"));
|
8
|
+
var _includes = _interopRequireDefault(require("lodash/includes"));
|
10
9
|
|
11
|
-
|
12
|
-
return data;
|
13
|
-
};
|
14
|
-
|
15
|
-
return data;
|
16
|
-
}
|
17
|
-
|
18
|
-
function _repeat() {
|
19
|
-
const data = _interopRequireDefault(require("lodash/repeat"));
|
20
|
-
|
21
|
-
_repeat = function () {
|
22
|
-
return data;
|
23
|
-
};
|
24
|
-
|
25
|
-
return data;
|
26
|
-
}
|
10
|
+
var _repeat = _interopRequireDefault(require("lodash/repeat"));
|
27
11
|
|
28
12
|
var _renamer = _interopRequireDefault(require("./lib/renamer"));
|
29
13
|
|
30
14
|
var _index = _interopRequireDefault(require("../index"));
|
31
15
|
|
32
|
-
|
33
|
-
const data = _interopRequireDefault(require("lodash/defaults"));
|
34
|
-
|
35
|
-
_defaults = function () {
|
36
|
-
return data;
|
37
|
-
};
|
38
|
-
|
39
|
-
return data;
|
40
|
-
}
|
16
|
+
var _defaults = _interopRequireDefault(require("lodash/defaults"));
|
41
17
|
|
42
18
|
var _binding = _interopRequireDefault(require("./binding"));
|
43
19
|
|
44
|
-
|
45
|
-
const data = _interopRequireDefault(require("globals"));
|
46
|
-
|
47
|
-
_globals = function () {
|
48
|
-
return data;
|
49
|
-
};
|
50
|
-
|
51
|
-
return data;
|
52
|
-
}
|
20
|
+
var _globals = _interopRequireDefault(require("globals"));
|
53
21
|
|
54
|
-
|
55
|
-
const data = _interopRequireWildcard(require("@babel/types"));
|
56
|
-
|
57
|
-
t = function () {
|
58
|
-
return data;
|
59
|
-
};
|
60
|
-
|
61
|
-
return data;
|
62
|
-
}
|
22
|
+
var t = _interopRequireWildcard(require("@babel/types"));
|
63
23
|
|
64
24
|
var _cache = require("../cache");
|
65
25
|
|
@@ -70,7 +30,7 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
|
|
70
30
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
71
31
|
|
72
32
|
function gatherNodeParts(node, parts) {
|
73
|
-
if (t
|
33
|
+
if (t.isModuleDeclaration(node)) {
|
74
34
|
if (node.source) {
|
75
35
|
gatherNodeParts(node.source, parts);
|
76
36
|
} else if (node.specifiers && node.specifiers.length) {
|
@@ -80,33 +40,33 @@ function gatherNodeParts(node, parts) {
|
|
80
40
|
} else if (node.declaration) {
|
81
41
|
gatherNodeParts(node.declaration, parts);
|
82
42
|
}
|
83
|
-
} else if (t
|
43
|
+
} else if (t.isModuleSpecifier(node)) {
|
84
44
|
gatherNodeParts(node.local, parts);
|
85
|
-
} else if (t
|
45
|
+
} else if (t.isMemberExpression(node)) {
|
86
46
|
gatherNodeParts(node.object, parts);
|
87
47
|
gatherNodeParts(node.property, parts);
|
88
|
-
} else if (t
|
48
|
+
} else if (t.isIdentifier(node)) {
|
89
49
|
parts.push(node.name);
|
90
|
-
} else if (t
|
50
|
+
} else if (t.isLiteral(node)) {
|
91
51
|
parts.push(node.value);
|
92
|
-
} else if (t
|
52
|
+
} else if (t.isCallExpression(node)) {
|
93
53
|
gatherNodeParts(node.callee, parts);
|
94
|
-
} else if (t
|
54
|
+
} else if (t.isObjectExpression(node) || t.isObjectPattern(node)) {
|
95
55
|
for (const prop of node.properties) {
|
96
56
|
gatherNodeParts(prop.key || prop.argument, parts);
|
97
57
|
}
|
98
|
-
} else if (t
|
58
|
+
} else if (t.isPrivateName(node)) {
|
99
59
|
gatherNodeParts(node.id, parts);
|
100
|
-
} else if (t
|
60
|
+
} else if (t.isThisExpression(node)) {
|
101
61
|
parts.push("this");
|
102
|
-
} else if (t
|
62
|
+
} else if (t.isSuper(node)) {
|
103
63
|
parts.push("super");
|
104
64
|
}
|
105
65
|
}
|
106
66
|
|
107
67
|
const collectorVisitor = {
|
108
68
|
For(path) {
|
109
|
-
for (const key of t
|
69
|
+
for (const key of t.FOR_INIT_KEYS) {
|
110
70
|
const declar = path.get(key);
|
111
71
|
|
112
72
|
if (declar.isVar()) {
|
@@ -147,14 +107,14 @@ const collectorVisitor = {
|
|
147
107
|
} = path;
|
148
108
|
const declar = node.declaration;
|
149
109
|
|
150
|
-
if (t
|
110
|
+
if (t.isClassDeclaration(declar) || t.isFunctionDeclaration(declar)) {
|
151
111
|
const id = declar.id;
|
152
112
|
if (!id) return;
|
153
113
|
const binding = scope.getBinding(id.name);
|
154
114
|
if (binding) binding.reference(path);
|
155
|
-
} else if (t
|
115
|
+
} else if (t.isVariableDeclaration(declar)) {
|
156
116
|
for (const decl of declar.declarations) {
|
157
|
-
for (const name of Object.keys(t
|
117
|
+
for (const name of Object.keys(t.getBindingIdentifiers(decl))) {
|
158
118
|
const binding = scope.getBinding(name);
|
159
119
|
if (binding) binding.reference(path);
|
160
120
|
}
|
@@ -251,15 +211,15 @@ class Scope {
|
|
251
211
|
this.push({
|
252
212
|
id
|
253
213
|
});
|
254
|
-
return t
|
214
|
+
return t.cloneNode(id);
|
255
215
|
}
|
256
216
|
|
257
217
|
generateUidIdentifier(name) {
|
258
|
-
return t
|
218
|
+
return t.identifier(this.generateUid(name));
|
259
219
|
}
|
260
220
|
|
261
221
|
generateUid(name = "temp") {
|
262
|
-
name = t
|
222
|
+
name = t.toIdentifier(name).replace(/^_+/, "").replace(/[0-9]+$/g, "");
|
263
223
|
let uid;
|
264
224
|
let i = 0;
|
265
225
|
|
@@ -283,11 +243,11 @@ class Scope {
|
|
283
243
|
generateUidBasedOnNode(parent, defaultName) {
|
284
244
|
let node = parent;
|
285
245
|
|
286
|
-
if (t
|
246
|
+
if (t.isAssignmentExpression(parent)) {
|
287
247
|
node = parent.left;
|
288
|
-
} else if (t
|
248
|
+
} else if (t.isVariableDeclarator(parent)) {
|
289
249
|
node = parent.id;
|
290
|
-
} else if (t
|
250
|
+
} else if (t.isObjectProperty(node) || t.isObjectMethod(node)) {
|
291
251
|
node = node.key;
|
292
252
|
}
|
293
253
|
|
@@ -299,15 +259,15 @@ class Scope {
|
|
299
259
|
}
|
300
260
|
|
301
261
|
generateUidIdentifierBasedOnNode(parent, defaultName) {
|
302
|
-
return t
|
262
|
+
return t.identifier(this.generateUidBasedOnNode(parent, defaultName));
|
303
263
|
}
|
304
264
|
|
305
265
|
isStatic(node) {
|
306
|
-
if (t
|
266
|
+
if (t.isThisExpression(node) || t.isSuper(node)) {
|
307
267
|
return true;
|
308
268
|
}
|
309
269
|
|
310
|
-
if (t
|
270
|
+
if (t.isIdentifier(node)) {
|
311
271
|
const binding = this.getBinding(node.name);
|
312
272
|
|
313
273
|
if (binding) {
|
@@ -330,7 +290,7 @@ class Scope {
|
|
330
290
|
this.push({
|
331
291
|
id
|
332
292
|
});
|
333
|
-
return t
|
293
|
+
return t.cloneNode(id);
|
334
294
|
}
|
335
295
|
|
336
296
|
return id;
|
@@ -364,7 +324,7 @@ class Scope {
|
|
364
324
|
}
|
365
325
|
|
366
326
|
dump() {
|
367
|
-
const sep = (0, _repeat
|
327
|
+
const sep = (0, _repeat.default)("-", 60);
|
368
328
|
console.log(sep);
|
369
329
|
let scope = this;
|
370
330
|
|
@@ -386,7 +346,7 @@ class Scope {
|
|
386
346
|
}
|
387
347
|
|
388
348
|
toArray(node, i) {
|
389
|
-
if (t
|
349
|
+
if (t.isIdentifier(node)) {
|
390
350
|
const binding = this.getBinding(node.name);
|
391
351
|
|
392
352
|
if (binding && binding.constant && binding.path.isGenericType("Array")) {
|
@@ -394,14 +354,14 @@ class Scope {
|
|
394
354
|
}
|
395
355
|
}
|
396
356
|
|
397
|
-
if (t
|
357
|
+
if (t.isArrayExpression(node)) {
|
398
358
|
return node;
|
399
359
|
}
|
400
360
|
|
401
|
-
if (t
|
361
|
+
if (t.isIdentifier(node, {
|
402
362
|
name: "arguments"
|
403
363
|
})) {
|
404
|
-
return t
|
364
|
+
return t.callExpression(t.memberExpression(t.memberExpression(t.memberExpression(t.identifier("Array"), t.identifier("prototype")), t.identifier("slice")), t.identifier("call")), [node]);
|
405
365
|
}
|
406
366
|
|
407
367
|
let helperName;
|
@@ -410,13 +370,13 @@ class Scope {
|
|
410
370
|
if (i === true) {
|
411
371
|
helperName = "toConsumableArray";
|
412
372
|
} else if (i) {
|
413
|
-
args.push(t
|
373
|
+
args.push(t.numericLiteral(i));
|
414
374
|
helperName = "slicedToArray";
|
415
375
|
} else {
|
416
376
|
helperName = "toArray";
|
417
377
|
}
|
418
378
|
|
419
|
-
return t
|
379
|
+
return t.callExpression(this.hub.addHelper(helperName), args);
|
420
380
|
}
|
421
381
|
|
422
382
|
hasLabel(name) {
|
@@ -462,7 +422,7 @@ class Scope {
|
|
462
422
|
}
|
463
423
|
|
464
424
|
buildUndefinedNode() {
|
465
|
-
return t
|
425
|
+
return t.unaryExpression("void", t.numericLiteral(0), true);
|
466
426
|
}
|
467
427
|
|
468
428
|
registerConstantViolation(path) {
|
@@ -550,56 +510,56 @@ class Scope {
|
|
550
510
|
}
|
551
511
|
|
552
512
|
isPure(node, constantsOnly) {
|
553
|
-
if (t
|
513
|
+
if (t.isIdentifier(node)) {
|
554
514
|
const binding = this.getBinding(node.name);
|
555
515
|
if (!binding) return false;
|
556
516
|
if (constantsOnly) return binding.constant;
|
557
517
|
return true;
|
558
|
-
} else if (t
|
518
|
+
} else if (t.isClass(node)) {
|
559
519
|
if (node.superClass && !this.isPure(node.superClass, constantsOnly)) {
|
560
520
|
return false;
|
561
521
|
}
|
562
522
|
|
563
523
|
return this.isPure(node.body, constantsOnly);
|
564
|
-
} else if (t
|
524
|
+
} else if (t.isClassBody(node)) {
|
565
525
|
for (const method of node.body) {
|
566
526
|
if (!this.isPure(method, constantsOnly)) return false;
|
567
527
|
}
|
568
528
|
|
569
529
|
return true;
|
570
|
-
} else if (t
|
530
|
+
} else if (t.isBinary(node)) {
|
571
531
|
return this.isPure(node.left, constantsOnly) && this.isPure(node.right, constantsOnly);
|
572
|
-
} else if (t
|
532
|
+
} else if (t.isArrayExpression(node)) {
|
573
533
|
for (const elem of node.elements) {
|
574
534
|
if (!this.isPure(elem, constantsOnly)) return false;
|
575
535
|
}
|
576
536
|
|
577
537
|
return true;
|
578
|
-
} else if (t
|
538
|
+
} else if (t.isObjectExpression(node)) {
|
579
539
|
for (const prop of node.properties) {
|
580
540
|
if (!this.isPure(prop, constantsOnly)) return false;
|
581
541
|
}
|
582
542
|
|
583
543
|
return true;
|
584
|
-
} else if (t
|
544
|
+
} else if (t.isClassMethod(node)) {
|
585
545
|
if (node.computed && !this.isPure(node.key, constantsOnly)) return false;
|
586
546
|
if (node.kind === "get" || node.kind === "set") return false;
|
587
547
|
return true;
|
588
|
-
} else if (t
|
548
|
+
} else if (t.isProperty(node)) {
|
589
549
|
if (node.computed && !this.isPure(node.key, constantsOnly)) return false;
|
590
550
|
return this.isPure(node.value, constantsOnly);
|
591
|
-
} else if (t
|
551
|
+
} else if (t.isUnaryExpression(node)) {
|
592
552
|
return this.isPure(node.argument, constantsOnly);
|
593
|
-
} else if (t
|
594
|
-
return t
|
595
|
-
} else if (t
|
553
|
+
} else if (t.isTaggedTemplateExpression(node)) {
|
554
|
+
return t.matchesPattern(node.tag, "String.raw") && !this.hasBinding("String", true) && this.isPure(node.quasi, constantsOnly);
|
555
|
+
} else if (t.isTemplateLiteral(node)) {
|
596
556
|
for (const expression of node.expressions) {
|
597
557
|
if (!this.isPure(expression, constantsOnly)) return false;
|
598
558
|
}
|
599
559
|
|
600
560
|
return true;
|
601
561
|
} else {
|
602
|
-
return t
|
562
|
+
return t.isPureish(node);
|
603
563
|
}
|
604
564
|
}
|
605
565
|
|
@@ -638,20 +598,20 @@ class Scope {
|
|
638
598
|
this.data = Object.create(null);
|
639
599
|
|
640
600
|
if (path.isLoop()) {
|
641
|
-
for (const key of t
|
601
|
+
for (const key of t.FOR_INIT_KEYS) {
|
642
602
|
const node = path.get(key);
|
643
603
|
if (node.isBlockScoped()) this.registerBinding(node.node.kind, node);
|
644
604
|
}
|
645
605
|
}
|
646
606
|
|
647
607
|
if (path.isFunctionExpression() && path.has("id")) {
|
648
|
-
if (!path.get("id").node[t
|
608
|
+
if (!path.get("id").node[t.NOT_LOCAL_BINDING]) {
|
649
609
|
this.registerBinding("local", path.get("id"), path);
|
650
610
|
}
|
651
611
|
}
|
652
612
|
|
653
613
|
if (path.isClassExpression() && path.has("id")) {
|
654
|
-
if (!path.get("id").node[t
|
614
|
+
if (!path.get("id").node[t.NOT_LOCAL_BINDING]) {
|
655
615
|
this.registerBinding("local", path);
|
656
616
|
}
|
657
617
|
}
|
@@ -730,13 +690,13 @@ class Scope {
|
|
730
690
|
let declarPath = !unique && path.getData(dataKey);
|
731
691
|
|
732
692
|
if (!declarPath) {
|
733
|
-
const declar = t
|
693
|
+
const declar = t.variableDeclaration(kind, []);
|
734
694
|
declar._blockHoist = blockHoist;
|
735
695
|
[declarPath] = path.unshiftContainer("body", [declar]);
|
736
696
|
if (!unique) path.setData(dataKey, declarPath);
|
737
697
|
}
|
738
698
|
|
739
|
-
const declarator = t
|
699
|
+
const declarator = t.variableDeclarator(opts.id, opts.init);
|
740
700
|
declarPath.node.declarations.push(declarator);
|
741
701
|
this.registerBinding(kind, declarPath.get("declarations").pop());
|
742
702
|
}
|
@@ -782,7 +742,7 @@ class Scope {
|
|
782
742
|
let scope = this;
|
783
743
|
|
784
744
|
do {
|
785
|
-
(0, _defaults
|
745
|
+
(0, _defaults.default)(ids, scope.bindings);
|
786
746
|
scope = scope.parent;
|
787
747
|
} while (scope);
|
788
748
|
|
@@ -844,8 +804,8 @@ class Scope {
|
|
844
804
|
if (this.hasOwnBinding(name)) return true;
|
845
805
|
if (this.parentHasBinding(name, noGlobals)) return true;
|
846
806
|
if (this.hasUid(name)) return true;
|
847
|
-
if (!noGlobals && (0, _includes
|
848
|
-
if (!noGlobals && (0, _includes
|
807
|
+
if (!noGlobals && (0, _includes.default)(Scope.globals, name)) return true;
|
808
|
+
if (!noGlobals && (0, _includes.default)(Scope.contextVariables, name)) return true;
|
849
809
|
return false;
|
850
810
|
}
|
851
811
|
|
@@ -886,5 +846,5 @@ class Scope {
|
|
886
846
|
}
|
887
847
|
|
888
848
|
exports.default = Scope;
|
889
|
-
Scope.globals = Object.keys(_globals
|
849
|
+
Scope.globals = Object.keys(_globals.default.builtin);
|
890
850
|
Scope.contextVariables = ["arguments", "undefined", "Infinity", "NaN"];
|
package/lib/scope/lib/renamer.js
CHANGED
@@ -7,25 +7,9 @@ exports.default = void 0;
|
|
7
7
|
|
8
8
|
var _binding = _interopRequireDefault(require("../binding"));
|
9
9
|
|
10
|
-
|
11
|
-
const data = _interopRequireDefault(require("@babel/helper-split-export-declaration"));
|
10
|
+
var _helperSplitExportDeclaration = _interopRequireDefault(require("@babel/helper-split-export-declaration"));
|
12
11
|
|
13
|
-
|
14
|
-
return data;
|
15
|
-
};
|
16
|
-
|
17
|
-
return data;
|
18
|
-
}
|
19
|
-
|
20
|
-
function t() {
|
21
|
-
const data = _interopRequireWildcard(require("@babel/types"));
|
22
|
-
|
23
|
-
t = function () {
|
24
|
-
return data;
|
25
|
-
};
|
26
|
-
|
27
|
-
return data;
|
28
|
-
}
|
12
|
+
var t = _interopRequireWildcard(require("@babel/types"));
|
29
13
|
|
30
14
|
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
31
15
|
|
@@ -76,27 +60,27 @@ class Renamer {
|
|
76
60
|
return;
|
77
61
|
}
|
78
62
|
|
79
|
-
(0, _helperSplitExportDeclaration
|
63
|
+
(0, _helperSplitExportDeclaration.default)(maybeExportDeclar);
|
80
64
|
}
|
81
65
|
|
82
66
|
maybeConvertFromClassFunctionDeclaration(path) {
|
83
67
|
return;
|
84
68
|
if (!path.isFunctionDeclaration() && !path.isClassDeclaration()) return;
|
85
69
|
if (this.binding.kind !== "hoisted") return;
|
86
|
-
path.node.id = t
|
70
|
+
path.node.id = t.identifier(this.oldName);
|
87
71
|
path.node._blockHoist = 3;
|
88
|
-
path.replaceWith(t
|
72
|
+
path.replaceWith(t.variableDeclaration("let", [t.variableDeclarator(t.identifier(this.newName), t.toExpression(path.node))]));
|
89
73
|
}
|
90
74
|
|
91
75
|
maybeConvertFromClassFunctionExpression(path) {
|
92
76
|
return;
|
93
77
|
if (!path.isFunctionExpression() && !path.isClassExpression()) return;
|
94
78
|
if (this.binding.kind !== "local") return;
|
95
|
-
path.node.id = t
|
79
|
+
path.node.id = t.identifier(this.oldName);
|
96
80
|
this.binding.scope.parent.push({
|
97
|
-
id: t
|
81
|
+
id: t.identifier(this.newName)
|
98
82
|
});
|
99
|
-
path.replaceWith(t
|
83
|
+
path.replaceWith(t.assignmentExpression("=", t.identifier(this.newName), path.node));
|
100
84
|
}
|
101
85
|
|
102
86
|
rename(block) {
|
package/lib/visitors.js
CHANGED
@@ -9,25 +9,9 @@ exports.merge = merge;
|
|
9
9
|
|
10
10
|
var virtualTypes = _interopRequireWildcard(require("./path/lib/virtual-types"));
|
11
11
|
|
12
|
-
|
13
|
-
const data = _interopRequireWildcard(require("@babel/types"));
|
12
|
+
var t = _interopRequireWildcard(require("@babel/types"));
|
14
13
|
|
15
|
-
|
16
|
-
return data;
|
17
|
-
};
|
18
|
-
|
19
|
-
return data;
|
20
|
-
}
|
21
|
-
|
22
|
-
function _clone() {
|
23
|
-
const data = _interopRequireDefault(require("lodash/clone"));
|
24
|
-
|
25
|
-
_clone = function () {
|
26
|
-
return data;
|
27
|
-
};
|
28
|
-
|
29
|
-
return data;
|
30
|
-
}
|
14
|
+
var _clone = _interopRequireDefault(require("lodash/clone"));
|
31
15
|
|
32
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
33
17
|
|
@@ -84,8 +68,8 @@ function explode(visitor) {
|
|
84
68
|
for (const nodeType of Object.keys(visitor)) {
|
85
69
|
if (shouldIgnoreKey(nodeType)) continue;
|
86
70
|
const fns = visitor[nodeType];
|
87
|
-
let aliases = t
|
88
|
-
const deprecratedKey = t
|
71
|
+
let aliases = t.FLIPPED_ALIAS_KEYS[nodeType];
|
72
|
+
const deprecratedKey = t.DEPRECATED_KEYS[nodeType];
|
89
73
|
|
90
74
|
if (deprecratedKey) {
|
91
75
|
console.trace(`Visitor defined for ${nodeType} but it has been renamed to ${deprecratedKey}`);
|
@@ -101,7 +85,7 @@ function explode(visitor) {
|
|
101
85
|
if (existing) {
|
102
86
|
mergePair(existing, fns);
|
103
87
|
} else {
|
104
|
-
visitor[alias] = (0, _clone
|
88
|
+
visitor[alias] = (0, _clone.default)(fns);
|
105
89
|
}
|
106
90
|
}
|
107
91
|
}
|
@@ -128,7 +112,7 @@ function verify(visitor) {
|
|
128
112
|
|
129
113
|
if (shouldIgnoreKey(nodeType)) continue;
|
130
114
|
|
131
|
-
if (t
|
115
|
+
if (t.TYPES.indexOf(nodeType) < 0) {
|
132
116
|
throw new Error(`You gave us a visitor for the node type ${nodeType} but it's not a valid type`);
|
133
117
|
}
|
134
118
|
|