@babel/traverse 8.0.0-alpha.1 → 8.0.0-alpha.10
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.
- package/lib/index.d.ts +3588 -0
- package/lib/index.js +551 -498
- package/lib/index.js.map +1 -1
- package/package.json +17 -13
- package/lib/cache.js +0 -14
- package/lib/cache.js.map +0 -1
- package/lib/context.js +0 -108
- package/lib/context.js.map +0 -1
- package/lib/hub.js +0 -12
- package/lib/hub.js.map +0 -1
- package/lib/path/ancestry.js +0 -126
- package/lib/path/ancestry.js.map +0 -1
- package/lib/path/comments.js +0 -46
- package/lib/path/comments.js.map +0 -1
- package/lib/path/context.js +0 -194
- package/lib/path/context.js.map +0 -1
- package/lib/path/conversion.js +0 -453
- package/lib/path/conversion.js.map +0 -1
- package/lib/path/evaluation.js +0 -333
- package/lib/path/evaluation.js.map +0 -1
- package/lib/path/family.js +0 -322
- package/lib/path/family.js.map +0 -1
- package/lib/path/index.js +0 -185
- package/lib/path/index.js.map +0 -1
- package/lib/path/inference/index.js +0 -137
- package/lib/path/inference/index.js.map +0 -1
- package/lib/path/inference/inferer-reference.js +0 -145
- package/lib/path/inference/inferer-reference.js.map +0 -1
- package/lib/path/inference/inferers.js +0 -172
- package/lib/path/inference/inferers.js.map +0 -1
- package/lib/path/inference/util.js +0 -20
- package/lib/path/inference/util.js.map +0 -1
- package/lib/path/introspection.js +0 -360
- package/lib/path/introspection.js.map +0 -1
- package/lib/path/lib/hoister.js +0 -164
- package/lib/path/lib/hoister.js.map +0 -1
- package/lib/path/lib/removal-hooks.js +0 -31
- package/lib/path/lib/removal-hooks.js.map +0 -1
- package/lib/path/lib/virtual-types-validator.js +0 -138
- package/lib/path/lib/virtual-types-validator.js.map +0 -1
- package/lib/path/lib/virtual-types.js +0 -20
- package/lib/path/lib/virtual-types.js.map +0 -1
- package/lib/path/modification.js +0 -209
- package/lib/path/modification.js.map +0 -1
- package/lib/path/removal.js +0 -46
- package/lib/path/removal.js.map +0 -1
- package/lib/path/replacement.js +0 -192
- package/lib/path/replacement.js.map +0 -1
- package/lib/scope/binding.js +0 -78
- package/lib/scope/binding.js.map +0 -1
- package/lib/scope/index.js +0 -870
- package/lib/scope/index.js.map +0 -1
- package/lib/scope/lib/renamer.js +0 -105
- package/lib/scope/lib/renamer.js.map +0 -1
- package/lib/traverse-node.js +0 -19
- package/lib/traverse-node.js.map +0 -1
- package/lib/types.js +0 -3
- package/lib/types.js.map +0 -1
- package/lib/visitors.js +0 -210
- package/lib/visitors.js.map +0 -1
package/lib/index.js
CHANGED
@@ -30,24 +30,174 @@ const ForAwaitStatement = ["ForOfStatement"];
|
|
30
30
|
|
31
31
|
var virtualTypes = /*#__PURE__*/Object.freeze({
|
32
32
|
__proto__: null,
|
33
|
-
ReferencedIdentifier: ReferencedIdentifier,
|
34
|
-
ReferencedMemberExpression: ReferencedMemberExpression,
|
35
33
|
BindingIdentifier: BindingIdentifier,
|
36
|
-
Statement: Statement,
|
37
|
-
Expression: Expression,
|
38
|
-
Scope: Scope$1,
|
39
|
-
Referenced: Referenced,
|
40
34
|
BlockScoped: BlockScoped,
|
41
|
-
|
42
|
-
|
35
|
+
ExistentialTypeParam: ExistentialTypeParam,
|
36
|
+
Expression: Expression,
|
37
|
+
Flow: Flow,
|
38
|
+
ForAwaitStatement: ForAwaitStatement,
|
43
39
|
Generated: Generated,
|
40
|
+
NumericLiteralTypeAnnotation: NumericLiteralTypeAnnotation,
|
44
41
|
Pure: Pure,
|
45
|
-
|
42
|
+
Referenced: Referenced,
|
43
|
+
ReferencedIdentifier: ReferencedIdentifier,
|
44
|
+
ReferencedMemberExpression: ReferencedMemberExpression,
|
46
45
|
RestProperty: RestProperty,
|
46
|
+
Scope: Scope$1,
|
47
47
|
SpreadProperty: SpreadProperty,
|
48
|
-
|
49
|
-
|
50
|
-
|
48
|
+
Statement: Statement,
|
49
|
+
User: User,
|
50
|
+
Var: Var
|
51
|
+
});
|
52
|
+
|
53
|
+
const {
|
54
|
+
isBinding,
|
55
|
+
isBlockScoped: nodeIsBlockScoped,
|
56
|
+
isExportDeclaration: isExportDeclaration$1,
|
57
|
+
isExpression: nodeIsExpression,
|
58
|
+
isFlow: nodeIsFlow,
|
59
|
+
isForStatement,
|
60
|
+
isForXStatement,
|
61
|
+
isIdentifier: isIdentifier$6,
|
62
|
+
isImportDeclaration: isImportDeclaration$1,
|
63
|
+
isImportSpecifier,
|
64
|
+
isJSXIdentifier,
|
65
|
+
isJSXMemberExpression,
|
66
|
+
isMemberExpression: isMemberExpression$1,
|
67
|
+
isRestElement: nodeIsRestElement,
|
68
|
+
isReferenced: nodeIsReferenced,
|
69
|
+
isScope: nodeIsScope,
|
70
|
+
isStatement: nodeIsStatement,
|
71
|
+
isVar: nodeIsVar,
|
72
|
+
isVariableDeclaration: isVariableDeclaration$2,
|
73
|
+
react: react$1,
|
74
|
+
isForOfStatement
|
75
|
+
} = _t;
|
76
|
+
const {
|
77
|
+
isCompatTag
|
78
|
+
} = react$1;
|
79
|
+
function isReferencedIdentifier(opts) {
|
80
|
+
const {
|
81
|
+
node,
|
82
|
+
parent
|
83
|
+
} = this;
|
84
|
+
if (!isIdentifier$6(node, opts) && !isJSXMemberExpression(parent, opts)) {
|
85
|
+
if (isJSXIdentifier(node, opts)) {
|
86
|
+
if (isCompatTag(node.name)) return false;
|
87
|
+
} else {
|
88
|
+
return false;
|
89
|
+
}
|
90
|
+
}
|
91
|
+
return nodeIsReferenced(node, parent, this.parentPath.parent);
|
92
|
+
}
|
93
|
+
function isReferencedMemberExpression() {
|
94
|
+
const {
|
95
|
+
node,
|
96
|
+
parent
|
97
|
+
} = this;
|
98
|
+
return isMemberExpression$1(node) && nodeIsReferenced(node, parent);
|
99
|
+
}
|
100
|
+
function isBindingIdentifier() {
|
101
|
+
const {
|
102
|
+
node,
|
103
|
+
parent
|
104
|
+
} = this;
|
105
|
+
const grandparent = this.parentPath.parent;
|
106
|
+
return isIdentifier$6(node) && isBinding(node, parent, grandparent);
|
107
|
+
}
|
108
|
+
function isStatement$1() {
|
109
|
+
const {
|
110
|
+
node,
|
111
|
+
parent
|
112
|
+
} = this;
|
113
|
+
if (nodeIsStatement(node)) {
|
114
|
+
if (isVariableDeclaration$2(node)) {
|
115
|
+
if (isForXStatement(parent, {
|
116
|
+
left: node
|
117
|
+
})) return false;
|
118
|
+
if (isForStatement(parent, {
|
119
|
+
init: node
|
120
|
+
})) return false;
|
121
|
+
}
|
122
|
+
return true;
|
123
|
+
} else {
|
124
|
+
return false;
|
125
|
+
}
|
126
|
+
}
|
127
|
+
function isExpression$3() {
|
128
|
+
if (this.isIdentifier()) {
|
129
|
+
return this.isReferencedIdentifier();
|
130
|
+
} else {
|
131
|
+
return nodeIsExpression(this.node);
|
132
|
+
}
|
133
|
+
}
|
134
|
+
function isScope() {
|
135
|
+
return nodeIsScope(this.node, this.parent);
|
136
|
+
}
|
137
|
+
function isReferenced() {
|
138
|
+
return nodeIsReferenced(this.node, this.parent);
|
139
|
+
}
|
140
|
+
function isBlockScoped() {
|
141
|
+
return nodeIsBlockScoped(this.node);
|
142
|
+
}
|
143
|
+
function isVar() {
|
144
|
+
return nodeIsVar(this.node);
|
145
|
+
}
|
146
|
+
function isUser() {
|
147
|
+
return this.node && !!this.node.loc;
|
148
|
+
}
|
149
|
+
function isGenerated() {
|
150
|
+
return !this.isUser();
|
151
|
+
}
|
152
|
+
function isPure(constantsOnly) {
|
153
|
+
return this.scope.isPure(this.node, constantsOnly);
|
154
|
+
}
|
155
|
+
function isFlow() {
|
156
|
+
const {
|
157
|
+
node
|
158
|
+
} = this;
|
159
|
+
if (nodeIsFlow(node)) {
|
160
|
+
return true;
|
161
|
+
} else if (isImportDeclaration$1(node)) {
|
162
|
+
return node.importKind === "type" || node.importKind === "typeof";
|
163
|
+
} else if (isExportDeclaration$1(node)) {
|
164
|
+
return node.exportKind === "type";
|
165
|
+
} else if (isImportSpecifier(node)) {
|
166
|
+
return node.importKind === "type" || node.importKind === "typeof";
|
167
|
+
} else {
|
168
|
+
return false;
|
169
|
+
}
|
170
|
+
}
|
171
|
+
function isRestProperty() {
|
172
|
+
return nodeIsRestElement(this.node) && this.parentPath?.isObjectPattern();
|
173
|
+
}
|
174
|
+
function isSpreadProperty() {
|
175
|
+
return nodeIsRestElement(this.node) && this.parentPath?.isObjectExpression();
|
176
|
+
}
|
177
|
+
function isForAwaitStatement() {
|
178
|
+
return isForOfStatement(this.node, {
|
179
|
+
await: true
|
180
|
+
});
|
181
|
+
}
|
182
|
+
|
183
|
+
var NodePath_virtual_types_validator = /*#__PURE__*/Object.freeze({
|
184
|
+
__proto__: null,
|
185
|
+
isBindingIdentifier: isBindingIdentifier,
|
186
|
+
isBlockScoped: isBlockScoped,
|
187
|
+
isExpression: isExpression$3,
|
188
|
+
isFlow: isFlow,
|
189
|
+
isForAwaitStatement: isForAwaitStatement,
|
190
|
+
isGenerated: isGenerated,
|
191
|
+
isPure: isPure,
|
192
|
+
isReferenced: isReferenced,
|
193
|
+
isReferencedIdentifier: isReferencedIdentifier,
|
194
|
+
isReferencedMemberExpression: isReferencedMemberExpression,
|
195
|
+
isRestProperty: isRestProperty,
|
196
|
+
isScope: isScope,
|
197
|
+
isSpreadProperty: isSpreadProperty,
|
198
|
+
isStatement: isStatement$1,
|
199
|
+
isUser: isUser,
|
200
|
+
isVar: isVar
|
51
201
|
});
|
52
202
|
|
53
203
|
const {
|
@@ -63,7 +213,7 @@ function isVirtualType(type) {
|
|
63
213
|
function isExplodedVisitor(visitor) {
|
64
214
|
return visitor?._exploded;
|
65
215
|
}
|
66
|
-
function explode(visitor) {
|
216
|
+
function explode$1(visitor) {
|
67
217
|
if (isExplodedVisitor(visitor)) return visitor;
|
68
218
|
visitor._exploded = true;
|
69
219
|
for (const nodeType of Object.keys(visitor)) {
|
@@ -76,7 +226,7 @@ function explode(visitor) {
|
|
76
226
|
visitor[part] = fns;
|
77
227
|
}
|
78
228
|
}
|
79
|
-
verify(visitor);
|
229
|
+
verify$1(visitor);
|
80
230
|
delete visitor.__esModule;
|
81
231
|
ensureEntranceObjects(visitor);
|
82
232
|
ensureCallbackArrays(visitor);
|
@@ -131,7 +281,7 @@ function explode(visitor) {
|
|
131
281
|
}
|
132
282
|
return visitor;
|
133
283
|
}
|
134
|
-
function verify(visitor) {
|
284
|
+
function verify$1(visitor) {
|
135
285
|
if (visitor._verified) return;
|
136
286
|
if (typeof visitor === "function") {
|
137
287
|
throw new Error("You passed `traverse()` a function when it expected a visitor object, " + "are you sure you didn't mean `{ enter: Function }`?");
|
@@ -168,7 +318,7 @@ function validateVisitorMethods(path, val) {
|
|
168
318
|
function merge(visitors, states = [], wrapper) {
|
169
319
|
const mergedVisitor = {};
|
170
320
|
for (let i = 0; i < visitors.length; i++) {
|
171
|
-
const visitor = explode(visitors[i]);
|
321
|
+
const visitor = explode$1(visitors[i]);
|
172
322
|
const state = states[i];
|
173
323
|
let topVisitor = visitor;
|
174
324
|
if (state || wrapper) {
|
@@ -232,8 +382,10 @@ function ensureCallbackArrays(obj) {
|
|
232
382
|
if (obj.exit && !Array.isArray(obj.exit)) obj.exit = [obj.exit];
|
233
383
|
}
|
234
384
|
function wrapCheck(nodeType, fn) {
|
385
|
+
const fnKey = `is${nodeType}`;
|
386
|
+
const validator = NodePath_virtual_types_validator[fnKey];
|
235
387
|
const newFn = function (path) {
|
236
|
-
if (path
|
388
|
+
if (validator.call(path)) {
|
237
389
|
return fn.apply(this, arguments);
|
238
390
|
}
|
239
391
|
};
|
@@ -257,32 +409,45 @@ function mergePair(dest, src) {
|
|
257
409
|
|
258
410
|
var visitors = /*#__PURE__*/Object.freeze({
|
259
411
|
__proto__: null,
|
412
|
+
explode: explode$1,
|
260
413
|
isExplodedVisitor: isExplodedVisitor,
|
261
|
-
|
262
|
-
verify: verify
|
263
|
-
merge: merge
|
414
|
+
merge: merge,
|
415
|
+
verify: verify$1
|
264
416
|
});
|
265
417
|
|
266
|
-
let
|
418
|
+
let pathsCache = new WeakMap();
|
267
419
|
let scope = new WeakMap();
|
268
420
|
function clear() {
|
269
421
|
clearPath();
|
270
422
|
clearScope();
|
271
423
|
}
|
272
424
|
function clearPath() {
|
273
|
-
|
425
|
+
pathsCache = new WeakMap();
|
274
426
|
}
|
275
427
|
function clearScope() {
|
276
428
|
scope = new WeakMap();
|
277
429
|
}
|
430
|
+
const nullHub = Object.freeze({});
|
431
|
+
function getCachedPaths(hub, parent) {
|
432
|
+
return pathsCache.get(hub ?? nullHub)?.get(parent);
|
433
|
+
}
|
434
|
+
function getOrCreateCachedPaths(hub, parent) {
|
435
|
+
let parents = pathsCache.get(hub ?? nullHub);
|
436
|
+
if (!parents) pathsCache.set(hub ?? nullHub, parents = new WeakMap());
|
437
|
+
let paths = parents.get(parent);
|
438
|
+
if (!paths) parents.set(parent, paths = new Map());
|
439
|
+
return paths;
|
440
|
+
}
|
278
441
|
|
279
442
|
var cache = /*#__PURE__*/Object.freeze({
|
280
443
|
__proto__: null,
|
281
|
-
get path () { return path; },
|
282
|
-
get scope () { return scope; },
|
283
444
|
clear: clear,
|
284
445
|
clearPath: clearPath,
|
285
|
-
clearScope: clearScope
|
446
|
+
clearScope: clearScope,
|
447
|
+
getCachedPaths: getCachedPaths,
|
448
|
+
getOrCreateCachedPaths: getOrCreateCachedPaths,
|
449
|
+
get path () { return pathsCache; },
|
450
|
+
get scope () { return scope; }
|
286
451
|
});
|
287
452
|
|
288
453
|
const renameVisitor = {
|
@@ -310,7 +475,6 @@ const renameVisitor = {
|
|
310
475
|
} = node.key;
|
311
476
|
if (node.shorthand && (name === state.oldName || name === state.newName) && scope.getBindingIdentifier(name) === state.binding.identifier) {
|
312
477
|
node.shorthand = false;
|
313
|
-
if (node.extra?.shorthand) node.extra.shorthand = false;
|
314
478
|
}
|
315
479
|
},
|
316
480
|
"AssignmentExpression|Declaration|VariableDeclarator"(path, state) {
|
@@ -369,7 +533,7 @@ class Renamer {
|
|
369
533
|
}
|
370
534
|
}
|
371
535
|
const blockToTraverse = scope.block;
|
372
|
-
traverseNode(blockToTraverse, explode(renameVisitor), scope, this, scope.path, {
|
536
|
+
traverseNode(blockToTraverse, explode$1(renameVisitor), scope, this, scope.path, {
|
373
537
|
discriminant: true
|
374
538
|
});
|
375
539
|
{
|
@@ -399,9 +563,7 @@ class Binding {
|
|
399
563
|
this.scope = scope;
|
400
564
|
this.path = path;
|
401
565
|
this.kind = kind;
|
402
|
-
if ((kind === "var" || kind === "hoisted") && isDeclaredInLoop(path
|
403
|
-
throw new Error("Internal Babel error: unreachable ");
|
404
|
-
})())) {
|
566
|
+
if ((kind === "var" || kind === "hoisted") && isDeclaredInLoop(path)) {
|
405
567
|
this.reassign(path);
|
406
568
|
}
|
407
569
|
this.clearValue();
|
@@ -465,10 +627,11 @@ const {
|
|
465
627
|
NOT_LOCAL_BINDING,
|
466
628
|
callExpression: callExpression$3,
|
467
629
|
cloneNode: cloneNode$3,
|
468
|
-
getBindingIdentifiers: getBindingIdentifiers$
|
630
|
+
getBindingIdentifiers: getBindingIdentifiers$3,
|
469
631
|
identifier: identifier$3,
|
470
632
|
isArrayExpression,
|
471
633
|
isBinary,
|
634
|
+
isCallExpression: isCallExpression$1,
|
472
635
|
isClass,
|
473
636
|
isClassBody,
|
474
637
|
isClassDeclaration,
|
@@ -476,9 +639,10 @@ const {
|
|
476
639
|
isExportDefaultDeclaration,
|
477
640
|
isExportNamedDeclaration: isExportNamedDeclaration$1,
|
478
641
|
isFunctionDeclaration,
|
479
|
-
isIdentifier: isIdentifier$
|
480
|
-
isImportDeclaration
|
642
|
+
isIdentifier: isIdentifier$5,
|
643
|
+
isImportDeclaration,
|
481
644
|
isLiteral: isLiteral$1,
|
645
|
+
isMemberExpression,
|
482
646
|
isMethod,
|
483
647
|
isModuleSpecifier,
|
484
648
|
isNullLiteral,
|
@@ -496,7 +660,6 @@ const {
|
|
496
660
|
memberExpression: memberExpression$1,
|
497
661
|
numericLiteral: numericLiteral$2,
|
498
662
|
toIdentifier,
|
499
|
-
unaryExpression: unaryExpression$2,
|
500
663
|
variableDeclaration: variableDeclaration$1,
|
501
664
|
variableDeclarator: variableDeclarator$1,
|
502
665
|
isRecordExpression,
|
@@ -505,15 +668,16 @@ const {
|
|
505
668
|
isTopicReference,
|
506
669
|
isMetaProperty,
|
507
670
|
isPrivateName,
|
508
|
-
isExportDeclaration
|
671
|
+
isExportDeclaration,
|
672
|
+
buildUndefinedNode: buildUndefinedNode$1
|
509
673
|
} = _t;
|
510
674
|
function gatherNodeParts(node, parts) {
|
511
675
|
switch (node?.type) {
|
512
676
|
default:
|
513
|
-
if (isImportDeclaration
|
514
|
-
if ((isExportAllDeclaration(node) || isExportNamedDeclaration$1(node) || isImportDeclaration
|
677
|
+
if (isImportDeclaration(node) || isExportDeclaration(node)) {
|
678
|
+
if ((isExportAllDeclaration(node) || isExportNamedDeclaration$1(node) || isImportDeclaration(node)) && node.source) {
|
515
679
|
gatherNodeParts(node.source, parts);
|
516
|
-
} else if ((isExportNamedDeclaration$1(node) || isImportDeclaration
|
680
|
+
} else if ((isExportNamedDeclaration$1(node) || isImportDeclaration(node)) && node.specifiers?.length) {
|
517
681
|
for (const e of node.specifiers) gatherNodeParts(e, parts);
|
518
682
|
} else if ((isExportDefaultDeclaration(node) || isExportNamedDeclaration$1(node)) && node.declaration) {
|
519
683
|
gatherNodeParts(node.declaration, parts);
|
@@ -673,7 +837,7 @@ const collectorVisitor = {
|
|
673
837
|
binding?.reference(path);
|
674
838
|
} else if (isVariableDeclaration$1(declar)) {
|
675
839
|
for (const decl of declar.declarations) {
|
676
|
-
for (const name of Object.keys(getBindingIdentifiers$
|
840
|
+
for (const name of Object.keys(getBindingIdentifiers$3(decl))) {
|
677
841
|
const binding = scope.getBinding(name);
|
678
842
|
binding?.reference(path);
|
679
843
|
}
|
@@ -720,8 +884,11 @@ const collectorVisitor = {
|
|
720
884
|
},
|
721
885
|
ClassExpression(path) {
|
722
886
|
if (path.has("id") && !path.get("id").node[NOT_LOCAL_BINDING]) {
|
723
|
-
path.scope.registerBinding("local", path);
|
887
|
+
path.scope.registerBinding("local", path.get("id"), path);
|
724
888
|
}
|
889
|
+
},
|
890
|
+
TSTypeAnnotation(path) {
|
891
|
+
path.skip();
|
725
892
|
}
|
726
893
|
};
|
727
894
|
let uid = 0;
|
@@ -761,7 +928,7 @@ class Scope {
|
|
761
928
|
const shouldSkip = path.key === "key" || path.listKey === "decorators";
|
762
929
|
path = path.parentPath;
|
763
930
|
if (shouldSkip && path.isMethod()) path = path.parentPath;
|
764
|
-
if (path
|
931
|
+
if (path?.isScope()) parent = path;
|
765
932
|
} while (path && !parent);
|
766
933
|
return parent?.scope;
|
767
934
|
}
|
@@ -816,7 +983,7 @@ class Scope {
|
|
816
983
|
if (isThisExpression(node) || isSuper$1(node) || isTopicReference(node)) {
|
817
984
|
return true;
|
818
985
|
}
|
819
|
-
if (isIdentifier$
|
986
|
+
if (isIdentifier$5(node)) {
|
820
987
|
const binding = this.getBinding(node.name);
|
821
988
|
if (binding) {
|
822
989
|
return binding.constant;
|
@@ -883,7 +1050,7 @@ class Scope {
|
|
883
1050
|
console.log(sep);
|
884
1051
|
}
|
885
1052
|
toArray(node, i, arrayLikeIsIterable) {
|
886
|
-
if (isIdentifier$
|
1053
|
+
if (isIdentifier$5(node)) {
|
887
1054
|
const binding = this.getBinding(node.name);
|
888
1055
|
if (binding?.constant && binding.path.isGenericType("Array")) {
|
889
1056
|
return node;
|
@@ -892,7 +1059,7 @@ class Scope {
|
|
892
1059
|
if (isArrayExpression(node)) {
|
893
1060
|
return node;
|
894
1061
|
}
|
895
|
-
if (isIdentifier$
|
1062
|
+
if (isIdentifier$5(node, {
|
896
1063
|
name: "arguments"
|
897
1064
|
})) {
|
898
1065
|
return callExpression$3(memberExpression$1(memberExpression$1(memberExpression$1(identifier$3("Array"), identifier$3("prototype")), identifier$3("slice")), identifier$3("call")), [node]);
|
@@ -955,7 +1122,7 @@ class Scope {
|
|
955
1122
|
}
|
956
1123
|
}
|
957
1124
|
buildUndefinedNode() {
|
958
|
-
return
|
1125
|
+
return buildUndefinedNode$1();
|
959
1126
|
}
|
960
1127
|
registerConstantViolation(path) {
|
961
1128
|
const ids = path.getBindingIdentifiers();
|
@@ -1016,7 +1183,7 @@ class Scope {
|
|
1016
1183
|
return !!this.getProgramParent().references[name];
|
1017
1184
|
}
|
1018
1185
|
isPure(node, constantsOnly) {
|
1019
|
-
if (isIdentifier$
|
1186
|
+
if (isIdentifier$5(node)) {
|
1020
1187
|
const binding = this.getBinding(node.name);
|
1021
1188
|
if (!binding) return false;
|
1022
1189
|
if (constantsOnly) return binding.constant;
|
@@ -1067,13 +1234,23 @@ class Scope {
|
|
1067
1234
|
return true;
|
1068
1235
|
} else if (isUnaryExpression(node)) {
|
1069
1236
|
return this.isPure(node.argument, constantsOnly);
|
1070
|
-
} else if (isTaggedTemplateExpression(node)) {
|
1071
|
-
return matchesPattern$1(node.tag, "String.raw") && !this.hasBinding("String", true) && this.isPure(node.quasi, constantsOnly);
|
1072
1237
|
} else if (isTemplateLiteral(node)) {
|
1073
1238
|
for (const expression of node.expressions) {
|
1074
1239
|
if (!this.isPure(expression, constantsOnly)) return false;
|
1075
1240
|
}
|
1076
1241
|
return true;
|
1242
|
+
} else if (isTaggedTemplateExpression(node)) {
|
1243
|
+
return matchesPattern$1(node.tag, "String.raw") && !this.hasBinding("String", {
|
1244
|
+
noGlobals: true
|
1245
|
+
}) && this.isPure(node.quasi, constantsOnly);
|
1246
|
+
} else if (isMemberExpression(node)) {
|
1247
|
+
return !node.computed && isIdentifier$5(node.object) && node.object.name === "Symbol" && isIdentifier$5(node.property) && node.property.name !== "for" && !this.hasBinding("Symbol", {
|
1248
|
+
noGlobals: true
|
1249
|
+
});
|
1250
|
+
} else if (isCallExpression$1(node)) {
|
1251
|
+
return matchesPattern$1(node.callee, "Symbol.for") && !this.hasBinding("Symbol", {
|
1252
|
+
noGlobals: true
|
1253
|
+
}) && node.arguments.length === 1 && _t.isStringLiteral(node.arguments[0]);
|
1077
1254
|
} else {
|
1078
1255
|
return isPureish(node);
|
1079
1256
|
}
|
@@ -1165,9 +1342,9 @@ class Scope {
|
|
1165
1342
|
kind = "var",
|
1166
1343
|
id
|
1167
1344
|
} = opts;
|
1168
|
-
if (!init && !unique && (kind === "var" || kind === "let") && path.isFunction() && !path.node.name &&
|
1345
|
+
if (!init && !unique && (kind === "var" || kind === "let") && path.isFunction() && !path.node.name && isCallExpression$1(path.parent, {
|
1169
1346
|
callee: path.node
|
1170
|
-
}) && path.parent.arguments.length <= path.node.params.length &&
|
1347
|
+
}) && path.parent.arguments.length <= path.node.params.length && isIdentifier$5(id)) {
|
1171
1348
|
path.pushContainer("params", id);
|
1172
1349
|
path.scope.registerBinding("param", path.get("params")[path.node.params.length - 1]);
|
1173
1350
|
return;
|
@@ -1446,20 +1623,6 @@ function inType(...candidateTypes) {
|
|
1446
1623
|
return false;
|
1447
1624
|
}
|
1448
1625
|
|
1449
|
-
var NodePath_ancestry = /*#__PURE__*/Object.freeze({
|
1450
|
-
__proto__: null,
|
1451
|
-
findParent: findParent,
|
1452
|
-
find: find,
|
1453
|
-
getFunctionParent: getFunctionParent,
|
1454
|
-
getStatementParent: getStatementParent,
|
1455
|
-
getEarliestCommonAncestorFrom: getEarliestCommonAncestorFrom,
|
1456
|
-
getDeepestCommonAncestorFrom: getDeepestCommonAncestorFrom,
|
1457
|
-
getAncestry: getAncestry,
|
1458
|
-
isAncestor: isAncestor,
|
1459
|
-
isDescendant: isDescendant,
|
1460
|
-
inType: inType
|
1461
|
-
});
|
1462
|
-
|
1463
1626
|
const {
|
1464
1627
|
createFlowUnionType,
|
1465
1628
|
createTSUnionType,
|
@@ -1469,10 +1632,10 @@ const {
|
|
1469
1632
|
} = _t;
|
1470
1633
|
function createUnionType(types) {
|
1471
1634
|
{
|
1472
|
-
if (isFlowType(
|
1635
|
+
if (types.every(v => isFlowType(v))) {
|
1473
1636
|
return createFlowUnionType(types);
|
1474
1637
|
}
|
1475
|
-
if (isTSType(
|
1638
|
+
if (types.every(v => isTSType(v))) {
|
1476
1639
|
return createTSUnionType(types);
|
1477
1640
|
}
|
1478
1641
|
}
|
@@ -1638,7 +1801,7 @@ const {
|
|
1638
1801
|
tupleTypeAnnotation,
|
1639
1802
|
unionTypeAnnotation,
|
1640
1803
|
voidTypeAnnotation: voidTypeAnnotation$1,
|
1641
|
-
isIdentifier: isIdentifier$
|
1804
|
+
isIdentifier: isIdentifier$4
|
1642
1805
|
} = _t;
|
1643
1806
|
function VariableDeclarator() {
|
1644
1807
|
if (!this.get("id").isIdentifier()) return;
|
@@ -1753,7 +1916,7 @@ function CallExpression() {
|
|
1753
1916
|
} = this.node;
|
1754
1917
|
if (isObjectKeys(callee)) {
|
1755
1918
|
return arrayTypeAnnotation(stringTypeAnnotation$1());
|
1756
|
-
} else if (isArrayFrom(callee) || isObjectValues(callee) || isIdentifier$
|
1919
|
+
} else if (isArrayFrom(callee) || isObjectValues(callee) || isIdentifier$4(callee, {
|
1757
1920
|
name: "Array"
|
1758
1921
|
})) {
|
1759
1922
|
return arrayTypeAnnotation(anyTypeAnnotation$1());
|
@@ -1789,36 +1952,36 @@ function resolveCall(callee) {
|
|
1789
1952
|
|
1790
1953
|
var inferers = /*#__PURE__*/Object.freeze({
|
1791
1954
|
__proto__: null,
|
1792
|
-
|
1793
|
-
|
1794
|
-
TSAsExpression: TSAsExpression,
|
1795
|
-
TSNonNullExpression: TSNonNullExpression,
|
1796
|
-
NewExpression: NewExpression,
|
1797
|
-
TemplateLiteral: TemplateLiteral,
|
1798
|
-
UnaryExpression: UnaryExpression,
|
1799
|
-
BinaryExpression: BinaryExpression,
|
1800
|
-
LogicalExpression: LogicalExpression,
|
1801
|
-
ConditionalExpression: ConditionalExpression,
|
1802
|
-
SequenceExpression: SequenceExpression,
|
1803
|
-
ParenthesizedExpression: ParenthesizedExpression,
|
1955
|
+
ArrayExpression: ArrayExpression,
|
1956
|
+
ArrowFunctionExpression: Func,
|
1804
1957
|
AssignmentExpression: AssignmentExpression,
|
1805
|
-
|
1806
|
-
StringLiteral: StringLiteral,
|
1807
|
-
NumericLiteral: NumericLiteral,
|
1958
|
+
BinaryExpression: BinaryExpression,
|
1808
1959
|
BooleanLiteral: BooleanLiteral,
|
1960
|
+
CallExpression: CallExpression,
|
1961
|
+
ClassDeclaration: Func,
|
1962
|
+
ClassExpression: Func,
|
1963
|
+
ConditionalExpression: ConditionalExpression,
|
1964
|
+
FunctionDeclaration: Func,
|
1965
|
+
FunctionExpression: Func,
|
1966
|
+
Identifier: infererReference,
|
1967
|
+
LogicalExpression: LogicalExpression,
|
1968
|
+
NewExpression: NewExpression,
|
1809
1969
|
NullLiteral: NullLiteral,
|
1810
|
-
|
1970
|
+
NumericLiteral: NumericLiteral,
|
1811
1971
|
ObjectExpression: ObjectExpression,
|
1812
|
-
|
1972
|
+
ParenthesizedExpression: ParenthesizedExpression,
|
1973
|
+
RegExpLiteral: RegExpLiteral,
|
1813
1974
|
RestElement: RestElement,
|
1814
|
-
|
1815
|
-
|
1816
|
-
|
1817
|
-
|
1818
|
-
ClassDeclaration: Func,
|
1819
|
-
CallExpression: CallExpression,
|
1975
|
+
SequenceExpression: SequenceExpression,
|
1976
|
+
StringLiteral: StringLiteral,
|
1977
|
+
TSAsExpression: TSAsExpression,
|
1978
|
+
TSNonNullExpression: TSNonNullExpression,
|
1820
1979
|
TaggedTemplateExpression: TaggedTemplateExpression,
|
1821
|
-
|
1980
|
+
TemplateLiteral: TemplateLiteral,
|
1981
|
+
TypeCastExpression: TypeCastExpression,
|
1982
|
+
UnaryExpression: UnaryExpression,
|
1983
|
+
UpdateExpression: UpdateExpression,
|
1984
|
+
VariableDeclarator: VariableDeclarator
|
1822
1985
|
});
|
1823
1986
|
|
1824
1987
|
const {
|
@@ -1829,7 +1992,7 @@ const {
|
|
1829
1992
|
isEmptyTypeAnnotation,
|
1830
1993
|
isFlowBaseAnnotation,
|
1831
1994
|
isGenericTypeAnnotation,
|
1832
|
-
isIdentifier: isIdentifier$
|
1995
|
+
isIdentifier: isIdentifier$3,
|
1833
1996
|
isMixedTypeAnnotation,
|
1834
1997
|
isNumberTypeAnnotation,
|
1835
1998
|
isStringTypeAnnotation,
|
@@ -1948,42 +2111,40 @@ function isGenericType(genericName) {
|
|
1948
2111
|
return true;
|
1949
2112
|
}
|
1950
2113
|
}
|
1951
|
-
return isGenericTypeAnnotation(type) && isIdentifier$
|
2114
|
+
return isGenericTypeAnnotation(type) && isIdentifier$3(type.id, {
|
1952
2115
|
name: genericName
|
1953
|
-
}) || isTSTypeReference(type) && isIdentifier$
|
2116
|
+
}) || isTSTypeReference(type) && isIdentifier$3(type.typeName, {
|
1954
2117
|
name: genericName
|
1955
2118
|
});
|
1956
2119
|
}
|
1957
2120
|
|
1958
|
-
var NodePath_inference = /*#__PURE__*/Object.freeze({
|
1959
|
-
__proto__: null,
|
1960
|
-
getTypeAnnotation: getTypeAnnotation,
|
1961
|
-
_getTypeAnnotation: _getTypeAnnotation,
|
1962
|
-
isBaseType: isBaseType,
|
1963
|
-
couldBeBaseType: couldBeBaseType,
|
1964
|
-
baseTypeStrictlyMatches: baseTypeStrictlyMatches,
|
1965
|
-
isGenericType: isGenericType
|
1966
|
-
});
|
1967
|
-
|
1968
2121
|
const {
|
1969
2122
|
FUNCTION_TYPES,
|
1970
2123
|
arrowFunctionExpression: arrowFunctionExpression$2,
|
1971
2124
|
assignmentExpression: assignmentExpression$2,
|
1972
2125
|
awaitExpression,
|
1973
2126
|
blockStatement: blockStatement$2,
|
2127
|
+
buildUndefinedNode,
|
1974
2128
|
callExpression: callExpression$2,
|
1975
2129
|
cloneNode: cloneNode$2,
|
2130
|
+
conditionalExpression: conditionalExpression$1,
|
1976
2131
|
expressionStatement: expressionStatement$2,
|
2132
|
+
getBindingIdentifiers: getBindingIdentifiers$2,
|
1977
2133
|
identifier: identifier$1,
|
1978
2134
|
inheritLeadingComments,
|
1979
2135
|
inheritTrailingComments,
|
1980
2136
|
inheritsComments,
|
1981
|
-
|
2137
|
+
isBlockStatement: isBlockStatement$1,
|
2138
|
+
isEmptyStatement,
|
2139
|
+
isExpression: isExpression$2,
|
2140
|
+
isExpressionStatement,
|
2141
|
+
isIfStatement,
|
1982
2142
|
isProgram,
|
1983
|
-
isStatement
|
2143
|
+
isStatement,
|
2144
|
+
isVariableDeclaration,
|
1984
2145
|
removeComments,
|
1985
2146
|
returnStatement: returnStatement$1,
|
1986
|
-
|
2147
|
+
sequenceExpression: sequenceExpression$1,
|
1987
2148
|
validate: validate$1,
|
1988
2149
|
yieldExpression
|
1989
2150
|
} = _t;
|
@@ -1992,7 +2153,7 @@ function replaceWithMultiple(nodes) {
|
|
1992
2153
|
nodes = this._verifyNodeList(nodes);
|
1993
2154
|
inheritLeadingComments(nodes[0], this.node);
|
1994
2155
|
inheritTrailingComments(nodes[nodes.length - 1], this.node);
|
1995
|
-
|
2156
|
+
getCachedPaths(this.hub, this.parent)?.delete(this.node);
|
1996
2157
|
this.node = this.container[this.key] = null;
|
1997
2158
|
const paths = this.insertAfter(nodes);
|
1998
2159
|
if (this.node) {
|
@@ -2030,7 +2191,7 @@ function replaceWith(replacementPath) {
|
|
2030
2191
|
if (this.removed) {
|
2031
2192
|
throw new Error("You can't replace this node, we've already removed it");
|
2032
2193
|
}
|
2033
|
-
let replacement = replacementPath instanceof
|
2194
|
+
let replacement = replacementPath instanceof NodePath_Final ? replacementPath.node : replacementPath;
|
2034
2195
|
if (!replacement) {
|
2035
2196
|
throw new Error("You passed `path.replaceWith()` a falsy node, use `path.remove()` instead");
|
2036
2197
|
}
|
@@ -2047,13 +2208,13 @@ function replaceWith(replacementPath) {
|
|
2047
2208
|
throw new Error("Don't use `path.replaceWith()` with a source string, use `path.replaceWithSourceString()`");
|
2048
2209
|
}
|
2049
2210
|
let nodePath = "";
|
2050
|
-
if (this.isNodeType("Statement") && isExpression$
|
2211
|
+
if (this.isNodeType("Statement") && isExpression$2(replacement)) {
|
2051
2212
|
if (!this.canHaveVariableDeclarationOrExpression() && !this.canSwapBetweenExpressionAndStatement(replacement) && !this.parentPath.isExportDefaultDeclaration()) {
|
2052
2213
|
replacement = expressionStatement$2(replacement);
|
2053
2214
|
nodePath = "expression";
|
2054
2215
|
}
|
2055
2216
|
}
|
2056
|
-
if (this.isNodeType("Expression") && isStatement
|
2217
|
+
if (this.isNodeType("Expression") && isStatement(replacement)) {
|
2057
2218
|
if (!this.canHaveVariableDeclarationOrExpression() && !this.canSwapBetweenExpressionAndStatement(replacement)) {
|
2058
2219
|
return this.replaceExpressionWithStatements([replacement]);
|
2059
2220
|
}
|
@@ -2079,14 +2240,18 @@ function _replaceWith(node) {
|
|
2079
2240
|
validate$1(this.parent, this.key, node);
|
2080
2241
|
}
|
2081
2242
|
this.debug(`Replace with ${node?.type}`);
|
2082
|
-
|
2243
|
+
getCachedPaths(this.hub, this.parent)?.set(node, this).delete(this.node);
|
2083
2244
|
this.node = this.container[this.key] = node;
|
2084
2245
|
}
|
2085
2246
|
function replaceExpressionWithStatements(nodes) {
|
2086
2247
|
this.resync();
|
2087
|
-
const
|
2088
|
-
|
2089
|
-
|
2248
|
+
const declars = [];
|
2249
|
+
const nodesAsSingleExpression = gatherSequenceExpressions(nodes, declars);
|
2250
|
+
if (nodesAsSingleExpression) {
|
2251
|
+
for (const id of declars) this.scope.push({
|
2252
|
+
id
|
2253
|
+
});
|
2254
|
+
return this.replaceWith(nodesAsSingleExpression)[0].get("expressions");
|
2090
2255
|
}
|
2091
2256
|
const functionParent = this.getFunctionParent();
|
2092
2257
|
const isParentAsync = functionParent?.is("async");
|
@@ -2133,6 +2298,53 @@ function replaceExpressionWithStatements(nodes) {
|
|
2133
2298
|
}
|
2134
2299
|
return newCallee.get("body.body");
|
2135
2300
|
}
|
2301
|
+
function gatherSequenceExpressions(nodes, declars) {
|
2302
|
+
const exprs = [];
|
2303
|
+
let ensureLastUndefined = true;
|
2304
|
+
for (const node of nodes) {
|
2305
|
+
if (!isEmptyStatement(node)) {
|
2306
|
+
ensureLastUndefined = false;
|
2307
|
+
}
|
2308
|
+
if (isExpression$2(node)) {
|
2309
|
+
exprs.push(node);
|
2310
|
+
} else if (isExpressionStatement(node)) {
|
2311
|
+
exprs.push(node.expression);
|
2312
|
+
} else if (isVariableDeclaration(node)) {
|
2313
|
+
if (node.kind !== "var") return;
|
2314
|
+
for (const declar of node.declarations) {
|
2315
|
+
const bindings = getBindingIdentifiers$2(declar);
|
2316
|
+
for (const key of Object.keys(bindings)) {
|
2317
|
+
declars.push(cloneNode$2(bindings[key]));
|
2318
|
+
}
|
2319
|
+
if (declar.init) {
|
2320
|
+
exprs.push(assignmentExpression$2("=", declar.id, declar.init));
|
2321
|
+
}
|
2322
|
+
}
|
2323
|
+
ensureLastUndefined = true;
|
2324
|
+
} else if (isIfStatement(node)) {
|
2325
|
+
const consequent = node.consequent ? gatherSequenceExpressions([node.consequent], declars) : buildUndefinedNode();
|
2326
|
+
const alternate = node.alternate ? gatherSequenceExpressions([node.alternate], declars) : buildUndefinedNode();
|
2327
|
+
if (!consequent || !alternate) return;
|
2328
|
+
exprs.push(conditionalExpression$1(node.test, consequent, alternate));
|
2329
|
+
} else if (isBlockStatement$1(node)) {
|
2330
|
+
const body = gatherSequenceExpressions(node.body, declars);
|
2331
|
+
if (!body) return;
|
2332
|
+
exprs.push(body);
|
2333
|
+
} else if (isEmptyStatement(node)) {
|
2334
|
+
if (nodes.indexOf(node) === 0) {
|
2335
|
+
ensureLastUndefined = true;
|
2336
|
+
}
|
2337
|
+
} else {
|
2338
|
+
return;
|
2339
|
+
}
|
2340
|
+
}
|
2341
|
+
if (ensureLastUndefined) exprs.push(buildUndefinedNode());
|
2342
|
+
if (exprs.length === 1) {
|
2343
|
+
return exprs[0];
|
2344
|
+
} else {
|
2345
|
+
return sequenceExpression$1(exprs);
|
2346
|
+
}
|
2347
|
+
}
|
2136
2348
|
function replaceInline(nodes) {
|
2137
2349
|
this.resync();
|
2138
2350
|
if (Array.isArray(nodes)) {
|
@@ -2149,20 +2361,14 @@ function replaceInline(nodes) {
|
|
2149
2361
|
}
|
2150
2362
|
}
|
2151
2363
|
|
2152
|
-
|
2153
|
-
|
2154
|
-
replaceWithMultiple: replaceWithMultiple,
|
2155
|
-
replaceWithSourceString: replaceWithSourceString,
|
2156
|
-
replaceWith: replaceWith,
|
2157
|
-
_replaceWith: _replaceWith,
|
2158
|
-
replaceExpressionWithStatements: replaceExpressionWithStatements,
|
2159
|
-
replaceInline: replaceInline
|
2160
|
-
});
|
2161
|
-
|
2162
|
-
const VALID_CALLEES = ["String", "Number", "Math"];
|
2364
|
+
const VALID_OBJECT_CALLEES = ["Number", "String", "Math"];
|
2365
|
+
const VALID_IDENTIFIER_CALLEES = ["isFinite", "isNaN", "parseFloat", "parseInt", "decodeURI", "decodeURIComponent", "encodeURI", "encodeURIComponent", "btoa", "atob"];
|
2163
2366
|
const INVALID_METHODS = ["random"];
|
2164
|
-
function
|
2165
|
-
return
|
2367
|
+
function isValidObjectCallee(val) {
|
2368
|
+
return VALID_OBJECT_CALLEES.includes(val);
|
2369
|
+
}
|
2370
|
+
function isValidIdentifierCallee(val) {
|
2371
|
+
return VALID_IDENTIFIER_CALLEES.includes(val);
|
2166
2372
|
}
|
2167
2373
|
function isInvalidMethod(val) {
|
2168
2374
|
return INVALID_METHODS.includes(val);
|
@@ -2437,15 +2643,18 @@ function _evaluate(path, state) {
|
|
2437
2643
|
const callee = path.get("callee");
|
2438
2644
|
let context;
|
2439
2645
|
let func;
|
2440
|
-
if (callee.isIdentifier() && !path.scope.getBinding(callee.node.name) &&
|
2646
|
+
if (callee.isIdentifier() && !path.scope.getBinding(callee.node.name) && (isValidObjectCallee(callee.node.name) || isValidIdentifierCallee(callee.node.name))) {
|
2441
2647
|
func = global[callee.node.name];
|
2442
2648
|
}
|
2443
2649
|
if (callee.isMemberExpression()) {
|
2444
2650
|
const object = callee.get("object");
|
2445
2651
|
const property = callee.get("property");
|
2446
|
-
if (object.isIdentifier() && property.isIdentifier() &&
|
2652
|
+
if (object.isIdentifier() && property.isIdentifier() && isValidObjectCallee(object.node.name) && !isInvalidMethod(property.node.name)) {
|
2447
2653
|
context = global[object.node.name];
|
2448
|
-
|
2654
|
+
const key = property.node.name;
|
2655
|
+
if (Object.hasOwn(context, key)) {
|
2656
|
+
func = context[key];
|
2657
|
+
}
|
2449
2658
|
}
|
2450
2659
|
if (object.isLiteral() && property.isIdentifier()) {
|
2451
2660
|
const type = typeof object.node.value;
|
@@ -2491,12 +2700,6 @@ function evaluate() {
|
|
2491
2700
|
};
|
2492
2701
|
}
|
2493
2702
|
|
2494
|
-
var NodePath_evaluation = /*#__PURE__*/Object.freeze({
|
2495
|
-
__proto__: null,
|
2496
|
-
evaluateTruthy: evaluateTruthy,
|
2497
|
-
evaluate: evaluate
|
2498
|
-
});
|
2499
|
-
|
2500
2703
|
const {
|
2501
2704
|
arrowFunctionExpression: arrowFunctionExpression$1,
|
2502
2705
|
assignmentExpression: assignmentExpression$1,
|
@@ -2506,7 +2709,7 @@ const {
|
|
2506
2709
|
conditionalExpression,
|
2507
2710
|
expressionStatement: expressionStatement$1,
|
2508
2711
|
identifier,
|
2509
|
-
isIdentifier: isIdentifier$
|
2712
|
+
isIdentifier: isIdentifier$2,
|
2510
2713
|
jsxIdentifier,
|
2511
2714
|
logicalExpression,
|
2512
2715
|
LOGICAL_OPERATORS,
|
@@ -2534,7 +2737,7 @@ function toComputedKey() {
|
|
2534
2737
|
throw new ReferenceError("todo");
|
2535
2738
|
}
|
2536
2739
|
if (!this.node.computed) {
|
2537
|
-
if (isIdentifier$
|
2740
|
+
if (isIdentifier$2(key)) key = stringLiteral(key.name);
|
2538
2741
|
}
|
2539
2742
|
return key;
|
2540
2743
|
}
|
@@ -2944,20 +3147,12 @@ function getScopeInformation(fnPath) {
|
|
2944
3147
|
};
|
2945
3148
|
}
|
2946
3149
|
|
2947
|
-
var NodePath_conversion = /*#__PURE__*/Object.freeze({
|
2948
|
-
__proto__: null,
|
2949
|
-
toComputedKey: toComputedKey,
|
2950
|
-
ensureBlock: ensureBlock,
|
2951
|
-
unwrapFunctionEnvironment: unwrapFunctionEnvironment,
|
2952
|
-
arrowFunctionToExpression: arrowFunctionToExpression
|
2953
|
-
});
|
2954
|
-
|
2955
3150
|
const {
|
2956
3151
|
STATEMENT_OR_BLOCK_KEYS,
|
2957
3152
|
VISITOR_KEYS: VISITOR_KEYS$3,
|
2958
3153
|
isBlockStatement,
|
2959
|
-
isExpression: isExpression$
|
2960
|
-
isIdentifier: isIdentifier$
|
3154
|
+
isExpression: isExpression$1,
|
3155
|
+
isIdentifier: isIdentifier$1,
|
2961
3156
|
isLiteral,
|
2962
3157
|
isStringLiteral,
|
2963
3158
|
isType,
|
@@ -2967,7 +3162,7 @@ function matchesPattern(pattern, allowPartial) {
|
|
2967
3162
|
return _matchesPattern(this.node, pattern, allowPartial);
|
2968
3163
|
}
|
2969
3164
|
function has(key) {
|
2970
|
-
const val = this.node
|
3165
|
+
const val = this.node?.[key];
|
2971
3166
|
if (val && Array.isArray(val)) {
|
2972
3167
|
return !!val.length;
|
2973
3168
|
} else {
|
@@ -2997,7 +3192,7 @@ function canSwapBetweenExpressionAndStatement(replacement) {
|
|
2997
3192
|
if (this.isExpression()) {
|
2998
3193
|
return isBlockStatement(replacement);
|
2999
3194
|
} else if (this.isBlockStatement()) {
|
3000
|
-
return isExpression$
|
3195
|
+
return isExpression$1(replacement);
|
3001
3196
|
}
|
3002
3197
|
return false;
|
3003
3198
|
}
|
@@ -3052,7 +3247,7 @@ function referencesImport(moduleSource, importName) {
|
|
3052
3247
|
if (path.isImportNamespaceSpecifier() && importName === "*") {
|
3053
3248
|
return true;
|
3054
3249
|
}
|
3055
|
-
if (path.isImportSpecifier() && isIdentifier$
|
3250
|
+
if (path.isImportSpecifier() && isIdentifier$1(path.node.imported, {
|
3056
3251
|
name: importName
|
3057
3252
|
})) {
|
3058
3253
|
return true;
|
@@ -3281,6 +3476,18 @@ function isConstantExpression() {
|
|
3281
3476
|
} = this.node;
|
3282
3477
|
return operator !== "in" && operator !== "instanceof" && this.get("left").isConstantExpression() && this.get("right").isConstantExpression();
|
3283
3478
|
}
|
3479
|
+
if (this.isMemberExpression()) {
|
3480
|
+
return !this.node.computed && this.get("object").isIdentifier({
|
3481
|
+
name: "Symbol"
|
3482
|
+
}) && !this.scope.hasBinding("Symbol", {
|
3483
|
+
noGlobals: true
|
3484
|
+
});
|
3485
|
+
}
|
3486
|
+
if (this.isCallExpression()) {
|
3487
|
+
return this.node.arguments.length === 1 && this.get("callee").matchesPattern("Symbol.for") && !this.scope.hasBinding("Symbol", {
|
3488
|
+
noGlobals: true
|
3489
|
+
}) && this.get("arguments")[0].isStringLiteral();
|
3490
|
+
}
|
3284
3491
|
return false;
|
3285
3492
|
}
|
3286
3493
|
function isInStrictMode() {
|
@@ -3310,29 +3517,6 @@ function isInStrictMode() {
|
|
3310
3517
|
return !!strictParent;
|
3311
3518
|
}
|
3312
3519
|
|
3313
|
-
var NodePath_introspection = /*#__PURE__*/Object.freeze({
|
3314
|
-
__proto__: null,
|
3315
|
-
matchesPattern: matchesPattern,
|
3316
|
-
has: has,
|
3317
|
-
isStatic: isStatic,
|
3318
|
-
is: is,
|
3319
|
-
isnt: isnt,
|
3320
|
-
equals: equals,
|
3321
|
-
isNodeType: isNodeType,
|
3322
|
-
canHaveVariableDeclarationOrExpression: canHaveVariableDeclarationOrExpression,
|
3323
|
-
canSwapBetweenExpressionAndStatement: canSwapBetweenExpressionAndStatement,
|
3324
|
-
isCompletionRecord: isCompletionRecord,
|
3325
|
-
isStatementOrBlock: isStatementOrBlock,
|
3326
|
-
referencesImport: referencesImport,
|
3327
|
-
getSource: getSource,
|
3328
|
-
willIMaybeExecuteBefore: willIMaybeExecuteBefore,
|
3329
|
-
_guessExecutionStatusRelativeTo: _guessExecutionStatusRelativeTo,
|
3330
|
-
resolve: resolve,
|
3331
|
-
_resolve: _resolve,
|
3332
|
-
isConstantExpression: isConstantExpression,
|
3333
|
-
isInStrictMode: isInStrictMode
|
3334
|
-
});
|
3335
|
-
|
3336
3520
|
function call(key) {
|
3337
3521
|
const opts = this.opts;
|
3338
3522
|
this.debug(key);
|
@@ -3523,31 +3707,6 @@ function _getQueueContexts() {
|
|
3523
3707
|
return contexts;
|
3524
3708
|
}
|
3525
3709
|
|
3526
|
-
var NodePath_context = /*#__PURE__*/Object.freeze({
|
3527
|
-
__proto__: null,
|
3528
|
-
call: call,
|
3529
|
-
_call: _call,
|
3530
|
-
isDenylisted: isDenylisted,
|
3531
|
-
isBlacklisted: isDenylisted,
|
3532
|
-
visit: visit,
|
3533
|
-
skip: skip,
|
3534
|
-
skipKey: skipKey,
|
3535
|
-
stop: stop,
|
3536
|
-
setScope: setScope,
|
3537
|
-
setContext: setContext,
|
3538
|
-
resync: resync,
|
3539
|
-
_resyncParent: _resyncParent,
|
3540
|
-
_resyncKey: _resyncKey,
|
3541
|
-
_resyncList: _resyncList,
|
3542
|
-
_resyncRemoved: _resyncRemoved,
|
3543
|
-
popContext: popContext,
|
3544
|
-
pushContext: pushContext,
|
3545
|
-
setup: setup,
|
3546
|
-
setKey: setKey,
|
3547
|
-
requeue: requeue,
|
3548
|
-
_getQueueContexts: _getQueueContexts
|
3549
|
-
});
|
3550
|
-
|
3551
3710
|
const hooks = [function (self, parent) {
|
3552
3711
|
const removeParent = self.key === "test" && (parent.isWhile() || parent.isSwitchCase()) || self.key === "declaration" && parent.isExportDeclaration() || self.key === "body" && parent.isLabeledStatement() || self.listKey === "declarations" && parent.isVariableDeclaration() && parent.node.declarations.length === 1 || self.key === "expression" && parent.isExpressionStatement();
|
3553
3712
|
if (removeParent) {
|
@@ -3578,6 +3737,9 @@ const hooks = [function (self, parent) {
|
|
3578
3737
|
}
|
3579
3738
|
}];
|
3580
3739
|
|
3740
|
+
const {
|
3741
|
+
getBindingIdentifiers: getBindingIdentifiers$1
|
3742
|
+
} = _t;
|
3581
3743
|
function remove() {
|
3582
3744
|
this._assertUnremoved();
|
3583
3745
|
this.resync();
|
@@ -3593,12 +3755,14 @@ function remove() {
|
|
3593
3755
|
this._markRemoved();
|
3594
3756
|
}
|
3595
3757
|
function _removeFromScope() {
|
3596
|
-
const bindings = this.
|
3758
|
+
const bindings = getBindingIdentifiers$1(this.node, false, false, true);
|
3597
3759
|
Object.keys(bindings).forEach(name => this.scope.removeBinding(name));
|
3598
3760
|
}
|
3599
3761
|
function _callRemovalHooks() {
|
3600
|
-
|
3601
|
-
|
3762
|
+
if (this.parentPath) {
|
3763
|
+
for (const fn of hooks) {
|
3764
|
+
if (fn(this, this.parentPath)) return true;
|
3765
|
+
}
|
3602
3766
|
}
|
3603
3767
|
}
|
3604
3768
|
function _remove() {
|
@@ -3611,7 +3775,9 @@ function _remove() {
|
|
3611
3775
|
}
|
3612
3776
|
function _markRemoved() {
|
3613
3777
|
this._traverseFlags |= SHOULD_SKIP | REMOVED;
|
3614
|
-
if (this.parent)
|
3778
|
+
if (this.parent) {
|
3779
|
+
getCachedPaths(this.hub, this.parent).delete(this.node);
|
3780
|
+
}
|
3615
3781
|
this.node = null;
|
3616
3782
|
}
|
3617
3783
|
function _assertUnremoved() {
|
@@ -3620,18 +3786,8 @@ function _assertUnremoved() {
|
|
3620
3786
|
}
|
3621
3787
|
}
|
3622
3788
|
|
3623
|
-
var NodePath_removal = /*#__PURE__*/Object.freeze({
|
3624
|
-
__proto__: null,
|
3625
|
-
remove: remove,
|
3626
|
-
_removeFromScope: _removeFromScope,
|
3627
|
-
_callRemovalHooks: _callRemovalHooks,
|
3628
|
-
_remove: _remove,
|
3629
|
-
_markRemoved: _markRemoved,
|
3630
|
-
_assertUnremoved: _assertUnremoved
|
3631
|
-
});
|
3632
|
-
|
3633
3789
|
const {
|
3634
|
-
react
|
3790
|
+
react
|
3635
3791
|
} = _t;
|
3636
3792
|
const {
|
3637
3793
|
cloneNode: cloneNode$1,
|
@@ -3641,7 +3797,7 @@ const {
|
|
3641
3797
|
} = _t;
|
3642
3798
|
const referenceVisitor = {
|
3643
3799
|
ReferencedIdentifier(path, state) {
|
3644
|
-
if (path.isJSXIdentifier() && react
|
3800
|
+
if (path.isJSXIdentifier() && react.isCompatTag(path.node.name) && !path.parentPath.isJSXMemberExpression()) {
|
3645
3801
|
return;
|
3646
3802
|
}
|
3647
3803
|
if (path.node.name === "this") {
|
@@ -3802,8 +3958,8 @@ const {
|
|
3802
3958
|
isAssignmentExpression,
|
3803
3959
|
isCallExpression,
|
3804
3960
|
isExportNamedDeclaration,
|
3805
|
-
isExpression
|
3806
|
-
isIdentifier
|
3961
|
+
isExpression,
|
3962
|
+
isIdentifier,
|
3807
3963
|
isSequenceExpression,
|
3808
3964
|
isSuper,
|
3809
3965
|
thisExpression
|
@@ -3864,7 +4020,7 @@ function isHiddenInSequenceExpression(path) {
|
|
3864
4020
|
return isSequenceExpression(path.parent) && (last(path.parent.expressions) !== path.node || isHiddenInSequenceExpression(path.parentPath));
|
3865
4021
|
}
|
3866
4022
|
function isAlmostConstantAssignment(node, scope) {
|
3867
|
-
if (!isAssignmentExpression(node) || !isIdentifier
|
4023
|
+
if (!isAssignmentExpression(node) || !isIdentifier(node.left)) {
|
3868
4024
|
return false;
|
3869
4025
|
}
|
3870
4026
|
const blockScope = scope.getBlockParent();
|
@@ -3882,21 +4038,22 @@ function insertAfter(nodes_) {
|
|
3882
4038
|
} = this;
|
3883
4039
|
if (parentPath.isExpressionStatement() || parentPath.isLabeledStatement() || isExportNamedDeclaration(parent) || parentPath.isExportDefaultDeclaration() && this.isDeclaration()) {
|
3884
4040
|
return parentPath.insertAfter(nodes.map(node => {
|
3885
|
-
return isExpression
|
4041
|
+
return isExpression(node) ? expressionStatement(node) : node;
|
3886
4042
|
}));
|
3887
4043
|
} else if (this.isNodeType("Expression") && !this.isJSXElement() && !parentPath.isJSXElement() || parentPath.isForStatement() && this.key === "init") {
|
3888
|
-
|
3889
|
-
|
4044
|
+
const self = this;
|
4045
|
+
if (self.node) {
|
4046
|
+
const node = self.node;
|
3890
4047
|
let {
|
3891
4048
|
scope
|
3892
4049
|
} = this;
|
3893
4050
|
if (scope.path.isPattern()) {
|
3894
4051
|
assertExpression(node);
|
3895
|
-
|
3896
|
-
|
3897
|
-
return [
|
4052
|
+
self.replaceWith(callExpression(arrowFunctionExpression([], node), []));
|
4053
|
+
self.get("callee.body").insertAfter(nodes);
|
4054
|
+
return [self];
|
3898
4055
|
}
|
3899
|
-
if (isHiddenInSequenceExpression(
|
4056
|
+
if (isHiddenInSequenceExpression(self)) {
|
3900
4057
|
nodes.unshift(node);
|
3901
4058
|
} else if (isCallExpression(node) && isSuper(node.callee)) {
|
3902
4059
|
nodes.unshift(node);
|
@@ -3932,7 +4089,7 @@ function insertAfter(nodes_) {
|
|
3932
4089
|
}
|
3933
4090
|
function updateSiblingKeys(fromIndex, incrementBy) {
|
3934
4091
|
if (!this.parent) return;
|
3935
|
-
const paths =
|
4092
|
+
const paths = getCachedPaths(this.hub, this.parent) || [];
|
3936
4093
|
for (const [, path] of paths) {
|
3937
4094
|
if (typeof path.key === "number" && path.key >= fromIndex) {
|
3938
4095
|
path.key += incrementBy;
|
@@ -3955,7 +4112,7 @@ function _verifyNodeList(nodes) {
|
|
3955
4112
|
msg = "contains a non-object node";
|
3956
4113
|
} else if (!node.type) {
|
3957
4114
|
msg = "without a type";
|
3958
|
-
} else if (node instanceof
|
4115
|
+
} else if (node instanceof NodePath_Final) {
|
3959
4116
|
msg = "has a NodePath when it expected a raw object";
|
3960
4117
|
}
|
3961
4118
|
if (msg) {
|
@@ -3968,7 +4125,7 @@ function _verifyNodeList(nodes) {
|
|
3968
4125
|
function unshiftContainer(listKey, nodes) {
|
3969
4126
|
this._assertUnremoved();
|
3970
4127
|
nodes = this._verifyNodeList(nodes);
|
3971
|
-
const path =
|
4128
|
+
const path = NodePath_Final.get({
|
3972
4129
|
parentPath: this,
|
3973
4130
|
parent: this.node,
|
3974
4131
|
container: this.node[listKey],
|
@@ -3981,7 +4138,7 @@ function pushContainer(listKey, nodes) {
|
|
3981
4138
|
this._assertUnremoved();
|
3982
4139
|
const verifiedNodes = this._verifyNodeList(nodes);
|
3983
4140
|
const container = this.node[listKey];
|
3984
|
-
const path =
|
4141
|
+
const path = NodePath_Final.get({
|
3985
4142
|
parentPath: this,
|
3986
4143
|
parent: this.node,
|
3987
4144
|
container: container,
|
@@ -3995,24 +4152,9 @@ function hoist(scope = this.scope) {
|
|
3995
4152
|
return hoister.run();
|
3996
4153
|
}
|
3997
4154
|
|
3998
|
-
var NodePath_modification = /*#__PURE__*/Object.freeze({
|
3999
|
-
__proto__: null,
|
4000
|
-
insertBefore: insertBefore,
|
4001
|
-
_containerInsert: _containerInsert,
|
4002
|
-
_containerInsertBefore: _containerInsertBefore,
|
4003
|
-
_containerInsertAfter: _containerInsertAfter,
|
4004
|
-
insertAfter: insertAfter,
|
4005
|
-
updateSiblingKeys: updateSiblingKeys,
|
4006
|
-
_verifyNodeList: _verifyNodeList,
|
4007
|
-
unshiftContainer: unshiftContainer,
|
4008
|
-
pushContainer: pushContainer,
|
4009
|
-
hoist: hoist
|
4010
|
-
});
|
4011
|
-
|
4012
4155
|
const {
|
4013
4156
|
getBindingIdentifiers: _getBindingIdentifiers,
|
4014
4157
|
getOuterBindingIdentifiers: _getOuterBindingIdentifiers,
|
4015
|
-
isDeclaration,
|
4016
4158
|
numericLiteral,
|
4017
4159
|
unaryExpression
|
4018
4160
|
} = _t;
|
@@ -4185,7 +4327,7 @@ function getCompletionRecords() {
|
|
4185
4327
|
return records.map(r => r.path);
|
4186
4328
|
}
|
4187
4329
|
function getSibling(key) {
|
4188
|
-
return
|
4330
|
+
return NodePath_Final.get({
|
4189
4331
|
parentPath: this.parentPath,
|
4190
4332
|
parent: this.parent,
|
4191
4333
|
container: this.container,
|
@@ -4233,7 +4375,7 @@ function _getKey(key, context) {
|
|
4233
4375
|
const container = node[key];
|
4234
4376
|
if (Array.isArray(container)) {
|
4235
4377
|
return container.map((_, i) => {
|
4236
|
-
return
|
4378
|
+
return NodePath_Final.get({
|
4237
4379
|
listKey: key,
|
4238
4380
|
parentPath: this,
|
4239
4381
|
parent: node,
|
@@ -4242,7 +4384,7 @@ function _getKey(key, context) {
|
|
4242
4384
|
}).setContext(context);
|
4243
4385
|
});
|
4244
4386
|
} else {
|
4245
|
-
return
|
4387
|
+
return NodePath_Final.get({
|
4246
4388
|
parentPath: this,
|
4247
4389
|
parent: node,
|
4248
4390
|
container: node,
|
@@ -4291,7 +4433,7 @@ function getBindingIdentifierPaths(duplicates = false, outerOnly = false) {
|
|
4291
4433
|
}
|
4292
4434
|
if (id.isExportDeclaration()) {
|
4293
4435
|
const declaration = id.get("declaration");
|
4294
|
-
if (isDeclaration(
|
4436
|
+
if (declaration.isDeclaration()) {
|
4295
4437
|
search.push(declaration);
|
4296
4438
|
}
|
4297
4439
|
continue;
|
@@ -4323,24 +4465,6 @@ function getOuterBindingIdentifierPaths(duplicates = false) {
|
|
4323
4465
|
return this.getBindingIdentifierPaths(duplicates, true);
|
4324
4466
|
}
|
4325
4467
|
|
4326
|
-
var NodePath_family = /*#__PURE__*/Object.freeze({
|
4327
|
-
__proto__: null,
|
4328
|
-
getOpposite: getOpposite,
|
4329
|
-
getCompletionRecords: getCompletionRecords,
|
4330
|
-
getSibling: getSibling,
|
4331
|
-
getPrevSibling: getPrevSibling,
|
4332
|
-
getNextSibling: getNextSibling,
|
4333
|
-
getAllNextSiblings: getAllNextSiblings,
|
4334
|
-
getAllPrevSiblings: getAllPrevSiblings,
|
4335
|
-
get: get,
|
4336
|
-
_getKey: _getKey,
|
4337
|
-
_getPattern: _getPattern,
|
4338
|
-
getBindingIdentifiers: getBindingIdentifiers,
|
4339
|
-
getOuterBindingIdentifiers: getOuterBindingIdentifiers,
|
4340
|
-
getBindingIdentifierPaths: getBindingIdentifierPaths,
|
4341
|
-
getOuterBindingIdentifierPaths: getOuterBindingIdentifierPaths
|
4342
|
-
});
|
4343
|
-
|
4344
4468
|
const {
|
4345
4469
|
addComment: _addComment,
|
4346
4470
|
addComments: _addComments
|
@@ -4370,12 +4494,10 @@ function shareCommentsWithSiblings() {
|
|
4370
4494
|
}
|
4371
4495
|
}
|
4372
4496
|
function removeIfExisting(list, toRemove) {
|
4373
|
-
if (!toRemove) return list;
|
4374
|
-
|
4497
|
+
if (!toRemove?.length) return list;
|
4498
|
+
const set = new Set(toRemove);
|
4375
4499
|
return list.filter(el => {
|
4376
|
-
|
4377
|
-
if (i === -1) return true;
|
4378
|
-
lastFoundIndex = i;
|
4500
|
+
return !set.has(el);
|
4379
4501
|
});
|
4380
4502
|
}
|
4381
4503
|
function addComment(type, content, line) {
|
@@ -4385,171 +4507,6 @@ function addComments(type, comments) {
|
|
4385
4507
|
_addComments(this.node, type, comments);
|
4386
4508
|
}
|
4387
4509
|
|
4388
|
-
var NodePath_comments = /*#__PURE__*/Object.freeze({
|
4389
|
-
__proto__: null,
|
4390
|
-
shareCommentsWithSiblings: shareCommentsWithSiblings,
|
4391
|
-
addComment: addComment,
|
4392
|
-
addComments: addComments
|
4393
|
-
});
|
4394
|
-
|
4395
|
-
const {
|
4396
|
-
isBinding,
|
4397
|
-
isBlockScoped: nodeIsBlockScoped,
|
4398
|
-
isExportDeclaration,
|
4399
|
-
isExpression: nodeIsExpression,
|
4400
|
-
isFlow: nodeIsFlow,
|
4401
|
-
isForStatement,
|
4402
|
-
isForXStatement,
|
4403
|
-
isIdentifier,
|
4404
|
-
isImportDeclaration,
|
4405
|
-
isImportSpecifier,
|
4406
|
-
isJSXIdentifier,
|
4407
|
-
isJSXMemberExpression,
|
4408
|
-
isMemberExpression,
|
4409
|
-
isRestElement: nodeIsRestElement,
|
4410
|
-
isReferenced: nodeIsReferenced,
|
4411
|
-
isScope: nodeIsScope,
|
4412
|
-
isStatement: nodeIsStatement,
|
4413
|
-
isVar: nodeIsVar,
|
4414
|
-
isVariableDeclaration,
|
4415
|
-
react,
|
4416
|
-
isForOfStatement
|
4417
|
-
} = _t;
|
4418
|
-
const {
|
4419
|
-
isCompatTag
|
4420
|
-
} = react;
|
4421
|
-
function isReferencedIdentifier(opts) {
|
4422
|
-
const {
|
4423
|
-
node,
|
4424
|
-
parent
|
4425
|
-
} = this;
|
4426
|
-
if (!isIdentifier(node, opts) && !isJSXMemberExpression(parent, opts)) {
|
4427
|
-
if (isJSXIdentifier(node, opts)) {
|
4428
|
-
if (isCompatTag(node.name)) return false;
|
4429
|
-
} else {
|
4430
|
-
return false;
|
4431
|
-
}
|
4432
|
-
}
|
4433
|
-
return nodeIsReferenced(node, parent, this.parentPath.parent);
|
4434
|
-
}
|
4435
|
-
function isReferencedMemberExpression() {
|
4436
|
-
const {
|
4437
|
-
node,
|
4438
|
-
parent
|
4439
|
-
} = this;
|
4440
|
-
return isMemberExpression(node) && nodeIsReferenced(node, parent);
|
4441
|
-
}
|
4442
|
-
function isBindingIdentifier() {
|
4443
|
-
const {
|
4444
|
-
node,
|
4445
|
-
parent
|
4446
|
-
} = this;
|
4447
|
-
const grandparent = this.parentPath.parent;
|
4448
|
-
return isIdentifier(node) && isBinding(node, parent, grandparent);
|
4449
|
-
}
|
4450
|
-
function isStatement() {
|
4451
|
-
const {
|
4452
|
-
node,
|
4453
|
-
parent
|
4454
|
-
} = this;
|
4455
|
-
if (nodeIsStatement(node)) {
|
4456
|
-
if (isVariableDeclaration(node)) {
|
4457
|
-
if (isForXStatement(parent, {
|
4458
|
-
left: node
|
4459
|
-
})) return false;
|
4460
|
-
if (isForStatement(parent, {
|
4461
|
-
init: node
|
4462
|
-
})) return false;
|
4463
|
-
}
|
4464
|
-
return true;
|
4465
|
-
} else {
|
4466
|
-
return false;
|
4467
|
-
}
|
4468
|
-
}
|
4469
|
-
function isExpression() {
|
4470
|
-
if (this.isIdentifier()) {
|
4471
|
-
return this.isReferencedIdentifier();
|
4472
|
-
} else {
|
4473
|
-
return nodeIsExpression(this.node);
|
4474
|
-
}
|
4475
|
-
}
|
4476
|
-
function isScope() {
|
4477
|
-
return nodeIsScope(this.node, this.parent);
|
4478
|
-
}
|
4479
|
-
function isReferenced() {
|
4480
|
-
return nodeIsReferenced(this.node, this.parent);
|
4481
|
-
}
|
4482
|
-
function isBlockScoped() {
|
4483
|
-
return nodeIsBlockScoped(this.node);
|
4484
|
-
}
|
4485
|
-
function isVar() {
|
4486
|
-
return nodeIsVar(this.node);
|
4487
|
-
}
|
4488
|
-
function isUser() {
|
4489
|
-
return this.node && !!this.node.loc;
|
4490
|
-
}
|
4491
|
-
function isGenerated() {
|
4492
|
-
return !this.isUser();
|
4493
|
-
}
|
4494
|
-
function isPure(constantsOnly) {
|
4495
|
-
return this.scope.isPure(this.node, constantsOnly);
|
4496
|
-
}
|
4497
|
-
function isFlow() {
|
4498
|
-
const {
|
4499
|
-
node
|
4500
|
-
} = this;
|
4501
|
-
if (nodeIsFlow(node)) {
|
4502
|
-
return true;
|
4503
|
-
} else if (isImportDeclaration(node)) {
|
4504
|
-
return node.importKind === "type" || node.importKind === "typeof";
|
4505
|
-
} else if (isExportDeclaration(node)) {
|
4506
|
-
return node.exportKind === "type";
|
4507
|
-
} else if (isImportSpecifier(node)) {
|
4508
|
-
return node.importKind === "type" || node.importKind === "typeof";
|
4509
|
-
} else {
|
4510
|
-
return false;
|
4511
|
-
}
|
4512
|
-
}
|
4513
|
-
function isRestProperty() {
|
4514
|
-
return nodeIsRestElement(this.node) && this.parentPath && this.parentPath.isObjectPattern();
|
4515
|
-
}
|
4516
|
-
function isSpreadProperty() {
|
4517
|
-
return nodeIsRestElement(this.node) && this.parentPath && this.parentPath.isObjectExpression();
|
4518
|
-
}
|
4519
|
-
function isForAwaitStatement() {
|
4520
|
-
return isForOfStatement(this.node, {
|
4521
|
-
await: true
|
4522
|
-
});
|
4523
|
-
}
|
4524
|
-
function isExistentialTypeParam() {
|
4525
|
-
throw new Error("`path.isExistentialTypeParam` has been renamed to `path.isExistsTypeAnnotation()` in Babel 7.");
|
4526
|
-
}
|
4527
|
-
function isNumericLiteralTypeAnnotation() {
|
4528
|
-
throw new Error("`path.isNumericLiteralTypeAnnotation()` has been renamed to `path.isNumberLiteralTypeAnnotation()` in Babel 7.");
|
4529
|
-
}
|
4530
|
-
|
4531
|
-
var NodePath_virtual_types_validator = /*#__PURE__*/Object.freeze({
|
4532
|
-
__proto__: null,
|
4533
|
-
isReferencedIdentifier: isReferencedIdentifier,
|
4534
|
-
isReferencedMemberExpression: isReferencedMemberExpression,
|
4535
|
-
isBindingIdentifier: isBindingIdentifier,
|
4536
|
-
isStatement: isStatement,
|
4537
|
-
isExpression: isExpression,
|
4538
|
-
isScope: isScope,
|
4539
|
-
isReferenced: isReferenced,
|
4540
|
-
isBlockScoped: isBlockScoped,
|
4541
|
-
isVar: isVar,
|
4542
|
-
isUser: isUser,
|
4543
|
-
isGenerated: isGenerated,
|
4544
|
-
isPure: isPure,
|
4545
|
-
isFlow: isFlow,
|
4546
|
-
isRestProperty: isRestProperty,
|
4547
|
-
isSpreadProperty: isSpreadProperty,
|
4548
|
-
isForAwaitStatement: isForAwaitStatement,
|
4549
|
-
isExistentialTypeParam: isExistentialTypeParam,
|
4550
|
-
isNumericLiteralTypeAnnotation: isNumericLiteralTypeAnnotation
|
4551
|
-
});
|
4552
|
-
|
4553
4510
|
const {
|
4554
4511
|
validate
|
4555
4512
|
} = _t;
|
@@ -4557,7 +4514,7 @@ const debug = buildDebug("babel");
|
|
4557
4514
|
const REMOVED = 1 << 0;
|
4558
4515
|
const SHOULD_STOP = 1 << 1;
|
4559
4516
|
const SHOULD_SKIP = 1 << 2;
|
4560
|
-
class NodePath {
|
4517
|
+
const NodePath_Final = class NodePath {
|
4561
4518
|
constructor(hub, parent) {
|
4562
4519
|
this.parent = parent;
|
4563
4520
|
this.hub = hub;
|
@@ -4569,6 +4526,24 @@ class NodePath {
|
|
4569
4526
|
state = null;
|
4570
4527
|
opts = null;
|
4571
4528
|
_traverseFlags = 0;
|
4529
|
+
get removed() {
|
4530
|
+
return (this._traverseFlags & 1) > 0;
|
4531
|
+
}
|
4532
|
+
set removed(v) {
|
4533
|
+
if (v) this._traverseFlags |= 1;else this._traverseFlags &= -2;
|
4534
|
+
}
|
4535
|
+
get shouldStop() {
|
4536
|
+
return (this._traverseFlags & 2) > 0;
|
4537
|
+
}
|
4538
|
+
set shouldStop(v) {
|
4539
|
+
if (v) this._traverseFlags |= 2;else this._traverseFlags &= -3;
|
4540
|
+
}
|
4541
|
+
get shouldSkip() {
|
4542
|
+
return (this._traverseFlags & 4) > 0;
|
4543
|
+
}
|
4544
|
+
set shouldSkip(v) {
|
4545
|
+
if (v) this._traverseFlags |= 4;else this._traverseFlags &= -5;
|
4546
|
+
}
|
4572
4547
|
skipKeys = null;
|
4573
4548
|
parentPath = null;
|
4574
4549
|
container = null;
|
@@ -4591,18 +4566,14 @@ class NodePath {
|
|
4591
4566
|
throw new Error("To get a node path the parent needs to exist");
|
4592
4567
|
}
|
4593
4568
|
const targetNode = container[key];
|
4594
|
-
|
4595
|
-
|
4596
|
-
|
4597
|
-
path
|
4569
|
+
const paths = getOrCreateCachedPaths(hub, parent);
|
4570
|
+
let path = paths.get(targetNode);
|
4571
|
+
if (!path) {
|
4572
|
+
path = new NodePath(hub, parent);
|
4573
|
+
if (targetNode) paths.set(targetNode, path);
|
4598
4574
|
}
|
4599
|
-
|
4600
|
-
|
4601
|
-
path$1 = new NodePath(hub, parent);
|
4602
|
-
if (targetNode) paths.set(targetNode, path$1);
|
4603
|
-
}
|
4604
|
-
path$1.setup(parentPath, container, listKey, key);
|
4605
|
-
return path$1;
|
4575
|
+
path.setup(parentPath, container, listKey, key);
|
4576
|
+
return path;
|
4606
4577
|
}
|
4607
4578
|
getScope(scope) {
|
4608
4579
|
return this.isScope() ? new Scope(this) : scope;
|
@@ -4662,51 +4633,124 @@ class NodePath {
|
|
4662
4633
|
get parentKey() {
|
4663
4634
|
return this.listKey || this.key;
|
4664
4635
|
}
|
4665
|
-
|
4666
|
-
|
4667
|
-
|
4668
|
-
|
4669
|
-
|
4670
|
-
|
4671
|
-
|
4672
|
-
|
4673
|
-
|
4674
|
-
|
4675
|
-
|
4676
|
-
|
4677
|
-
|
4678
|
-
|
4679
|
-
|
4680
|
-
|
4681
|
-
|
4682
|
-
|
4683
|
-
|
4684
|
-
|
4685
|
-
|
4686
|
-
|
4687
|
-
|
4688
|
-
|
4689
|
-
|
4690
|
-
|
4691
|
-
|
4692
|
-
|
4693
|
-
|
4694
|
-
|
4695
|
-
|
4696
|
-
|
4636
|
+
};
|
4637
|
+
const methods = {
|
4638
|
+
findParent: findParent,
|
4639
|
+
find: find,
|
4640
|
+
getFunctionParent: getFunctionParent,
|
4641
|
+
getStatementParent: getStatementParent,
|
4642
|
+
getEarliestCommonAncestorFrom: getEarliestCommonAncestorFrom,
|
4643
|
+
getDeepestCommonAncestorFrom: getDeepestCommonAncestorFrom,
|
4644
|
+
getAncestry: getAncestry,
|
4645
|
+
isAncestor: isAncestor,
|
4646
|
+
isDescendant: isDescendant,
|
4647
|
+
inType: inType,
|
4648
|
+
getTypeAnnotation: getTypeAnnotation,
|
4649
|
+
_getTypeAnnotation: _getTypeAnnotation,
|
4650
|
+
isBaseType: isBaseType,
|
4651
|
+
couldBeBaseType: couldBeBaseType,
|
4652
|
+
baseTypeStrictlyMatches: baseTypeStrictlyMatches,
|
4653
|
+
isGenericType: isGenericType,
|
4654
|
+
replaceWithMultiple: replaceWithMultiple,
|
4655
|
+
replaceWithSourceString: replaceWithSourceString,
|
4656
|
+
replaceWith: replaceWith,
|
4657
|
+
_replaceWith: _replaceWith,
|
4658
|
+
replaceExpressionWithStatements: replaceExpressionWithStatements,
|
4659
|
+
replaceInline: replaceInline,
|
4660
|
+
evaluateTruthy: evaluateTruthy,
|
4661
|
+
evaluate: evaluate,
|
4662
|
+
toComputedKey: toComputedKey,
|
4663
|
+
ensureBlock: ensureBlock,
|
4664
|
+
unwrapFunctionEnvironment: unwrapFunctionEnvironment,
|
4665
|
+
arrowFunctionToExpression: arrowFunctionToExpression,
|
4666
|
+
matchesPattern: matchesPattern,
|
4667
|
+
has: has,
|
4668
|
+
isStatic: isStatic,
|
4669
|
+
is: is,
|
4670
|
+
isnt: isnt,
|
4671
|
+
equals: equals,
|
4672
|
+
isNodeType: isNodeType,
|
4673
|
+
canHaveVariableDeclarationOrExpression: canHaveVariableDeclarationOrExpression,
|
4674
|
+
canSwapBetweenExpressionAndStatement: canSwapBetweenExpressionAndStatement,
|
4675
|
+
isCompletionRecord: isCompletionRecord,
|
4676
|
+
isStatementOrBlock: isStatementOrBlock,
|
4677
|
+
referencesImport: referencesImport,
|
4678
|
+
getSource: getSource,
|
4679
|
+
willIMaybeExecuteBefore: willIMaybeExecuteBefore,
|
4680
|
+
_guessExecutionStatusRelativeTo: _guessExecutionStatusRelativeTo,
|
4681
|
+
resolve: resolve,
|
4682
|
+
_resolve: _resolve,
|
4683
|
+
isConstantExpression: isConstantExpression,
|
4684
|
+
isInStrictMode: isInStrictMode,
|
4685
|
+
call: call,
|
4686
|
+
_call: _call,
|
4687
|
+
isDenylisted: isDenylisted,
|
4688
|
+
isBlacklisted: isDenylisted,
|
4689
|
+
visit: visit,
|
4690
|
+
skip: skip,
|
4691
|
+
skipKey: skipKey,
|
4692
|
+
stop: stop,
|
4693
|
+
setScope: setScope,
|
4694
|
+
setContext: setContext,
|
4695
|
+
resync: resync,
|
4696
|
+
_resyncParent: _resyncParent,
|
4697
|
+
_resyncKey: _resyncKey,
|
4698
|
+
_resyncList: _resyncList,
|
4699
|
+
_resyncRemoved: _resyncRemoved,
|
4700
|
+
popContext: popContext,
|
4701
|
+
pushContext: pushContext,
|
4702
|
+
setup: setup,
|
4703
|
+
setKey: setKey,
|
4704
|
+
requeue: requeue,
|
4705
|
+
_getQueueContexts: _getQueueContexts,
|
4706
|
+
remove: remove,
|
4707
|
+
_removeFromScope: _removeFromScope,
|
4708
|
+
_callRemovalHooks: _callRemovalHooks,
|
4709
|
+
_remove: _remove,
|
4710
|
+
_markRemoved: _markRemoved,
|
4711
|
+
_assertUnremoved: _assertUnremoved,
|
4712
|
+
insertBefore: insertBefore,
|
4713
|
+
_containerInsert: _containerInsert,
|
4714
|
+
_containerInsertBefore: _containerInsertBefore,
|
4715
|
+
_containerInsertAfter: _containerInsertAfter,
|
4716
|
+
insertAfter: insertAfter,
|
4717
|
+
updateSiblingKeys: updateSiblingKeys,
|
4718
|
+
_verifyNodeList: _verifyNodeList,
|
4719
|
+
unshiftContainer: unshiftContainer,
|
4720
|
+
pushContainer: pushContainer,
|
4721
|
+
hoist: hoist,
|
4722
|
+
getOpposite: getOpposite,
|
4723
|
+
getCompletionRecords: getCompletionRecords,
|
4724
|
+
getSibling: getSibling,
|
4725
|
+
getPrevSibling: getPrevSibling,
|
4726
|
+
getNextSibling: getNextSibling,
|
4727
|
+
getAllNextSiblings: getAllNextSiblings,
|
4728
|
+
getAllPrevSiblings: getAllPrevSiblings,
|
4729
|
+
get: get,
|
4730
|
+
_getKey: _getKey,
|
4731
|
+
_getPattern: _getPattern,
|
4732
|
+
getBindingIdentifiers: getBindingIdentifiers,
|
4733
|
+
getOuterBindingIdentifiers: getOuterBindingIdentifiers,
|
4734
|
+
getBindingIdentifierPaths: getBindingIdentifierPaths,
|
4735
|
+
getOuterBindingIdentifierPaths: getOuterBindingIdentifierPaths,
|
4736
|
+
shareCommentsWithSiblings: shareCommentsWithSiblings,
|
4737
|
+
addComment: addComment,
|
4738
|
+
addComments: addComments
|
4739
|
+
};
|
4740
|
+
Object.assign(NodePath_Final.prototype, methods);
|
4697
4741
|
for (const type of _t.TYPES) {
|
4698
4742
|
const typeKey = `is${type}`;
|
4699
4743
|
const fn = _t[typeKey];
|
4700
|
-
|
4744
|
+
NodePath_Final.prototype[typeKey] = function (opts) {
|
4701
4745
|
return fn(this.node, opts);
|
4702
4746
|
};
|
4703
|
-
|
4747
|
+
NodePath_Final.prototype[`assert${type}`] = function (opts) {
|
4704
4748
|
if (!fn(this.node, opts)) {
|
4705
4749
|
throw new TypeError(`Expected node path of type ${type}`);
|
4706
4750
|
}
|
4707
4751
|
};
|
4708
4752
|
}
|
4709
|
-
Object.assign(
|
4753
|
+
Object.assign(NodePath_Final.prototype, NodePath_virtual_types_validator);
|
4710
4754
|
for (const type of Object.keys(virtualTypes)) {
|
4711
4755
|
if (type[0] === "_") continue;
|
4712
4756
|
if (!_t.TYPES.includes(type)) _t.TYPES.push(type);
|
@@ -4738,7 +4782,7 @@ class TraversalContext {
|
|
4738
4782
|
return false;
|
4739
4783
|
}
|
4740
4784
|
create(node, container, key, listKey) {
|
4741
|
-
return
|
4785
|
+
return NodePath_Final.get({
|
4742
4786
|
parentPath: this.parentPath,
|
4743
4787
|
parent: node,
|
4744
4788
|
container,
|
@@ -4778,7 +4822,10 @@ class TraversalContext {
|
|
4778
4822
|
this.priorityQueue = [];
|
4779
4823
|
const visited = new WeakSet();
|
4780
4824
|
let stop = false;
|
4781
|
-
|
4825
|
+
let visitIndex = 0;
|
4826
|
+
for (; visitIndex < queue.length;) {
|
4827
|
+
const path = queue[visitIndex];
|
4828
|
+
visitIndex++;
|
4782
4829
|
path.resync();
|
4783
4830
|
if (path.contexts.length === 0 || path.contexts[path.contexts.length - 1] !== this) {
|
4784
4831
|
path.pushContext(this);
|
@@ -4800,8 +4847,8 @@ class TraversalContext {
|
|
4800
4847
|
if (stop) break;
|
4801
4848
|
}
|
4802
4849
|
}
|
4803
|
-
for (
|
4804
|
-
|
4850
|
+
for (let i = 0; i < visitIndex; i++) {
|
4851
|
+
queue[i].popContext();
|
4805
4852
|
}
|
4806
4853
|
this.queue = null;
|
4807
4854
|
return stop;
|
@@ -4820,12 +4867,16 @@ class TraversalContext {
|
|
4820
4867
|
const {
|
4821
4868
|
VISITOR_KEYS: VISITOR_KEYS$1
|
4822
4869
|
} = _t;
|
4823
|
-
function traverseNode(node, opts, scope, state, path, skipKeys) {
|
4870
|
+
function traverseNode(node, opts, scope, state, path, skipKeys, visitSelf) {
|
4824
4871
|
const keys = VISITOR_KEYS$1[node.type];
|
4825
4872
|
if (!keys) return false;
|
4826
4873
|
const context = new TraversalContext(scope, opts, state, path);
|
4874
|
+
if (visitSelf) {
|
4875
|
+
if (skipKeys?.[path.parentKey]) return false;
|
4876
|
+
return context.visitQueue([path]);
|
4877
|
+
}
|
4827
4878
|
for (const key of keys) {
|
4828
|
-
if (skipKeys
|
4879
|
+
if (skipKeys?.[key]) continue;
|
4829
4880
|
if (context.visit(node, key)) {
|
4830
4881
|
return true;
|
4831
4882
|
}
|
@@ -4849,22 +4900,25 @@ const {
|
|
4849
4900
|
removeProperties,
|
4850
4901
|
traverseFast
|
4851
4902
|
} = _t;
|
4852
|
-
function traverse(parent, opts = {}, scope, state, parentPath) {
|
4903
|
+
function traverse(parent, opts = {}, scope, state, parentPath, visitSelf) {
|
4853
4904
|
if (!parent) return;
|
4854
4905
|
if (!opts.noScope && !scope) {
|
4855
4906
|
if (parent.type !== "Program" && parent.type !== "File") {
|
4856
4907
|
throw new Error("You must pass a scope and parentPath unless traversing a Program/File. " + `Instead of that you tried to traverse a ${parent.type} node without ` + "passing scope and parentPath.");
|
4857
4908
|
}
|
4858
4909
|
}
|
4910
|
+
if (!parentPath && visitSelf) {
|
4911
|
+
throw new Error("visitSelf can only be used when providing a NodePath.");
|
4912
|
+
}
|
4859
4913
|
if (!VISITOR_KEYS[parent.type]) {
|
4860
4914
|
return;
|
4861
4915
|
}
|
4862
|
-
explode(opts);
|
4863
|
-
traverseNode(parent, opts, scope, state, parentPath);
|
4916
|
+
explode$1(opts);
|
4917
|
+
traverseNode(parent, opts, scope, state, parentPath, null, visitSelf);
|
4864
4918
|
}
|
4865
4919
|
traverse.visitors = visitors;
|
4866
|
-
traverse.verify = verify;
|
4867
|
-
traverse.explode = explode;
|
4920
|
+
traverse.verify = verify$1;
|
4921
|
+
traverse.explode = explode$1;
|
4868
4922
|
traverse.cheap = function (node, enter) {
|
4869
4923
|
traverseFast(node, enter);
|
4870
4924
|
return;
|
@@ -4874,7 +4928,6 @@ traverse.node = function (node, opts, scope, state, path, skipKeys) {
|
|
4874
4928
|
};
|
4875
4929
|
traverse.clearNode = function (node, opts) {
|
4876
4930
|
removeProperties(node, opts);
|
4877
|
-
path.delete(node);
|
4878
4931
|
};
|
4879
4932
|
traverse.removeProperties = function (tree, opts) {
|
4880
4933
|
traverseFast(tree, traverse.clearNode, opts);
|
@@ -4902,5 +4955,5 @@ traverse.hasType = function (tree, type, denylistTypes) {
|
|
4902
4955
|
};
|
4903
4956
|
traverse.cache = cache;
|
4904
4957
|
|
4905
|
-
export { Hub, NodePath, Scope, traverse as default, visitors };
|
4958
|
+
export { Hub, NodePath_Final as NodePath, Scope, traverse as default, visitors };
|
4906
4959
|
//# sourceMappingURL=index.js.map
|