@babel/traverse 8.0.0-alpha.8 → 8.0.0-beta.0
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 +3523 -0
- package/lib/index.js +1298 -1231
- package/lib/index.js.map +1 -1
- package/package.json +14 -14
package/lib/index.js
CHANGED
@@ -1,13 +1,10 @@
|
|
1
|
-
import * as _t from '@babel/types';
|
2
1
|
import buildDebug from 'debug';
|
3
|
-
import splitExportDeclaration from '@babel/helper-split-export-declaration';
|
4
|
-
import environmentVisitor, { requeueComputedKeyAndDecorators } from '@babel/helper-environment-visitor';
|
5
|
-
import globals from 'globals';
|
6
|
-
import generator from '@babel/generator';
|
7
2
|
import { codeFrameColumns } from '@babel/code-frame';
|
3
|
+
import * as _t from '@babel/types';
|
8
4
|
import { parse } from '@babel/parser';
|
9
|
-
import
|
10
|
-
import
|
5
|
+
import globals from 'globals';
|
6
|
+
import generator from '@babel/generator';
|
7
|
+
import template from '@babel/template';
|
11
8
|
|
12
9
|
const ReferencedIdentifier = ["Identifier", "JSXIdentifier"];
|
13
10
|
const ReferencedMemberExpression = ["MemberExpression"];
|
@@ -70,12 +67,12 @@ const {
|
|
70
67
|
isStatement: nodeIsStatement,
|
71
68
|
isVar: nodeIsVar,
|
72
69
|
isVariableDeclaration: isVariableDeclaration$2,
|
73
|
-
react
|
70
|
+
react,
|
74
71
|
isForOfStatement
|
75
72
|
} = _t;
|
76
73
|
const {
|
77
74
|
isCompatTag
|
78
|
-
} = react
|
75
|
+
} = react;
|
79
76
|
function isReferencedIdentifier(opts) {
|
80
77
|
const {
|
81
78
|
node,
|
@@ -169,10 +166,10 @@ function isFlow() {
|
|
169
166
|
}
|
170
167
|
}
|
171
168
|
function isRestProperty() {
|
172
|
-
return nodeIsRestElement(this.node) && this.parentPath
|
169
|
+
return nodeIsRestElement(this.node) && this.parentPath?.isObjectPattern();
|
173
170
|
}
|
174
171
|
function isSpreadProperty() {
|
175
|
-
return nodeIsRestElement(this.node) && this.parentPath
|
172
|
+
return nodeIsRestElement(this.node) && this.parentPath?.isObjectExpression();
|
176
173
|
}
|
177
174
|
function isForAwaitStatement() {
|
178
175
|
return isForOfStatement(this.node, {
|
@@ -213,7 +210,7 @@ function isVirtualType(type) {
|
|
213
210
|
function isExplodedVisitor(visitor) {
|
214
211
|
return visitor?._exploded;
|
215
212
|
}
|
216
|
-
function explode(visitor) {
|
213
|
+
function explode$1(visitor) {
|
217
214
|
if (isExplodedVisitor(visitor)) return visitor;
|
218
215
|
visitor._exploded = true;
|
219
216
|
for (const nodeType of Object.keys(visitor)) {
|
@@ -226,7 +223,7 @@ function explode(visitor) {
|
|
226
223
|
visitor[part] = fns;
|
227
224
|
}
|
228
225
|
}
|
229
|
-
verify(visitor);
|
226
|
+
verify$1(visitor);
|
230
227
|
delete visitor.__esModule;
|
231
228
|
ensureEntranceObjects(visitor);
|
232
229
|
ensureCallbackArrays(visitor);
|
@@ -281,7 +278,7 @@ function explode(visitor) {
|
|
281
278
|
}
|
282
279
|
return visitor;
|
283
280
|
}
|
284
|
-
function verify(visitor) {
|
281
|
+
function verify$1(visitor) {
|
285
282
|
if (visitor._verified) return;
|
286
283
|
if (typeof visitor === "function") {
|
287
284
|
throw new Error("You passed `traverse()` a function when it expected a visitor object, " + "are you sure you didn't mean `{ enter: Function }`?");
|
@@ -291,8 +288,8 @@ function verify(visitor) {
|
|
291
288
|
validateVisitorMethods(nodeType, visitor[nodeType]);
|
292
289
|
}
|
293
290
|
if (shouldIgnoreKey(nodeType)) continue;
|
294
|
-
if (TYPES.
|
295
|
-
throw new Error(`You gave us a visitor for the node type ${nodeType} but it's not a valid type`);
|
291
|
+
if (!TYPES.includes(nodeType)) {
|
292
|
+
throw new Error(`You gave us a visitor for the node type ${nodeType} but it's not a valid type in @babel/traverse ${"8.0.0-beta.0"}`);
|
296
293
|
}
|
297
294
|
const visitors = visitor[nodeType];
|
298
295
|
if (typeof visitors === "object") {
|
@@ -316,9 +313,12 @@ function validateVisitorMethods(path, val) {
|
|
316
313
|
}
|
317
314
|
}
|
318
315
|
function merge(visitors, states = [], wrapper) {
|
319
|
-
const mergedVisitor = {
|
316
|
+
const mergedVisitor = {
|
317
|
+
_verified: true,
|
318
|
+
_exploded: true
|
319
|
+
};
|
320
320
|
for (let i = 0; i < visitors.length; i++) {
|
321
|
-
const visitor = explode(visitors[i]);
|
321
|
+
const visitor = explode$1(visitors[i]);
|
322
322
|
const state = states[i];
|
323
323
|
let topVisitor = visitor;
|
324
324
|
if (state || wrapper) {
|
@@ -335,12 +335,7 @@ function merge(visitors, states = [], wrapper) {
|
|
335
335
|
mergePair(nodeVisitor, typeVisitor);
|
336
336
|
}
|
337
337
|
}
|
338
|
-
|
339
|
-
return Object.assign({}, mergedVisitor, {
|
340
|
-
_exploded: true,
|
341
|
-
_verified: true
|
342
|
-
});
|
343
|
-
}
|
338
|
+
return mergedVisitor;
|
344
339
|
}
|
345
340
|
function wrapWithStateOrWrapper(oldVisitor, state, wrapper) {
|
346
341
|
const newVisitor = {};
|
@@ -406,50 +401,40 @@ function mergePair(dest, src) {
|
|
406
401
|
dest[phase] = [].concat(dest[phase] || [], src[phase]);
|
407
402
|
}
|
408
403
|
}
|
404
|
+
const _environmentVisitor = {
|
405
|
+
FunctionParent(path) {
|
406
|
+
if (path.isArrowFunctionExpression()) return;
|
407
|
+
path.skip();
|
408
|
+
if (path.isMethod()) {
|
409
|
+
{
|
410
|
+
path.requeueComputedKeyAndDecorators();
|
411
|
+
}
|
412
|
+
}
|
413
|
+
},
|
414
|
+
Property(path) {
|
415
|
+
if (path.isObjectProperty()) return;
|
416
|
+
path.skip();
|
417
|
+
{
|
418
|
+
path.requeueComputedKeyAndDecorators();
|
419
|
+
}
|
420
|
+
}
|
421
|
+
};
|
422
|
+
function environmentVisitor(visitor) {
|
423
|
+
return merge([_environmentVisitor, visitor]);
|
424
|
+
}
|
409
425
|
|
410
426
|
var visitors = /*#__PURE__*/Object.freeze({
|
411
427
|
__proto__: null,
|
412
|
-
|
428
|
+
environmentVisitor: environmentVisitor,
|
429
|
+
explode: explode$1,
|
413
430
|
isExplodedVisitor: isExplodedVisitor,
|
414
431
|
merge: merge,
|
415
|
-
verify: verify
|
416
|
-
});
|
417
|
-
|
418
|
-
let pathsCache = new WeakMap();
|
419
|
-
let scope = new WeakMap();
|
420
|
-
function clear() {
|
421
|
-
clearPath();
|
422
|
-
clearScope();
|
423
|
-
}
|
424
|
-
function clearPath() {
|
425
|
-
pathsCache = new WeakMap();
|
426
|
-
}
|
427
|
-
function clearScope() {
|
428
|
-
scope = new WeakMap();
|
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
|
-
}
|
441
|
-
|
442
|
-
var cache = /*#__PURE__*/Object.freeze({
|
443
|
-
__proto__: null,
|
444
|
-
clear: clear,
|
445
|
-
clearPath: clearPath,
|
446
|
-
clearScope: clearScope,
|
447
|
-
getCachedPaths: getCachedPaths,
|
448
|
-
getOrCreateCachedPaths: getOrCreateCachedPaths,
|
449
|
-
get path () { return pathsCache; },
|
450
|
-
get scope () { return scope; }
|
432
|
+
verify: verify$1
|
451
433
|
});
|
452
434
|
|
435
|
+
const {
|
436
|
+
getAssignmentIdentifiers: getAssignmentIdentifiers$1
|
437
|
+
} = _t;
|
453
438
|
const renameVisitor = {
|
454
439
|
ReferencedIdentifier({
|
455
440
|
node
|
@@ -462,7 +447,9 @@ const renameVisitor = {
|
|
462
447
|
if (!path.scope.bindingIdentifierEquals(state.oldName, state.binding.identifier)) {
|
463
448
|
path.skip();
|
464
449
|
if (path.isMethod()) {
|
465
|
-
|
450
|
+
{
|
451
|
+
path.requeueComputedKeyAndDecorators();
|
452
|
+
}
|
466
453
|
}
|
467
454
|
}
|
468
455
|
},
|
@@ -475,12 +462,11 @@ const renameVisitor = {
|
|
475
462
|
} = node.key;
|
476
463
|
if (node.shorthand && (name === state.oldName || name === state.newName) && scope.getBindingIdentifier(name) === state.binding.identifier) {
|
477
464
|
node.shorthand = false;
|
478
|
-
if (node.extra?.shorthand) node.extra.shorthand = false;
|
479
465
|
}
|
480
466
|
},
|
481
467
|
"AssignmentExpression|Declaration|VariableDeclarator"(path, state) {
|
482
468
|
if (path.isVariableDeclaration()) return;
|
483
|
-
const ids = path.getOuterBindingIdentifiers();
|
469
|
+
const ids = path.isAssignmentExpression() ? getAssignmentIdentifiers$1(path.node) : path.getOuterBindingIdentifiers();
|
484
470
|
for (const name in ids) {
|
485
471
|
if (name === state.oldName) ids[name].name = state.newName;
|
486
472
|
}
|
@@ -508,7 +494,7 @@ class Renamer {
|
|
508
494
|
if (maybeExportDeclar.isExportAllDeclaration()) {
|
509
495
|
return;
|
510
496
|
}
|
511
|
-
splitExportDeclaration(
|
497
|
+
maybeExportDeclar.splitExportDeclaration();
|
512
498
|
}
|
513
499
|
maybeConvertFromClassFunctionDeclaration(path) {
|
514
500
|
return path;
|
@@ -534,9 +520,18 @@ class Renamer {
|
|
534
520
|
}
|
535
521
|
}
|
536
522
|
const blockToTraverse = scope.block;
|
537
|
-
|
523
|
+
const skipKeys = {
|
538
524
|
discriminant: true
|
539
|
-
}
|
525
|
+
};
|
526
|
+
if (_t.isMethod(blockToTraverse)) {
|
527
|
+
if (blockToTraverse.computed) {
|
528
|
+
skipKeys.key = true;
|
529
|
+
}
|
530
|
+
if (!_t.isObjectMethod(blockToTraverse)) {
|
531
|
+
skipKeys.decorators = true;
|
532
|
+
}
|
533
|
+
}
|
534
|
+
traverseNode(blockToTraverse, explode$1(renameVisitor), scope, this, scope.path, skipKeys);
|
540
535
|
{
|
541
536
|
scope.removeOwnBinding(oldName);
|
542
537
|
scope.bindings[newName] = binding;
|
@@ -564,7 +559,7 @@ class Binding {
|
|
564
559
|
this.scope = scope;
|
565
560
|
this.path = path;
|
566
561
|
this.kind = kind;
|
567
|
-
if ((kind === "var" || kind === "hoisted") &&
|
562
|
+
if ((kind === "var" || kind === "hoisted") && isInitInLoop(path)) {
|
568
563
|
this.reassign(path);
|
569
564
|
}
|
570
565
|
this.clearValue();
|
@@ -590,13 +585,13 @@ class Binding {
|
|
590
585
|
}
|
591
586
|
reassign(path) {
|
592
587
|
this.constant = false;
|
593
|
-
if (this.constantViolations.
|
588
|
+
if (this.constantViolations.includes(path)) {
|
594
589
|
return;
|
595
590
|
}
|
596
591
|
this.constantViolations.push(path);
|
597
592
|
}
|
598
593
|
reference(path) {
|
599
|
-
if (this.referencePaths.
|
594
|
+
if (this.referencePaths.includes(path)) {
|
600
595
|
return;
|
601
596
|
}
|
602
597
|
this.referenced = true;
|
@@ -608,24 +603,64 @@ class Binding {
|
|
608
603
|
this.referenced = !!this.references;
|
609
604
|
}
|
610
605
|
}
|
611
|
-
function
|
606
|
+
function isInitInLoop(path) {
|
607
|
+
const isFunctionDeclarationOrHasInit = !path.isVariableDeclarator() || path.node.init;
|
612
608
|
for (let {
|
613
609
|
parentPath,
|
614
610
|
key
|
615
|
-
} = path; parentPath;
|
611
|
+
} = path; parentPath; {
|
616
612
|
parentPath,
|
617
613
|
key
|
618
|
-
} = parentPath)
|
614
|
+
} = parentPath) {
|
619
615
|
if (parentPath.isFunctionParent()) return false;
|
620
|
-
if (
|
616
|
+
if (key === "left" && parentPath.isForXStatement() || isFunctionDeclarationOrHasInit && key === "body" && parentPath.isLoop()) {
|
621
617
|
return true;
|
622
618
|
}
|
623
619
|
}
|
624
620
|
return false;
|
625
621
|
}
|
626
622
|
|
623
|
+
let pathsCache = new WeakMap();
|
624
|
+
let scope = new WeakMap();
|
625
|
+
function clear() {
|
626
|
+
clearPath();
|
627
|
+
clearScope();
|
628
|
+
}
|
629
|
+
function clearPath() {
|
630
|
+
pathsCache = new WeakMap();
|
631
|
+
}
|
632
|
+
function clearScope() {
|
633
|
+
scope = new WeakMap();
|
634
|
+
}
|
635
|
+
function getCachedPaths(path) {
|
636
|
+
const {
|
637
|
+
parent,
|
638
|
+
parentPath
|
639
|
+
} = path;
|
640
|
+
return parentPath ? parentPath._store : pathsCache.get(parent);
|
641
|
+
}
|
642
|
+
function getOrCreateCachedPaths(node, parentPath) {
|
643
|
+
if (parentPath) {
|
644
|
+
return parentPath._store ||= new Map();
|
645
|
+
}
|
646
|
+
let paths = pathsCache.get(node);
|
647
|
+
if (!paths) pathsCache.set(node, paths = new Map());
|
648
|
+
return paths;
|
649
|
+
}
|
650
|
+
|
651
|
+
var cache = /*#__PURE__*/Object.freeze({
|
652
|
+
__proto__: null,
|
653
|
+
clear: clear,
|
654
|
+
clearPath: clearPath,
|
655
|
+
clearScope: clearScope,
|
656
|
+
getCachedPaths: getCachedPaths,
|
657
|
+
getOrCreateCachedPaths: getOrCreateCachedPaths,
|
658
|
+
get path () { return pathsCache; },
|
659
|
+
get scope () { return scope; }
|
660
|
+
});
|
661
|
+
|
627
662
|
const {
|
628
|
-
|
663
|
+
assignmentExpression: assignmentExpression$3,
|
629
664
|
callExpression: callExpression$3,
|
630
665
|
cloneNode: cloneNode$3,
|
631
666
|
getBindingIdentifiers: getBindingIdentifiers$3,
|
@@ -657,6 +692,7 @@ const {
|
|
657
692
|
isThisExpression,
|
658
693
|
isUnaryExpression,
|
659
694
|
isVariableDeclaration: isVariableDeclaration$1,
|
695
|
+
expressionStatement: expressionStatement$3,
|
660
696
|
matchesPattern: matchesPattern$1,
|
661
697
|
memberExpression: memberExpression$1,
|
662
698
|
numericLiteral: numericLiteral$2,
|
@@ -670,7 +706,8 @@ const {
|
|
670
706
|
isMetaProperty,
|
671
707
|
isPrivateName,
|
672
708
|
isExportDeclaration,
|
673
|
-
buildUndefinedNode: buildUndefinedNode$1
|
709
|
+
buildUndefinedNode: buildUndefinedNode$1,
|
710
|
+
sequenceExpression: sequenceExpression$2
|
674
711
|
} = _t;
|
675
712
|
function gatherNodeParts(node, parts) {
|
676
713
|
switch (node?.type) {
|
@@ -786,6 +823,14 @@ function gatherNodeParts(node, parts) {
|
|
786
823
|
break;
|
787
824
|
}
|
788
825
|
}
|
826
|
+
function resetScope(scope) {
|
827
|
+
if (scope.path.type === "Program") {
|
828
|
+
scope.referencesSet = new Set();
|
829
|
+
scope.uidsSet = new Set();
|
830
|
+
}
|
831
|
+
scope.bindings = Object.create(null);
|
832
|
+
scope.globals = Object.create(null);
|
833
|
+
}
|
789
834
|
const collectorVisitor = {
|
790
835
|
ForStatement(path) {
|
791
836
|
const declar = path.get("init");
|
@@ -808,7 +853,15 @@ const collectorVisitor = {
|
|
808
853
|
const parent = path.scope.getBlockParent();
|
809
854
|
parent.registerDeclaration(path);
|
810
855
|
},
|
856
|
+
TSImportEqualsDeclaration(path) {
|
857
|
+
const parent = path.scope.getBlockParent();
|
858
|
+
parent.registerDeclaration(path);
|
859
|
+
},
|
811
860
|
ReferencedIdentifier(path, state) {
|
861
|
+
if (_t.isTSQualifiedName(path.parent) && path.parent.right === path.node) {
|
862
|
+
return;
|
863
|
+
}
|
864
|
+
if (path.parentPath.isTSImportEqualsDeclaration()) return;
|
812
865
|
state.references.push(path);
|
813
866
|
},
|
814
867
|
ForXStatement(path, state) {
|
@@ -879,27 +932,31 @@ const collectorVisitor = {
|
|
879
932
|
for (const param of params) {
|
880
933
|
path.scope.registerBinding("param", param);
|
881
934
|
}
|
882
|
-
if (path.isFunctionExpression() && path.
|
935
|
+
if (path.isFunctionExpression() && path.node.id) {
|
883
936
|
path.scope.registerBinding("local", path.get("id"), path);
|
884
937
|
}
|
885
938
|
},
|
886
939
|
ClassExpression(path) {
|
887
|
-
if (path.
|
888
|
-
path.scope.registerBinding("local", path);
|
940
|
+
if (path.node.id) {
|
941
|
+
path.scope.registerBinding("local", path.get("id"), path);
|
889
942
|
}
|
943
|
+
},
|
944
|
+
TSTypeAnnotation(path) {
|
945
|
+
path.skip();
|
890
946
|
}
|
891
947
|
};
|
948
|
+
let scopeVisitor;
|
892
949
|
let uid = 0;
|
893
950
|
class Scope {
|
894
951
|
uid;
|
895
952
|
path;
|
896
953
|
block;
|
897
|
-
labels;
|
898
954
|
inited;
|
955
|
+
labels;
|
899
956
|
bindings;
|
900
|
-
|
957
|
+
referencesSet;
|
901
958
|
globals;
|
902
|
-
|
959
|
+
uidsSet;
|
903
960
|
data;
|
904
961
|
crawling;
|
905
962
|
constructor(path) {
|
@@ -926,18 +983,15 @@ class Scope {
|
|
926
983
|
const shouldSkip = path.key === "key" || path.listKey === "decorators";
|
927
984
|
path = path.parentPath;
|
928
985
|
if (shouldSkip && path.isMethod()) path = path.parentPath;
|
929
|
-
if (path
|
986
|
+
if (path?.isScope()) parent = path;
|
930
987
|
} while (path && !parent);
|
931
988
|
return parent?.scope;
|
932
989
|
}
|
933
|
-
get
|
934
|
-
|
990
|
+
get references() {
|
991
|
+
throw new Error("Scope#references is not available in Babel 8. Use Scope#referencesSet instead.");
|
935
992
|
}
|
936
|
-
get
|
937
|
-
|
938
|
-
}
|
939
|
-
traverse(node, opts, state) {
|
940
|
-
traverse(node, opts, this, state, this.path);
|
993
|
+
get uids() {
|
994
|
+
throw new Error("Scope#uids is not available in Babel 8. Use Scope#uidsSet instead.");
|
941
995
|
}
|
942
996
|
generateDeclaredUidIdentifier(name) {
|
943
997
|
const id = this.generateUidIdentifier(name);
|
@@ -950,23 +1004,21 @@ class Scope {
|
|
950
1004
|
return identifier$3(this.generateUid(name));
|
951
1005
|
}
|
952
1006
|
generateUid(name = "temp") {
|
953
|
-
name = toIdentifier(name).replace(/^_+/, "").replace(
|
1007
|
+
name = toIdentifier(name).replace(/^_+/, "").replace(/\d+$/g, "");
|
954
1008
|
let uid;
|
955
|
-
let i =
|
1009
|
+
let i = 0;
|
956
1010
|
do {
|
957
|
-
uid =
|
1011
|
+
uid = `_${name}`;
|
1012
|
+
if (i >= 11) uid += i - 1;else if (i >= 9) uid += i - 9;else if (i >= 1) uid += i + 1;
|
958
1013
|
i++;
|
959
1014
|
} while (this.hasLabel(uid) || this.hasBinding(uid) || this.hasGlobal(uid) || this.hasReference(uid));
|
960
1015
|
const program = this.getProgramParent();
|
961
|
-
|
962
|
-
|
1016
|
+
{
|
1017
|
+
program.referencesSet.add(uid);
|
1018
|
+
program.uidsSet.add(uid);
|
1019
|
+
}
|
963
1020
|
return uid;
|
964
1021
|
}
|
965
|
-
_generateUid(name, i) {
|
966
|
-
let id = name;
|
967
|
-
if (i > 1) id += i;
|
968
|
-
return `_${id}`;
|
969
|
-
}
|
970
1022
|
generateUidBasedOnNode(node, defaultName) {
|
971
1023
|
const parts = [];
|
972
1024
|
gatherNodeParts(node, parts);
|
@@ -1010,7 +1062,7 @@ class Scope {
|
|
1010
1062
|
if (local.kind === "local") return;
|
1011
1063
|
const duplicate = kind === "let" || local.kind === "let" || local.kind === "const" || local.kind === "module" || local.kind === "param" && kind === "const";
|
1012
1064
|
if (duplicate) {
|
1013
|
-
throw this.hub.buildError(id, `Duplicate declaration "${name}"`, TypeError);
|
1065
|
+
throw this.path.hub.buildError(id, `Duplicate declaration "${name}"`, TypeError);
|
1014
1066
|
}
|
1015
1067
|
}
|
1016
1068
|
rename(oldName, newName) {
|
@@ -1023,12 +1075,6 @@ class Scope {
|
|
1023
1075
|
}
|
1024
1076
|
}
|
1025
1077
|
}
|
1026
|
-
_renameFromMap(map, oldName, newName, value) {
|
1027
|
-
if (map[oldName]) {
|
1028
|
-
map[newName] = value;
|
1029
|
-
map[oldName] = null;
|
1030
|
-
}
|
1031
|
-
}
|
1032
1078
|
dump() {
|
1033
1079
|
const sep = "-".repeat(60);
|
1034
1080
|
console.log(sep);
|
@@ -1047,37 +1093,6 @@ class Scope {
|
|
1047
1093
|
} while (scope = scope.parent);
|
1048
1094
|
console.log(sep);
|
1049
1095
|
}
|
1050
|
-
toArray(node, i, arrayLikeIsIterable) {
|
1051
|
-
if (isIdentifier$5(node)) {
|
1052
|
-
const binding = this.getBinding(node.name);
|
1053
|
-
if (binding?.constant && binding.path.isGenericType("Array")) {
|
1054
|
-
return node;
|
1055
|
-
}
|
1056
|
-
}
|
1057
|
-
if (isArrayExpression(node)) {
|
1058
|
-
return node;
|
1059
|
-
}
|
1060
|
-
if (isIdentifier$5(node, {
|
1061
|
-
name: "arguments"
|
1062
|
-
})) {
|
1063
|
-
return callExpression$3(memberExpression$1(memberExpression$1(memberExpression$1(identifier$3("Array"), identifier$3("prototype")), identifier$3("slice")), identifier$3("call")), [node]);
|
1064
|
-
}
|
1065
|
-
let helperName;
|
1066
|
-
const args = [node];
|
1067
|
-
if (i === true) {
|
1068
|
-
helperName = "toConsumableArray";
|
1069
|
-
} else if (typeof i === "number") {
|
1070
|
-
args.push(numericLiteral$2(i));
|
1071
|
-
helperName = "slicedToArray";
|
1072
|
-
} else {
|
1073
|
-
helperName = "toArray";
|
1074
|
-
}
|
1075
|
-
if (arrayLikeIsIterable) {
|
1076
|
-
args.unshift(this.hub.addHelper(helperName));
|
1077
|
-
helperName = "maybeArrayLike";
|
1078
|
-
}
|
1079
|
-
return callExpression$3(this.hub.addHelper(helperName), args);
|
1080
|
-
}
|
1081
1096
|
hasLabel(name) {
|
1082
1097
|
return !!this.getLabel(name);
|
1083
1098
|
}
|
@@ -1123,7 +1138,7 @@ class Scope {
|
|
1123
1138
|
return buildUndefinedNode$1();
|
1124
1139
|
}
|
1125
1140
|
registerConstantViolation(path) {
|
1126
|
-
const ids = path.
|
1141
|
+
const ids = path.getAssignmentIdentifiers();
|
1127
1142
|
for (const name of Object.keys(ids)) {
|
1128
1143
|
this.getBinding(name)?.reassign(path);
|
1129
1144
|
}
|
@@ -1140,7 +1155,9 @@ class Scope {
|
|
1140
1155
|
const parent = this.getProgramParent();
|
1141
1156
|
const ids = path.getOuterBindingIdentifiers(true);
|
1142
1157
|
for (const name of Object.keys(ids)) {
|
1143
|
-
|
1158
|
+
{
|
1159
|
+
parent.referencesSet.add(name);
|
1160
|
+
}
|
1144
1161
|
for (const id of ids[name]) {
|
1145
1162
|
const local = this.getOwnBinding(name);
|
1146
1163
|
if (local) {
|
@@ -1148,7 +1165,7 @@ class Scope {
|
|
1148
1165
|
this.checkBlockScopedCollisions(local, kind, name, id);
|
1149
1166
|
}
|
1150
1167
|
if (local) {
|
1151
|
-
|
1168
|
+
local.reassign(bindingPath);
|
1152
1169
|
} else {
|
1153
1170
|
this.bindings[name] = new Binding({
|
1154
1171
|
identifier: id,
|
@@ -1164,11 +1181,9 @@ class Scope {
|
|
1164
1181
|
this.globals[node.name] = node;
|
1165
1182
|
}
|
1166
1183
|
hasUid(name) {
|
1167
|
-
|
1168
|
-
|
1169
|
-
|
1170
|
-
} while (scope = scope.parent);
|
1171
|
-
return false;
|
1184
|
+
{
|
1185
|
+
return this.getProgramParent().uidsSet.has(name);
|
1186
|
+
}
|
1172
1187
|
}
|
1173
1188
|
hasGlobal(name) {
|
1174
1189
|
let scope = this;
|
@@ -1178,7 +1193,9 @@ class Scope {
|
|
1178
1193
|
return false;
|
1179
1194
|
}
|
1180
1195
|
hasReference(name) {
|
1181
|
-
|
1196
|
+
{
|
1197
|
+
return this.getProgramParent().referencesSet.has(name);
|
1198
|
+
}
|
1182
1199
|
}
|
1183
1200
|
isPure(node, constantsOnly) {
|
1184
1201
|
if (isIdentifier$5(node)) {
|
@@ -1278,34 +1295,42 @@ class Scope {
|
|
1278
1295
|
}
|
1279
1296
|
crawl() {
|
1280
1297
|
const path = this.path;
|
1281
|
-
this
|
1282
|
-
this.bindings = Object.create(null);
|
1283
|
-
this.globals = Object.create(null);
|
1284
|
-
this.uids = Object.create(null);
|
1298
|
+
resetScope(this);
|
1285
1299
|
this.data = Object.create(null);
|
1286
|
-
|
1287
|
-
|
1300
|
+
let scope = this;
|
1301
|
+
do {
|
1302
|
+
if (scope.crawling) return;
|
1303
|
+
if (scope.path.isProgram()) {
|
1304
|
+
break;
|
1305
|
+
}
|
1306
|
+
} while (scope = scope.parent);
|
1307
|
+
const programParent = scope;
|
1288
1308
|
const state = {
|
1289
1309
|
references: [],
|
1290
1310
|
constantViolations: [],
|
1291
1311
|
assignments: []
|
1292
1312
|
};
|
1293
1313
|
this.crawling = true;
|
1294
|
-
|
1295
|
-
|
1314
|
+
scopeVisitor ||= traverse.visitors.merge([{
|
1315
|
+
Scope(path) {
|
1316
|
+
resetScope(path.scope);
|
1317
|
+
}
|
1318
|
+
}, collectorVisitor]);
|
1319
|
+
if (path.type !== "Program") {
|
1320
|
+
for (const visit of scopeVisitor.enter) {
|
1296
1321
|
visit.call(state, path, state);
|
1297
1322
|
}
|
1298
|
-
const typeVisitors =
|
1323
|
+
const typeVisitors = scopeVisitor[path.type];
|
1299
1324
|
if (typeVisitors) {
|
1300
1325
|
for (const visit of typeVisitors.enter) {
|
1301
1326
|
visit.call(state, path, state);
|
1302
1327
|
}
|
1303
1328
|
}
|
1304
1329
|
}
|
1305
|
-
path.traverse(
|
1330
|
+
path.traverse(scopeVisitor, state);
|
1306
1331
|
this.crawling = false;
|
1307
1332
|
for (const path of state.assignments) {
|
1308
|
-
const ids = path.
|
1333
|
+
const ids = path.getAssignmentIdentifiers();
|
1309
1334
|
for (const name of Object.keys(ids)) {
|
1310
1335
|
if (path.scope.getBinding(name)) continue;
|
1311
1336
|
programParent.addGlobal(ids[name]);
|
@@ -1413,20 +1438,6 @@ class Scope {
|
|
1413
1438
|
} while (scope);
|
1414
1439
|
return ids;
|
1415
1440
|
}
|
1416
|
-
getAllBindingsOfKind(...kinds) {
|
1417
|
-
const ids = Object.create(null);
|
1418
|
-
for (const kind of kinds) {
|
1419
|
-
let scope = this;
|
1420
|
-
do {
|
1421
|
-
for (const name of Object.keys(scope.bindings)) {
|
1422
|
-
const binding = scope.bindings[name];
|
1423
|
-
if (binding.kind === kind) ids[name] = binding;
|
1424
|
-
}
|
1425
|
-
scope = scope.parent;
|
1426
|
-
} while (scope);
|
1427
|
-
}
|
1428
|
-
return ids;
|
1429
|
-
}
|
1430
1441
|
bindingIdentifierEquals(name, node) {
|
1431
1442
|
return this.getBindingIdentifier(name) === node;
|
1432
1443
|
}
|
@@ -1460,16 +1471,28 @@ class Scope {
|
|
1460
1471
|
}
|
1461
1472
|
hasBinding(name, opts) {
|
1462
1473
|
if (!name) return false;
|
1463
|
-
|
1464
|
-
|
1465
|
-
|
1466
|
-
|
1467
|
-
|
1474
|
+
let noGlobals;
|
1475
|
+
let noUids;
|
1476
|
+
let upToScope;
|
1477
|
+
if (typeof opts === "object") {
|
1478
|
+
noGlobals = opts.noGlobals;
|
1479
|
+
noUids = opts.noUids;
|
1480
|
+
upToScope = opts.upToScope;
|
1481
|
+
} else if (typeof opts === "boolean") {
|
1482
|
+
noGlobals = opts;
|
1468
1483
|
}
|
1469
|
-
|
1470
|
-
|
1471
|
-
|
1472
|
-
|
1484
|
+
let scope = this;
|
1485
|
+
do {
|
1486
|
+
if (upToScope === scope) {
|
1487
|
+
break;
|
1488
|
+
}
|
1489
|
+
if (scope.hasOwnBinding(name)) {
|
1490
|
+
return true;
|
1491
|
+
}
|
1492
|
+
} while (scope = scope.parent);
|
1493
|
+
if (!noUids && this.hasUid(name)) return true;
|
1494
|
+
if (!noGlobals && Scope.globals.includes(name)) return true;
|
1495
|
+
if (!noGlobals && Scope.contextVariables.includes(name)) return true;
|
1473
1496
|
return false;
|
1474
1497
|
}
|
1475
1498
|
parentHasBinding(name, opts) {
|
@@ -1488,12 +1511,57 @@ class Scope {
|
|
1488
1511
|
}
|
1489
1512
|
removeBinding(name) {
|
1490
1513
|
this.getBinding(name)?.scope.removeOwnBinding(name);
|
1491
|
-
|
1492
|
-
|
1493
|
-
|
1494
|
-
|
1514
|
+
{
|
1515
|
+
this.getProgramParent().uidsSet.delete(name);
|
1516
|
+
}
|
1517
|
+
}
|
1518
|
+
hoistVariables(emit = id => this.push({
|
1519
|
+
id
|
1520
|
+
})) {
|
1521
|
+
this.crawl();
|
1522
|
+
const seen = new Set();
|
1523
|
+
for (const name of Object.keys(this.bindings)) {
|
1524
|
+
const binding = this.bindings[name];
|
1525
|
+
if (!binding) continue;
|
1526
|
+
const {
|
1527
|
+
path
|
1528
|
+
} = binding;
|
1529
|
+
if (!path.isVariableDeclarator()) continue;
|
1530
|
+
const {
|
1531
|
+
parent,
|
1532
|
+
parentPath
|
1533
|
+
} = path;
|
1534
|
+
if (parent.kind !== "var" || seen.has(parent)) continue;
|
1535
|
+
seen.add(path.parent);
|
1536
|
+
let firstId;
|
1537
|
+
const init = [];
|
1538
|
+
for (const decl of parent.declarations) {
|
1539
|
+
firstId ??= decl.id;
|
1540
|
+
if (decl.init) {
|
1541
|
+
init.push(assignmentExpression$3("=", decl.id, decl.init));
|
1542
|
+
}
|
1543
|
+
const ids = Object.keys(getBindingIdentifiers$3(decl, false, true, true));
|
1544
|
+
for (const name of ids) {
|
1545
|
+
emit(identifier$3(name), decl.init != null);
|
1546
|
+
}
|
1495
1547
|
}
|
1496
|
-
|
1548
|
+
if (parentPath.parentPath.isFor({
|
1549
|
+
left: parent
|
1550
|
+
})) {
|
1551
|
+
parentPath.replaceWith(firstId);
|
1552
|
+
} else if (init.length === 0) {
|
1553
|
+
parentPath.remove();
|
1554
|
+
} else {
|
1555
|
+
const expr = init.length === 1 ? init[0] : sequenceExpression$2(init);
|
1556
|
+
if (parentPath.parentPath.isForStatement({
|
1557
|
+
init: parent
|
1558
|
+
})) {
|
1559
|
+
parentPath.replaceWith(expr);
|
1560
|
+
} else {
|
1561
|
+
parentPath.replaceWith(expressionStatement$3(expr));
|
1562
|
+
}
|
1563
|
+
}
|
1564
|
+
}
|
1497
1565
|
}
|
1498
1566
|
}
|
1499
1567
|
|
@@ -1613,28 +1681,12 @@ function isDescendant(maybeAncestor) {
|
|
1613
1681
|
function inType(...candidateTypes) {
|
1614
1682
|
let path = this;
|
1615
1683
|
while (path) {
|
1616
|
-
|
1617
|
-
if (path.node.type === type) return true;
|
1618
|
-
}
|
1684
|
+
if (candidateTypes.includes(path.node.type)) return true;
|
1619
1685
|
path = path.parentPath;
|
1620
1686
|
}
|
1621
1687
|
return false;
|
1622
1688
|
}
|
1623
1689
|
|
1624
|
-
var NodePath_ancestry = /*#__PURE__*/Object.freeze({
|
1625
|
-
__proto__: null,
|
1626
|
-
find: find,
|
1627
|
-
findParent: findParent,
|
1628
|
-
getAncestry: getAncestry,
|
1629
|
-
getDeepestCommonAncestorFrom: getDeepestCommonAncestorFrom,
|
1630
|
-
getEarliestCommonAncestorFrom: getEarliestCommonAncestorFrom,
|
1631
|
-
getFunctionParent: getFunctionParent,
|
1632
|
-
getStatementParent: getStatementParent,
|
1633
|
-
inType: inType,
|
1634
|
-
isAncestor: isAncestor,
|
1635
|
-
isDescendant: isDescendant
|
1636
|
-
});
|
1637
|
-
|
1638
1690
|
const {
|
1639
1691
|
createFlowUnionType,
|
1640
1692
|
createTSUnionType,
|
@@ -1682,7 +1734,7 @@ function getTypeAnnotationBindingConstantViolations(binding, path, name) {
|
|
1682
1734
|
const testType = getConditionalAnnotation(binding, path, name);
|
1683
1735
|
if (testType) {
|
1684
1736
|
const testConstantViolations = getConstantViolationsBefore(binding, testType.ifStatement);
|
1685
|
-
constantViolations = constantViolations.filter(path => testConstantViolations.
|
1737
|
+
constantViolations = constantViolations.filter(path => !testConstantViolations.includes(path));
|
1686
1738
|
types.push(testType.typeAnnotation);
|
1687
1739
|
}
|
1688
1740
|
if (constantViolations.length) {
|
@@ -1724,7 +1776,7 @@ function inferAnnotationFromBinaryExpression(name, path) {
|
|
1724
1776
|
if (operator === "===") {
|
1725
1777
|
return target.getTypeAnnotation();
|
1726
1778
|
}
|
1727
|
-
if (BOOLEAN_NUMBER_BINARY_OPERATORS.
|
1779
|
+
if (BOOLEAN_NUMBER_BINARY_OPERATORS.includes(operator)) {
|
1728
1780
|
return numberTypeAnnotation$1();
|
1729
1781
|
}
|
1730
1782
|
return;
|
@@ -1842,19 +1894,19 @@ function UnaryExpression(node) {
|
|
1842
1894
|
const operator = node.operator;
|
1843
1895
|
if (operator === "void") {
|
1844
1896
|
return voidTypeAnnotation$1();
|
1845
|
-
} else if (NUMBER_UNARY_OPERATORS.
|
1897
|
+
} else if (NUMBER_UNARY_OPERATORS.includes(operator)) {
|
1846
1898
|
return numberTypeAnnotation();
|
1847
|
-
} else if (STRING_UNARY_OPERATORS.
|
1899
|
+
} else if (STRING_UNARY_OPERATORS.includes(operator)) {
|
1848
1900
|
return stringTypeAnnotation$1();
|
1849
|
-
} else if (BOOLEAN_UNARY_OPERATORS.
|
1901
|
+
} else if (BOOLEAN_UNARY_OPERATORS.includes(operator)) {
|
1850
1902
|
return booleanTypeAnnotation();
|
1851
1903
|
}
|
1852
1904
|
}
|
1853
1905
|
function BinaryExpression(node) {
|
1854
1906
|
const operator = node.operator;
|
1855
|
-
if (NUMBER_BINARY_OPERATORS.
|
1907
|
+
if (NUMBER_BINARY_OPERATORS.includes(operator)) {
|
1856
1908
|
return numberTypeAnnotation();
|
1857
|
-
} else if (BOOLEAN_BINARY_OPERATORS.
|
1909
|
+
} else if (BOOLEAN_BINARY_OPERATORS.includes(operator)) {
|
1858
1910
|
return booleanTypeAnnotation();
|
1859
1911
|
} else if (operator === "+") {
|
1860
1912
|
const right = this.get("right");
|
@@ -2023,7 +2075,7 @@ function getTypeAnnotation() {
|
|
2023
2075
|
if (type != null) {
|
2024
2076
|
return type;
|
2025
2077
|
}
|
2026
|
-
type =
|
2078
|
+
type = _getTypeAnnotation.call(this) || anyTypeAnnotation();
|
2027
2079
|
if (isTypeAnnotation(type) || isTSTypeAnnotation(type)) {
|
2028
2080
|
type = type.typeAnnotation;
|
2029
2081
|
}
|
@@ -2130,35 +2182,306 @@ function isGenericType(genericName) {
|
|
2130
2182
|
});
|
2131
2183
|
}
|
2132
2184
|
|
2133
|
-
|
2134
|
-
|
2135
|
-
|
2136
|
-
|
2137
|
-
|
2138
|
-
|
2139
|
-
|
2140
|
-
|
2141
|
-
|
2185
|
+
const hooks = [function (self, parent) {
|
2186
|
+
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();
|
2187
|
+
if (removeParent) {
|
2188
|
+
parent.remove();
|
2189
|
+
return true;
|
2190
|
+
}
|
2191
|
+
}, function (self, parent) {
|
2192
|
+
if (parent.isSequenceExpression() && parent.node.expressions.length === 1) {
|
2193
|
+
parent.replaceWith(parent.node.expressions[0]);
|
2194
|
+
return true;
|
2195
|
+
}
|
2196
|
+
}, function (self, parent) {
|
2197
|
+
if (parent.isBinary()) {
|
2198
|
+
if (self.key === "left") {
|
2199
|
+
parent.replaceWith(parent.node.right);
|
2200
|
+
} else {
|
2201
|
+
parent.replaceWith(parent.node.left);
|
2202
|
+
}
|
2203
|
+
return true;
|
2204
|
+
}
|
2205
|
+
}, function (self, parent) {
|
2206
|
+
if (parent.isIfStatement() && self.key === "consequent" || self.key === "body" && (parent.isLoop() || parent.isArrowFunctionExpression())) {
|
2207
|
+
self.replaceWith({
|
2208
|
+
type: "BlockStatement",
|
2209
|
+
body: []
|
2210
|
+
});
|
2211
|
+
return true;
|
2212
|
+
}
|
2213
|
+
}];
|
2214
|
+
|
2215
|
+
const {
|
2216
|
+
getBindingIdentifiers: getBindingIdentifiers$2
|
2217
|
+
} = _t;
|
2218
|
+
function remove() {
|
2219
|
+
_assertUnremoved.call(this);
|
2220
|
+
resync.call(this);
|
2221
|
+
if (_callRemovalHooks.call(this)) {
|
2222
|
+
_markRemoved.call(this);
|
2223
|
+
return;
|
2224
|
+
}
|
2225
|
+
if (!this.opts?.noScope) {
|
2226
|
+
_removeFromScope.call(this);
|
2227
|
+
}
|
2228
|
+
this.shareCommentsWithSiblings();
|
2229
|
+
_remove.call(this);
|
2230
|
+
_markRemoved.call(this);
|
2231
|
+
}
|
2232
|
+
function _removeFromScope() {
|
2233
|
+
const bindings = getBindingIdentifiers$2(this.node, false, false, true);
|
2234
|
+
Object.keys(bindings).forEach(name => this.scope.removeBinding(name));
|
2235
|
+
}
|
2236
|
+
function _callRemovalHooks() {
|
2237
|
+
if (this.parentPath) {
|
2238
|
+
for (const fn of hooks) {
|
2239
|
+
if (fn(this, this.parentPath)) return true;
|
2240
|
+
}
|
2241
|
+
}
|
2242
|
+
}
|
2243
|
+
function _remove() {
|
2244
|
+
if (Array.isArray(this.container)) {
|
2245
|
+
this.container.splice(this.key, 1);
|
2246
|
+
updateSiblingKeys.call(this, this.key, -1);
|
2247
|
+
} else {
|
2248
|
+
_replaceWith.call(this, null);
|
2249
|
+
}
|
2250
|
+
}
|
2251
|
+
function _markRemoved() {
|
2252
|
+
this._traverseFlags |= SHOULD_SKIP | REMOVED;
|
2253
|
+
if (this.parent) {
|
2254
|
+
getCachedPaths(this)?.delete(this.node);
|
2255
|
+
}
|
2256
|
+
this.node = null;
|
2257
|
+
}
|
2258
|
+
function _assertUnremoved() {
|
2259
|
+
if (this.removed) {
|
2260
|
+
throw this.buildCodeFrameError("NodePath has been removed so is read-only.");
|
2261
|
+
}
|
2262
|
+
}
|
2142
2263
|
|
2143
2264
|
const {
|
2144
|
-
FUNCTION_TYPES,
|
2145
2265
|
arrowFunctionExpression: arrowFunctionExpression$2,
|
2266
|
+
assertExpression,
|
2146
2267
|
assignmentExpression: assignmentExpression$2,
|
2147
|
-
awaitExpression,
|
2148
2268
|
blockStatement: blockStatement$2,
|
2149
|
-
buildUndefinedNode,
|
2150
2269
|
callExpression: callExpression$2,
|
2151
2270
|
cloneNode: cloneNode$2,
|
2152
|
-
conditionalExpression: conditionalExpression$1,
|
2153
2271
|
expressionStatement: expressionStatement$2,
|
2154
|
-
|
2155
|
-
|
2156
|
-
|
2272
|
+
isAssignmentExpression,
|
2273
|
+
isCallExpression,
|
2274
|
+
isExportNamedDeclaration,
|
2275
|
+
isExpression: isExpression$2,
|
2276
|
+
isIdentifier: isIdentifier$2,
|
2277
|
+
isSequenceExpression,
|
2278
|
+
isSuper,
|
2279
|
+
thisExpression: thisExpression$1
|
2280
|
+
} = _t;
|
2281
|
+
function insertBefore(nodes_) {
|
2282
|
+
_assertUnremoved.call(this);
|
2283
|
+
const nodes = _verifyNodeList.call(this, nodes_);
|
2284
|
+
const {
|
2285
|
+
parentPath,
|
2286
|
+
parent
|
2287
|
+
} = this;
|
2288
|
+
if (parentPath.isExpressionStatement() || parentPath.isLabeledStatement() || isExportNamedDeclaration(parent) || parentPath.isExportDefaultDeclaration() && this.isDeclaration()) {
|
2289
|
+
return parentPath.insertBefore(nodes);
|
2290
|
+
} else if (this.isNodeType("Expression") && !this.isJSXElement() || parentPath.isForStatement() && this.key === "init") {
|
2291
|
+
if (this.node) nodes.push(this.node);
|
2292
|
+
return this.replaceExpressionWithStatements(nodes);
|
2293
|
+
} else if (Array.isArray(this.container)) {
|
2294
|
+
return _containerInsertBefore.call(this, nodes);
|
2295
|
+
} else if (this.isStatementOrBlock()) {
|
2296
|
+
const node = this.node;
|
2297
|
+
const shouldInsertCurrentNode = node && (!this.isExpressionStatement() || node.expression != null);
|
2298
|
+
this.replaceWith(blockStatement$2(shouldInsertCurrentNode ? [node] : []));
|
2299
|
+
return this.unshiftContainer("body", nodes);
|
2300
|
+
} else {
|
2301
|
+
throw new Error("We don't know what to do with this node type. " + "We were previously a Statement but we can't fit in here?");
|
2302
|
+
}
|
2303
|
+
}
|
2304
|
+
function _containerInsert(from, nodes) {
|
2305
|
+
updateSiblingKeys.call(this, from, nodes.length);
|
2306
|
+
const paths = [];
|
2307
|
+
this.container.splice(from, 0, ...nodes);
|
2308
|
+
for (let i = 0; i < nodes.length; i++) {
|
2309
|
+
const to = from + i;
|
2310
|
+
const path = this.getSibling(to);
|
2311
|
+
paths.push(path);
|
2312
|
+
if (this.context?.queue) {
|
2313
|
+
pushContext.call(path, this.context);
|
2314
|
+
}
|
2315
|
+
}
|
2316
|
+
const contexts = _getQueueContexts.call(this);
|
2317
|
+
for (const path of paths) {
|
2318
|
+
setScope.call(path);
|
2319
|
+
path.debug("Inserted.");
|
2320
|
+
for (const context of contexts) {
|
2321
|
+
context.maybeQueue(path, true);
|
2322
|
+
}
|
2323
|
+
}
|
2324
|
+
return paths;
|
2325
|
+
}
|
2326
|
+
function _containerInsertBefore(nodes) {
|
2327
|
+
return _containerInsert.call(this, this.key, nodes);
|
2328
|
+
}
|
2329
|
+
function _containerInsertAfter(nodes) {
|
2330
|
+
return _containerInsert.call(this, this.key + 1, nodes);
|
2331
|
+
}
|
2332
|
+
const last = arr => arr[arr.length - 1];
|
2333
|
+
function isHiddenInSequenceExpression(path) {
|
2334
|
+
return isSequenceExpression(path.parent) && (last(path.parent.expressions) !== path.node || isHiddenInSequenceExpression(path.parentPath));
|
2335
|
+
}
|
2336
|
+
function isAlmostConstantAssignment(node, scope) {
|
2337
|
+
if (!isAssignmentExpression(node) || !isIdentifier$2(node.left)) {
|
2338
|
+
return false;
|
2339
|
+
}
|
2340
|
+
const blockScope = scope.getBlockParent();
|
2341
|
+
return blockScope.hasOwnBinding(node.left.name) && blockScope.getOwnBinding(node.left.name).constantViolations.length <= 1;
|
2342
|
+
}
|
2343
|
+
function insertAfter(nodes_) {
|
2344
|
+
_assertUnremoved.call(this);
|
2345
|
+
if (this.isSequenceExpression()) {
|
2346
|
+
return last(this.get("expressions")).insertAfter(nodes_);
|
2347
|
+
}
|
2348
|
+
const nodes = _verifyNodeList.call(this, nodes_);
|
2349
|
+
const {
|
2350
|
+
parentPath,
|
2351
|
+
parent
|
2352
|
+
} = this;
|
2353
|
+
if (parentPath.isExpressionStatement() || parentPath.isLabeledStatement() || isExportNamedDeclaration(parent) || parentPath.isExportDefaultDeclaration() && this.isDeclaration()) {
|
2354
|
+
return parentPath.insertAfter(nodes.map(node => {
|
2355
|
+
return isExpression$2(node) ? expressionStatement$2(node) : node;
|
2356
|
+
}));
|
2357
|
+
} else if (this.isNodeType("Expression") && !this.isJSXElement() && !parentPath.isJSXElement() || parentPath.isForStatement() && this.key === "init") {
|
2358
|
+
const self = this;
|
2359
|
+
if (self.node) {
|
2360
|
+
const node = self.node;
|
2361
|
+
let {
|
2362
|
+
scope
|
2363
|
+
} = this;
|
2364
|
+
if (scope.path.isPattern()) {
|
2365
|
+
assertExpression(node);
|
2366
|
+
self.replaceWith(callExpression$2(arrowFunctionExpression$2([], node), []));
|
2367
|
+
self.get("callee.body").insertAfter(nodes);
|
2368
|
+
return [self];
|
2369
|
+
}
|
2370
|
+
if (isHiddenInSequenceExpression(self)) {
|
2371
|
+
nodes.unshift(node);
|
2372
|
+
} else if (isCallExpression(node) && isSuper(node.callee)) {
|
2373
|
+
nodes.unshift(node);
|
2374
|
+
nodes.push(thisExpression$1());
|
2375
|
+
} else if (isAlmostConstantAssignment(node, scope)) {
|
2376
|
+
nodes.unshift(node);
|
2377
|
+
nodes.push(cloneNode$2(node.left));
|
2378
|
+
} else if (scope.isPure(node, true)) {
|
2379
|
+
nodes.push(node);
|
2380
|
+
} else {
|
2381
|
+
if (parentPath.isMethod({
|
2382
|
+
computed: true,
|
2383
|
+
key: node
|
2384
|
+
})) {
|
2385
|
+
scope = scope.parent;
|
2386
|
+
}
|
2387
|
+
const temp = scope.generateDeclaredUidIdentifier();
|
2388
|
+
nodes.unshift(expressionStatement$2(assignmentExpression$2("=", cloneNode$2(temp), node)));
|
2389
|
+
nodes.push(expressionStatement$2(cloneNode$2(temp)));
|
2390
|
+
}
|
2391
|
+
}
|
2392
|
+
return this.replaceExpressionWithStatements(nodes);
|
2393
|
+
} else if (Array.isArray(this.container)) {
|
2394
|
+
return _containerInsertAfter.call(this, nodes);
|
2395
|
+
} else if (this.isStatementOrBlock()) {
|
2396
|
+
const node = this.node;
|
2397
|
+
const shouldInsertCurrentNode = node && (!this.isExpressionStatement() || node.expression != null);
|
2398
|
+
this.replaceWith(blockStatement$2(shouldInsertCurrentNode ? [node] : []));
|
2399
|
+
return this.pushContainer("body", nodes);
|
2400
|
+
} else {
|
2401
|
+
throw new Error("We don't know what to do with this node type. " + "We were previously a Statement but we can't fit in here?");
|
2402
|
+
}
|
2403
|
+
}
|
2404
|
+
function updateSiblingKeys(fromIndex, incrementBy) {
|
2405
|
+
if (!this.parent) return;
|
2406
|
+
const paths = getCachedPaths(this);
|
2407
|
+
if (!paths) return;
|
2408
|
+
for (const [, path] of paths) {
|
2409
|
+
if (typeof path.key === "number" && path.container === this.container && path.key >= fromIndex) {
|
2410
|
+
path.key += incrementBy;
|
2411
|
+
}
|
2412
|
+
}
|
2413
|
+
}
|
2414
|
+
function _verifyNodeList(nodes) {
|
2415
|
+
if (!nodes) {
|
2416
|
+
return [];
|
2417
|
+
}
|
2418
|
+
if (!Array.isArray(nodes)) {
|
2419
|
+
nodes = [nodes];
|
2420
|
+
}
|
2421
|
+
for (let i = 0; i < nodes.length; i++) {
|
2422
|
+
const node = nodes[i];
|
2423
|
+
let msg;
|
2424
|
+
if (!node) {
|
2425
|
+
msg = "has falsy node";
|
2426
|
+
} else if (typeof node !== "object") {
|
2427
|
+
msg = "contains a non-object node";
|
2428
|
+
} else if (!node.type) {
|
2429
|
+
msg = "without a type";
|
2430
|
+
} else if (node instanceof NodePath_Final) {
|
2431
|
+
msg = "has a NodePath when it expected a raw object";
|
2432
|
+
}
|
2433
|
+
if (msg) {
|
2434
|
+
const type = Array.isArray(node) ? "array" : typeof node;
|
2435
|
+
throw new Error(`Node list ${msg} with the index of ${i} and type of ${type}`);
|
2436
|
+
}
|
2437
|
+
}
|
2438
|
+
return nodes;
|
2439
|
+
}
|
2440
|
+
function unshiftContainer(listKey, nodes) {
|
2441
|
+
_assertUnremoved.call(this);
|
2442
|
+
nodes = _verifyNodeList.call(this, nodes);
|
2443
|
+
const path = NodePath_Final.get({
|
2444
|
+
parentPath: this,
|
2445
|
+
parent: this.node,
|
2446
|
+
container: this.node[listKey],
|
2447
|
+
listKey,
|
2448
|
+
key: 0
|
2449
|
+
}).setContext(this.context);
|
2450
|
+
return _containerInsertBefore.call(path, nodes);
|
2451
|
+
}
|
2452
|
+
function pushContainer(listKey, nodes) {
|
2453
|
+
_assertUnremoved.call(this);
|
2454
|
+
const verifiedNodes = _verifyNodeList.call(this, nodes);
|
2455
|
+
const container = this.node[listKey];
|
2456
|
+
const path = NodePath_Final.get({
|
2457
|
+
parentPath: this,
|
2458
|
+
parent: this.node,
|
2459
|
+
container: container,
|
2460
|
+
listKey,
|
2461
|
+
key: container.length
|
2462
|
+
}).setContext(this.context);
|
2463
|
+
return path.replaceWithMultiple(verifiedNodes);
|
2464
|
+
}
|
2465
|
+
|
2466
|
+
const {
|
2467
|
+
FUNCTION_TYPES,
|
2468
|
+
arrowFunctionExpression: arrowFunctionExpression$1,
|
2469
|
+
assignmentExpression: assignmentExpression$1,
|
2470
|
+
awaitExpression,
|
2471
|
+
blockStatement: blockStatement$1,
|
2472
|
+
buildUndefinedNode,
|
2473
|
+
callExpression: callExpression$1,
|
2474
|
+
cloneNode: cloneNode$1,
|
2475
|
+
conditionalExpression: conditionalExpression$1,
|
2476
|
+
expressionStatement: expressionStatement$1,
|
2477
|
+
getBindingIdentifiers: getBindingIdentifiers$1,
|
2478
|
+
identifier: identifier$1,
|
2479
|
+
inheritLeadingComments,
|
2157
2480
|
inheritTrailingComments,
|
2158
2481
|
inheritsComments,
|
2159
2482
|
isBlockStatement: isBlockStatement$1,
|
2160
2483
|
isEmptyStatement,
|
2161
|
-
isExpression: isExpression$
|
2484
|
+
isExpression: isExpression$1,
|
2162
2485
|
isExpressionStatement,
|
2163
2486
|
isIfStatement,
|
2164
2487
|
isProgram,
|
@@ -2171,11 +2494,11 @@ const {
|
|
2171
2494
|
yieldExpression
|
2172
2495
|
} = _t;
|
2173
2496
|
function replaceWithMultiple(nodes) {
|
2174
|
-
|
2175
|
-
nodes =
|
2497
|
+
resync.call(this);
|
2498
|
+
nodes = _verifyNodeList.call(this, nodes);
|
2176
2499
|
inheritLeadingComments(nodes[0], this.node);
|
2177
2500
|
inheritTrailingComments(nodes[nodes.length - 1], this.node);
|
2178
|
-
getCachedPaths(this
|
2501
|
+
getCachedPaths(this)?.delete(this.node);
|
2179
2502
|
this.node = this.container[this.key] = null;
|
2180
2503
|
const paths = this.insertAfter(nodes);
|
2181
2504
|
if (this.node) {
|
@@ -2186,7 +2509,7 @@ function replaceWithMultiple(nodes) {
|
|
2186
2509
|
return paths;
|
2187
2510
|
}
|
2188
2511
|
function replaceWithSourceString(replacement) {
|
2189
|
-
|
2512
|
+
resync.call(this);
|
2190
2513
|
let ast;
|
2191
2514
|
try {
|
2192
2515
|
replacement = `(${replacement})`;
|
@@ -2209,11 +2532,11 @@ function replaceWithSourceString(replacement) {
|
|
2209
2532
|
return this.replaceWith(expressionAST);
|
2210
2533
|
}
|
2211
2534
|
function replaceWith(replacementPath) {
|
2212
|
-
|
2535
|
+
resync.call(this);
|
2213
2536
|
if (this.removed) {
|
2214
2537
|
throw new Error("You can't replace this node, we've already removed it");
|
2215
2538
|
}
|
2216
|
-
let replacement = replacementPath instanceof
|
2539
|
+
let replacement = replacementPath instanceof NodePath_Final ? replacementPath.node : replacementPath;
|
2217
2540
|
if (!replacement) {
|
2218
2541
|
throw new Error("You passed `path.replaceWith()` a falsy node, use `path.remove()` instead");
|
2219
2542
|
}
|
@@ -2230,9 +2553,9 @@ function replaceWith(replacementPath) {
|
|
2230
2553
|
throw new Error("Don't use `path.replaceWith()` with a source string, use `path.replaceWithSourceString()`");
|
2231
2554
|
}
|
2232
2555
|
let nodePath = "";
|
2233
|
-
if (this.isNodeType("Statement") && isExpression$
|
2556
|
+
if (this.isNodeType("Statement") && isExpression$1(replacement)) {
|
2234
2557
|
if (!this.canHaveVariableDeclarationOrExpression() && !this.canSwapBetweenExpressionAndStatement(replacement) && !this.parentPath.isExportDefaultDeclaration()) {
|
2235
|
-
replacement = expressionStatement$
|
2558
|
+
replacement = expressionStatement$1(replacement);
|
2236
2559
|
nodePath = "expression";
|
2237
2560
|
}
|
2238
2561
|
}
|
@@ -2246,9 +2569,9 @@ function replaceWith(replacementPath) {
|
|
2246
2569
|
inheritsComments(replacement, oldNode);
|
2247
2570
|
removeComments(oldNode);
|
2248
2571
|
}
|
2249
|
-
|
2572
|
+
_replaceWith.call(this, replacement);
|
2250
2573
|
this.type = replacement.type;
|
2251
|
-
|
2574
|
+
setScope.call(this);
|
2252
2575
|
this.requeue();
|
2253
2576
|
return [nodePath ? this.get(nodePath) : this];
|
2254
2577
|
}
|
@@ -2262,11 +2585,11 @@ function _replaceWith(node) {
|
|
2262
2585
|
validate$1(this.parent, this.key, node);
|
2263
2586
|
}
|
2264
2587
|
this.debug(`Replace with ${node?.type}`);
|
2265
|
-
getCachedPaths(this
|
2588
|
+
getCachedPaths(this)?.set(node, this).delete(this.node);
|
2266
2589
|
this.node = this.container[this.key] = node;
|
2267
2590
|
}
|
2268
2591
|
function replaceExpressionWithStatements(nodes) {
|
2269
|
-
|
2592
|
+
resync.call(this);
|
2270
2593
|
const declars = [];
|
2271
2594
|
const nodesAsSingleExpression = gatherSequenceExpressions(nodes, declars);
|
2272
2595
|
if (nodesAsSingleExpression) {
|
@@ -2276,17 +2599,15 @@ function replaceExpressionWithStatements(nodes) {
|
|
2276
2599
|
return this.replaceWith(nodesAsSingleExpression)[0].get("expressions");
|
2277
2600
|
}
|
2278
2601
|
const functionParent = this.getFunctionParent();
|
2279
|
-
const isParentAsync = functionParent?.
|
2280
|
-
const isParentGenerator = functionParent?.
|
2281
|
-
const container = arrowFunctionExpression$
|
2282
|
-
this.replaceWith(callExpression$
|
2602
|
+
const isParentAsync = functionParent?.node.async;
|
2603
|
+
const isParentGenerator = functionParent?.node.generator;
|
2604
|
+
const container = arrowFunctionExpression$1([], blockStatement$1(nodes));
|
2605
|
+
this.replaceWith(callExpression$1(container, []));
|
2283
2606
|
const callee = this.get("callee");
|
2284
|
-
|
2285
|
-
|
2286
|
-
|
2287
|
-
|
2288
|
-
}, "var");
|
2289
|
-
const completionRecords = this.get("callee").getCompletionRecords();
|
2607
|
+
callee.get("body").scope.hoistVariables(id => this.scope.push({
|
2608
|
+
id
|
2609
|
+
}));
|
2610
|
+
const completionRecords = callee.getCompletionRecords();
|
2290
2611
|
for (const path of completionRecords) {
|
2291
2612
|
if (!path.isExpressionStatement()) continue;
|
2292
2613
|
const loop = path.findParent(path => path.isLoop());
|
@@ -2294,12 +2615,12 @@ function replaceExpressionWithStatements(nodes) {
|
|
2294
2615
|
let uid = loop.getData("expressionReplacementReturnUid");
|
2295
2616
|
if (!uid) {
|
2296
2617
|
uid = callee.scope.generateDeclaredUidIdentifier("ret");
|
2297
|
-
callee.get("body").pushContainer("body", returnStatement$1(cloneNode$
|
2618
|
+
callee.get("body").pushContainer("body", returnStatement$1(cloneNode$1(uid)));
|
2298
2619
|
loop.setData("expressionReplacementReturnUid", uid);
|
2299
2620
|
} else {
|
2300
2621
|
uid = identifier$1(uid.name);
|
2301
2622
|
}
|
2302
|
-
path.get("expression").replaceWith(assignmentExpression$
|
2623
|
+
path.get("expression").replaceWith(assignmentExpression$1("=", cloneNode$1(uid), path.node.expression));
|
2303
2624
|
} else {
|
2304
2625
|
path.replaceWith(returnStatement$1(path.node.expression));
|
2305
2626
|
}
|
@@ -2327,19 +2648,19 @@ function gatherSequenceExpressions(nodes, declars) {
|
|
2327
2648
|
if (!isEmptyStatement(node)) {
|
2328
2649
|
ensureLastUndefined = false;
|
2329
2650
|
}
|
2330
|
-
if (isExpression$
|
2651
|
+
if (isExpression$1(node)) {
|
2331
2652
|
exprs.push(node);
|
2332
2653
|
} else if (isExpressionStatement(node)) {
|
2333
2654
|
exprs.push(node.expression);
|
2334
2655
|
} else if (isVariableDeclaration(node)) {
|
2335
2656
|
if (node.kind !== "var") return;
|
2336
2657
|
for (const declar of node.declarations) {
|
2337
|
-
const bindings = getBindingIdentifiers$
|
2658
|
+
const bindings = getBindingIdentifiers$1(declar);
|
2338
2659
|
for (const key of Object.keys(bindings)) {
|
2339
|
-
declars.push(cloneNode$
|
2660
|
+
declars.push(cloneNode$1(bindings[key]));
|
2340
2661
|
}
|
2341
2662
|
if (declar.init) {
|
2342
|
-
exprs.push(assignmentExpression$
|
2663
|
+
exprs.push(assignmentExpression$1("=", declar.id, declar.init));
|
2343
2664
|
}
|
2344
2665
|
}
|
2345
2666
|
ensureLastUndefined = true;
|
@@ -2368,11 +2689,11 @@ function gatherSequenceExpressions(nodes, declars) {
|
|
2368
2689
|
}
|
2369
2690
|
}
|
2370
2691
|
function replaceInline(nodes) {
|
2371
|
-
|
2692
|
+
resync.call(this);
|
2372
2693
|
if (Array.isArray(nodes)) {
|
2373
2694
|
if (Array.isArray(this.container)) {
|
2374
|
-
nodes =
|
2375
|
-
const paths =
|
2695
|
+
nodes = _verifyNodeList.call(this, nodes);
|
2696
|
+
const paths = _containerInsertAfter.call(this, nodes);
|
2376
2697
|
this.remove();
|
2377
2698
|
return paths;
|
2378
2699
|
} else {
|
@@ -2383,16 +2704,6 @@ function replaceInline(nodes) {
|
|
2383
2704
|
}
|
2384
2705
|
}
|
2385
2706
|
|
2386
|
-
var NodePath_replacement = /*#__PURE__*/Object.freeze({
|
2387
|
-
__proto__: null,
|
2388
|
-
_replaceWith: _replaceWith,
|
2389
|
-
replaceExpressionWithStatements: replaceExpressionWithStatements,
|
2390
|
-
replaceInline: replaceInline,
|
2391
|
-
replaceWith: replaceWith,
|
2392
|
-
replaceWithMultiple: replaceWithMultiple,
|
2393
|
-
replaceWithSourceString: replaceWithSourceString
|
2394
|
-
});
|
2395
|
-
|
2396
2707
|
const VALID_OBJECT_CALLEES = ["Number", "String", "Math"];
|
2397
2708
|
const VALID_IDENTIFIER_CALLEES = ["isFinite", "isNaN", "parseFloat", "parseInt", "decodeURI", "decodeURIComponent", "encodeURI", "encodeURIComponent", "btoa", "atob"];
|
2398
2709
|
const INVALID_METHODS = ["random"];
|
@@ -2509,6 +2820,22 @@ function _evaluate(path, state) {
|
|
2509
2820
|
deopt(binding.path, state);
|
2510
2821
|
return;
|
2511
2822
|
}
|
2823
|
+
const bindingPathScope = binding.path.scope;
|
2824
|
+
if (binding.kind === "var" && bindingPathScope !== binding.scope) {
|
2825
|
+
let hasUnsafeBlock = !bindingPathScope.path.parentPath.isBlockStatement();
|
2826
|
+
for (let scope = bindingPathScope.parent; scope; scope = scope.parent) {
|
2827
|
+
if (scope === path.scope) {
|
2828
|
+
if (hasUnsafeBlock) {
|
2829
|
+
deopt(binding.path, state);
|
2830
|
+
return;
|
2831
|
+
}
|
2832
|
+
break;
|
2833
|
+
}
|
2834
|
+
if (scope.path.parentPath?.isBlockStatement()) {
|
2835
|
+
hasUnsafeBlock = true;
|
2836
|
+
}
|
2837
|
+
}
|
2838
|
+
}
|
2512
2839
|
if (binding.hasValue) {
|
2513
2840
|
return binding.value;
|
2514
2841
|
}
|
@@ -2525,9 +2852,13 @@ function _evaluate(path, state) {
|
|
2525
2852
|
if (resolved === path) {
|
2526
2853
|
deopt(path, state);
|
2527
2854
|
return;
|
2528
|
-
} else {
|
2529
|
-
return evaluateCached(resolved, state);
|
2530
2855
|
}
|
2856
|
+
const value = evaluateCached(resolved, state);
|
2857
|
+
if (typeof value === "object" && value !== null && binding.references > 1) {
|
2858
|
+
deopt(resolved, state);
|
2859
|
+
return;
|
2860
|
+
}
|
2861
|
+
return value;
|
2531
2862
|
}
|
2532
2863
|
if (path.isUnaryExpression({
|
2533
2864
|
prefix: true
|
@@ -2732,22 +3063,16 @@ function evaluate() {
|
|
2732
3063
|
};
|
2733
3064
|
}
|
2734
3065
|
|
2735
|
-
var NodePath_evaluation = /*#__PURE__*/Object.freeze({
|
2736
|
-
__proto__: null,
|
2737
|
-
evaluate: evaluate,
|
2738
|
-
evaluateTruthy: evaluateTruthy
|
2739
|
-
});
|
2740
|
-
|
2741
3066
|
const {
|
2742
|
-
arrowFunctionExpression
|
2743
|
-
assignmentExpression
|
3067
|
+
arrowFunctionExpression,
|
3068
|
+
assignmentExpression,
|
2744
3069
|
binaryExpression,
|
2745
|
-
blockStatement
|
2746
|
-
callExpression
|
3070
|
+
blockStatement,
|
3071
|
+
callExpression,
|
2747
3072
|
conditionalExpression,
|
2748
|
-
expressionStatement
|
3073
|
+
expressionStatement,
|
2749
3074
|
identifier,
|
2750
|
-
isIdentifier: isIdentifier$
|
3075
|
+
isIdentifier: isIdentifier$1,
|
2751
3076
|
jsxIdentifier,
|
2752
3077
|
logicalExpression,
|
2753
3078
|
LOGICAL_OPERATORS,
|
@@ -2761,9 +3086,20 @@ const {
|
|
2761
3086
|
spreadElement,
|
2762
3087
|
stringLiteral,
|
2763
3088
|
super: _super,
|
2764
|
-
thisExpression
|
3089
|
+
thisExpression,
|
2765
3090
|
toExpression,
|
2766
|
-
unaryExpression: unaryExpression$1
|
3091
|
+
unaryExpression: unaryExpression$1,
|
3092
|
+
toBindingIdentifierName,
|
3093
|
+
isFunction,
|
3094
|
+
isAssignmentPattern,
|
3095
|
+
isRestElement,
|
3096
|
+
getFunctionName,
|
3097
|
+
cloneNode,
|
3098
|
+
variableDeclaration,
|
3099
|
+
variableDeclarator,
|
3100
|
+
exportNamedDeclaration,
|
3101
|
+
exportSpecifier,
|
3102
|
+
inherits
|
2767
3103
|
} = _t;
|
2768
3104
|
function toComputedKey() {
|
2769
3105
|
let key;
|
@@ -2775,7 +3111,7 @@ function toComputedKey() {
|
|
2775
3111
|
throw new ReferenceError("todo");
|
2776
3112
|
}
|
2777
3113
|
if (!this.node.computed) {
|
2778
|
-
if (isIdentifier$
|
3114
|
+
if (isIdentifier$1(key)) key = stringLiteral(key.name);
|
2779
3115
|
}
|
2780
3116
|
return key;
|
2781
3117
|
}
|
@@ -2806,12 +3142,12 @@ function ensureBlock() {
|
|
2806
3142
|
statements.push(returnStatement(body.node));
|
2807
3143
|
} else {
|
2808
3144
|
key = "expression";
|
2809
|
-
statements.push(expressionStatement
|
3145
|
+
statements.push(expressionStatement(body.node));
|
2810
3146
|
}
|
2811
3147
|
}
|
2812
|
-
this.node.body = blockStatement
|
3148
|
+
this.node.body = blockStatement(statements);
|
2813
3149
|
const parentPath = this.get(stringPath);
|
2814
|
-
|
3150
|
+
setup.call(body, parentPath, listKey ? parentPath.node[listKey] : parentPath.node, listKey, key);
|
2815
3151
|
return this.node;
|
2816
3152
|
}
|
2817
3153
|
function unwrapFunctionEnvironment() {
|
@@ -2831,10 +3167,14 @@ function arrowFunctionToExpression({
|
|
2831
3167
|
if (!this.isArrowFunctionExpression()) {
|
2832
3168
|
throw this.buildCodeFrameError("Cannot convert non-arrow function to a function expression.");
|
2833
3169
|
}
|
3170
|
+
let self = this;
|
3171
|
+
if (!noNewArrows) {
|
3172
|
+
self = self.ensureFunctionName(false) ?? self;
|
3173
|
+
}
|
2834
3174
|
const {
|
2835
3175
|
thisBinding,
|
2836
3176
|
fnPath: fn
|
2837
|
-
} = hoistFunctionEnvironment(
|
3177
|
+
} = hoistFunctionEnvironment(self, noNewArrows, allowInsertArrow, allowInsertArrowWithRest);
|
2838
3178
|
fn.ensureBlock();
|
2839
3179
|
setType(fn, "FunctionExpression");
|
2840
3180
|
if (!noNewArrows) {
|
@@ -2845,20 +3185,20 @@ function arrowFunctionToExpression({
|
|
2845
3185
|
init: objectExpression([])
|
2846
3186
|
});
|
2847
3187
|
}
|
2848
|
-
fn.get("body").unshiftContainer("body", expressionStatement
|
2849
|
-
fn.replaceWith(callExpression
|
3188
|
+
fn.get("body").unshiftContainer("body", expressionStatement(callExpression(this.hub.addHelper("newArrowCheck"), [thisExpression(), checkBinding ? identifier(checkBinding.name) : identifier(thisBinding)])));
|
3189
|
+
fn.replaceWith(callExpression(memberExpression(fn.node, identifier("bind")), [checkBinding ? identifier(checkBinding.name) : thisExpression()]));
|
2850
3190
|
return fn.get("callee.object");
|
2851
3191
|
}
|
2852
3192
|
return fn;
|
2853
3193
|
}
|
2854
|
-
const getSuperCallsVisitor =
|
3194
|
+
const getSuperCallsVisitor = environmentVisitor({
|
2855
3195
|
CallExpression(child, {
|
2856
3196
|
allSuperCalls
|
2857
3197
|
}) {
|
2858
3198
|
if (!child.get("callee").isSuper()) return;
|
2859
3199
|
allSuperCalls.push(child);
|
2860
3200
|
}
|
2861
|
-
}
|
3201
|
+
});
|
2862
3202
|
function hoistFunctionEnvironment(fnPath, noNewArrows = true, allowInsertArrow = true, allowInsertArrowWithRest = true) {
|
2863
3203
|
let arrowParent;
|
2864
3204
|
let thisEnvFn = fnPath.findParent(p => {
|
@@ -2879,7 +3219,7 @@ function hoistFunctionEnvironment(fnPath, noNewArrows = true, allowInsertArrow =
|
|
2879
3219
|
if (arrowParent) {
|
2880
3220
|
thisEnvFn = arrowParent;
|
2881
3221
|
} else if (allowInsertArrow) {
|
2882
|
-
fnPath.replaceWith(callExpression
|
3222
|
+
fnPath.replaceWith(callExpression(arrowFunctionExpression([], toExpression(fnPath.node)), []));
|
2883
3223
|
thisEnvFn = fnPath.get("callee");
|
2884
3224
|
fnPath = thisEnvFn.get("body");
|
2885
3225
|
} else {
|
@@ -2960,15 +3300,15 @@ function hoistFunctionEnvironment(fnPath, noNewArrows = true, allowInsertArrow =
|
|
2960
3300
|
const value = superParentPath.node.right;
|
2961
3301
|
args.push(value);
|
2962
3302
|
}
|
2963
|
-
const call = callExpression
|
3303
|
+
const call = callExpression(identifier(superBinding), args);
|
2964
3304
|
if (isCall) {
|
2965
|
-
superParentPath.unshiftContainer("arguments", thisExpression
|
3305
|
+
superParentPath.unshiftContainer("arguments", thisExpression());
|
2966
3306
|
superProp.replaceWith(memberExpression(call, identifier("call")));
|
2967
3307
|
thisPaths.push(superParentPath.get("arguments.0"));
|
2968
3308
|
} else if (isAssignment) {
|
2969
3309
|
superParentPath.replaceWith(call);
|
2970
3310
|
} else if (isTaggedTemplate) {
|
2971
|
-
superProp.replaceWith(callExpression
|
3311
|
+
superProp.replaceWith(callExpression(memberExpression(call, identifier("bind"), false), [thisExpression()]));
|
2972
3312
|
thisPaths.push(superProp.get("arguments.0"));
|
2973
3313
|
} else {
|
2974
3314
|
superProp.replaceWith(call);
|
@@ -3005,7 +3345,7 @@ function standardizeSuperProperty(superProp) {
|
|
3005
3345
|
const tmp = superProp.scope.generateDeclaredUidIdentifier("tmp");
|
3006
3346
|
const object = superProp.node.object;
|
3007
3347
|
const property = superProp.node.property;
|
3008
|
-
assignmentPath.get("left").replaceWith(memberExpression(object, assignmentExpression
|
3348
|
+
assignmentPath.get("left").replaceWith(memberExpression(object, assignmentExpression("=", tmp, property), true));
|
3009
3349
|
assignmentPath.get("right").replaceWith(rightExpression(isLogicalAssignment ? "=" : op, memberExpression(object, identifier(tmp.name), true), value));
|
3010
3350
|
} else {
|
3011
3351
|
const object = superProp.node.object;
|
@@ -3023,7 +3363,7 @@ function standardizeSuperProperty(superProp) {
|
|
3023
3363
|
const updateExpr = superProp.parentPath;
|
3024
3364
|
const tmp = superProp.scope.generateDeclaredUidIdentifier("tmp");
|
3025
3365
|
const computedKey = superProp.node.computed ? superProp.scope.generateDeclaredUidIdentifier("prop") : null;
|
3026
|
-
const parts = [assignmentExpression
|
3366
|
+
const parts = [assignmentExpression("=", tmp, memberExpression(superProp.node.object, computedKey ? assignmentExpression("=", computedKey, superProp.node.property) : superProp.node.property, superProp.node.computed)), assignmentExpression("=", memberExpression(superProp.node.object, computedKey ? identifier(computedKey.name) : superProp.node.property, superProp.node.computed), binaryExpression(superProp.parentPath.node.operator[0], identifier(tmp.name), numericLiteral$1(1)))];
|
3027
3367
|
if (!superProp.parentPath.node.prefix) {
|
3028
3368
|
parts.push(identifier(tmp.name));
|
3029
3369
|
}
|
@@ -3035,7 +3375,7 @@ function standardizeSuperProperty(superProp) {
|
|
3035
3375
|
return [superProp];
|
3036
3376
|
function rightExpression(op, left, right) {
|
3037
3377
|
if (op === "=") {
|
3038
|
-
return assignmentExpression
|
3378
|
+
return assignmentExpression("=", left, right);
|
3039
3379
|
} else {
|
3040
3380
|
return binaryExpression(op, left, right);
|
3041
3381
|
}
|
@@ -3044,7 +3384,7 @@ function standardizeSuperProperty(superProp) {
|
|
3044
3384
|
function hasSuperClass(thisEnvFn) {
|
3045
3385
|
return thisEnvFn.isClassMethod() && !!thisEnvFn.parentPath.parentPath.node.superClass;
|
3046
3386
|
}
|
3047
|
-
const assignSuperThisVisitor =
|
3387
|
+
const assignSuperThisVisitor = environmentVisitor({
|
3048
3388
|
CallExpression(child, {
|
3049
3389
|
supers,
|
3050
3390
|
thisBinding
|
@@ -3052,12 +3392,12 @@ const assignSuperThisVisitor = merge([{
|
|
3052
3392
|
if (!child.get("callee").isSuper()) return;
|
3053
3393
|
if (supers.has(child.node)) return;
|
3054
3394
|
supers.add(child.node);
|
3055
|
-
child.replaceWithMultiple([child.node, assignmentExpression
|
3395
|
+
child.replaceWithMultiple([child.node, assignmentExpression("=", identifier(thisBinding), identifier("this"))]);
|
3056
3396
|
}
|
3057
|
-
}
|
3397
|
+
});
|
3058
3398
|
function getThisBinding(thisEnvFn, inConstructor) {
|
3059
3399
|
return getBinding(thisEnvFn, "this", thisBinding => {
|
3060
|
-
if (!inConstructor || !hasSuperClass(thisEnvFn)) return thisExpression
|
3400
|
+
if (!inConstructor || !hasSuperClass(thisEnvFn)) return thisExpression();
|
3061
3401
|
thisEnvFn.traverse(assignSuperThisVisitor, {
|
3062
3402
|
supers: new WeakSet(),
|
3063
3403
|
thisBinding
|
@@ -3067,7 +3407,7 @@ function getThisBinding(thisEnvFn, inConstructor) {
|
|
3067
3407
|
function getSuperBinding(thisEnvFn) {
|
3068
3408
|
return getBinding(thisEnvFn, "supercall", () => {
|
3069
3409
|
const argsBinding = thisEnvFn.scope.generateUidIdentifier("args");
|
3070
|
-
return arrowFunctionExpression
|
3410
|
+
return arrowFunctionExpression([restElement(argsBinding)], callExpression(_super(), [spreadElement(identifier(argsBinding.name))]));
|
3071
3411
|
});
|
3072
3412
|
}
|
3073
3413
|
function getSuperPropBinding(thisEnvFn, isAssignment, propName) {
|
@@ -3085,9 +3425,9 @@ function getSuperPropBinding(thisEnvFn, isAssignment, propName) {
|
|
3085
3425
|
if (isAssignment) {
|
3086
3426
|
const valueIdent = thisEnvFn.scope.generateUidIdentifier("value");
|
3087
3427
|
argsList.push(valueIdent);
|
3088
|
-
fnBody = assignmentExpression
|
3428
|
+
fnBody = assignmentExpression("=", fnBody, identifier(valueIdent.name));
|
3089
3429
|
}
|
3090
|
-
return arrowFunctionExpression
|
3430
|
+
return arrowFunctionExpression(argsList, fnBody);
|
3091
3431
|
});
|
3092
3432
|
}
|
3093
3433
|
function getBinding(thisEnvFn, key, init) {
|
@@ -3104,7 +3444,7 @@ function getBinding(thisEnvFn, key, init) {
|
|
3104
3444
|
}
|
3105
3445
|
return data;
|
3106
3446
|
}
|
3107
|
-
const getScopeInformationVisitor =
|
3447
|
+
const getScopeInformationVisitor = environmentVisitor({
|
3108
3448
|
ThisExpression(child, {
|
3109
3449
|
thisPaths
|
3110
3450
|
}) {
|
@@ -3162,7 +3502,7 @@ const getScopeInformationVisitor = merge([{
|
|
3162
3502
|
})) return;
|
3163
3503
|
newTargetPaths.push(child);
|
3164
3504
|
}
|
3165
|
-
}
|
3505
|
+
});
|
3166
3506
|
function getScopeInformation(fnPath) {
|
3167
3507
|
const thisPaths = [];
|
3168
3508
|
const argumentsPaths = [];
|
@@ -3184,61 +3524,165 @@ function getScopeInformation(fnPath) {
|
|
3184
3524
|
superCalls
|
3185
3525
|
};
|
3186
3526
|
}
|
3187
|
-
|
3188
|
-
|
3189
|
-
|
3190
|
-
|
3191
|
-
|
3192
|
-
|
3193
|
-
|
3194
|
-
|
3195
|
-
|
3196
|
-
const
|
3197
|
-
|
3198
|
-
|
3199
|
-
|
3200
|
-
|
3201
|
-
|
3202
|
-
|
3203
|
-
|
3204
|
-
|
3205
|
-
|
3206
|
-
}
|
3207
|
-
|
3208
|
-
|
3209
|
-
|
3210
|
-
|
3211
|
-
|
3212
|
-
|
3213
|
-
|
3214
|
-
|
3215
|
-
|
3527
|
+
function splitExportDeclaration() {
|
3528
|
+
if (!this.isExportDeclaration() || this.isExportAllDeclaration()) {
|
3529
|
+
throw new Error("Only default and named export declarations can be split.");
|
3530
|
+
}
|
3531
|
+
if (this.isExportNamedDeclaration() && this.get("specifiers").length > 0) {
|
3532
|
+
throw new Error("It doesn't make sense to split exported specifiers.");
|
3533
|
+
}
|
3534
|
+
const declaration = this.get("declaration");
|
3535
|
+
if (this.isExportDefaultDeclaration()) {
|
3536
|
+
const standaloneDeclaration = declaration.isFunctionDeclaration() || declaration.isClassDeclaration();
|
3537
|
+
const exportExpr = declaration.isFunctionExpression() || declaration.isClassExpression();
|
3538
|
+
const scope = declaration.isScope() ? declaration.scope.parent : declaration.scope;
|
3539
|
+
let id = declaration.node.id;
|
3540
|
+
let needBindingRegistration = false;
|
3541
|
+
if (!id) {
|
3542
|
+
needBindingRegistration = true;
|
3543
|
+
id = scope.generateUidIdentifier("default");
|
3544
|
+
if (standaloneDeclaration || exportExpr) {
|
3545
|
+
declaration.node.id = cloneNode(id);
|
3546
|
+
}
|
3547
|
+
} else if (exportExpr && scope.hasBinding(id.name)) {
|
3548
|
+
needBindingRegistration = true;
|
3549
|
+
id = scope.generateUidIdentifier(id.name);
|
3550
|
+
}
|
3551
|
+
const updatedDeclaration = standaloneDeclaration ? declaration.node : variableDeclaration("var", [variableDeclarator(cloneNode(id), declaration.node)]);
|
3552
|
+
const updatedExportDeclaration = exportNamedDeclaration(null, [exportSpecifier(cloneNode(id), identifier("default"))]);
|
3553
|
+
this.insertAfter(updatedExportDeclaration);
|
3554
|
+
this.replaceWith(updatedDeclaration);
|
3555
|
+
if (needBindingRegistration) {
|
3556
|
+
scope.registerDeclaration(this);
|
3557
|
+
}
|
3558
|
+
return this;
|
3559
|
+
} else if (this.get("specifiers").length > 0) {
|
3560
|
+
throw new Error("It doesn't make sense to split exported specifiers.");
|
3216
3561
|
}
|
3562
|
+
const bindingIdentifiers = declaration.getOuterBindingIdentifiers();
|
3563
|
+
const specifiers = Object.keys(bindingIdentifiers).map(name => {
|
3564
|
+
return exportSpecifier(identifier(name), identifier(name));
|
3565
|
+
});
|
3566
|
+
const aliasDeclar = exportNamedDeclaration(null, specifiers);
|
3567
|
+
this.insertAfter(aliasDeclar);
|
3568
|
+
this.replaceWith(declaration.node);
|
3569
|
+
return this;
|
3217
3570
|
}
|
3218
|
-
|
3219
|
-
|
3220
|
-
|
3221
|
-
|
3222
|
-
|
3223
|
-
|
3224
|
-
|
3225
|
-
|
3226
|
-
|
3227
|
-
}
|
3228
|
-
|
3229
|
-
|
3230
|
-
|
3231
|
-
|
3232
|
-
|
3233
|
-
|
3234
|
-
|
3235
|
-
|
3236
|
-
|
3237
|
-
|
3238
|
-
|
3239
|
-
|
3240
|
-
|
3241
|
-
return
|
3571
|
+
const refersOuterBindingVisitor = {
|
3572
|
+
"ReferencedIdentifier|BindingIdentifier"(path, state) {
|
3573
|
+
if (path.node.name !== state.name) return;
|
3574
|
+
state.needsRename = true;
|
3575
|
+
path.stop();
|
3576
|
+
},
|
3577
|
+
Scope(path, state) {
|
3578
|
+
if (path.scope.hasOwnBinding(state.name)) {
|
3579
|
+
path.skip();
|
3580
|
+
}
|
3581
|
+
}
|
3582
|
+
};
|
3583
|
+
function ensureFunctionName(supportUnicodeId) {
|
3584
|
+
if (this.node.id) return this;
|
3585
|
+
const res = getFunctionName(this.node, this.parent);
|
3586
|
+
if (res == null) return this;
|
3587
|
+
let {
|
3588
|
+
name
|
3589
|
+
} = res;
|
3590
|
+
if (!supportUnicodeId && /[\uD800-\uDFFF]/.test(name)) {
|
3591
|
+
return null;
|
3592
|
+
}
|
3593
|
+
if (name.startsWith("get ") || name.startsWith("set ")) {
|
3594
|
+
return null;
|
3595
|
+
}
|
3596
|
+
name = toBindingIdentifierName(name.replace(/[/ ]/g, "_"));
|
3597
|
+
const id = identifier(name);
|
3598
|
+
inherits(id, res.originalNode);
|
3599
|
+
const state = {
|
3600
|
+
needsRename: false,
|
3601
|
+
name
|
3602
|
+
};
|
3603
|
+
const {
|
3604
|
+
scope
|
3605
|
+
} = this;
|
3606
|
+
const binding = scope.getOwnBinding(name);
|
3607
|
+
if (binding) {
|
3608
|
+
if (binding.kind === "param") {
|
3609
|
+
state.needsRename = true;
|
3610
|
+
}
|
3611
|
+
} else if (scope.parent.hasBinding(name) || scope.hasGlobal(name)) {
|
3612
|
+
this.traverse(refersOuterBindingVisitor, state);
|
3613
|
+
}
|
3614
|
+
if (!state.needsRename) {
|
3615
|
+
this.node.id = id;
|
3616
|
+
{
|
3617
|
+
scope.getProgramParent().referencesSet.add(id.name);
|
3618
|
+
}
|
3619
|
+
return this;
|
3620
|
+
}
|
3621
|
+
if (scope.hasBinding(id.name) && !scope.hasGlobal(id.name)) {
|
3622
|
+
scope.rename(id.name);
|
3623
|
+
this.node.id = id;
|
3624
|
+
{
|
3625
|
+
scope.getProgramParent().referencesSet.add(id.name);
|
3626
|
+
}
|
3627
|
+
return this;
|
3628
|
+
}
|
3629
|
+
if (!isFunction(this.node)) return null;
|
3630
|
+
const key = scope.generateUidIdentifier(id.name);
|
3631
|
+
const params = [];
|
3632
|
+
for (let i = 0, len = getFunctionArity(this.node); i < len; i++) {
|
3633
|
+
params.push(scope.generateUidIdentifier("x"));
|
3634
|
+
}
|
3635
|
+
const call = template.expression.ast`
|
3636
|
+
(function (${key}) {
|
3637
|
+
function ${id}(${params}) {
|
3638
|
+
return ${cloneNode(key)}.apply(this, arguments);
|
3639
|
+
}
|
3640
|
+
|
3641
|
+
${cloneNode(id)}.toString = function () {
|
3642
|
+
return ${cloneNode(key)}.toString();
|
3643
|
+
}
|
3644
|
+
|
3645
|
+
return ${cloneNode(id)};
|
3646
|
+
})(${toExpression(this.node)})
|
3647
|
+
`;
|
3648
|
+
return this.replaceWith(call)[0].get("arguments.0");
|
3649
|
+
}
|
3650
|
+
function getFunctionArity(node) {
|
3651
|
+
const count = node.params.findIndex(param => isAssignmentPattern(param) || isRestElement(param));
|
3652
|
+
return count === -1 ? node.params.length : count;
|
3653
|
+
}
|
3654
|
+
|
3655
|
+
const {
|
3656
|
+
STATEMENT_OR_BLOCK_KEYS,
|
3657
|
+
VISITOR_KEYS: VISITOR_KEYS$3,
|
3658
|
+
isBlockStatement,
|
3659
|
+
isExpression,
|
3660
|
+
isIdentifier,
|
3661
|
+
isLiteral,
|
3662
|
+
isStringLiteral,
|
3663
|
+
isType,
|
3664
|
+
matchesPattern: _matchesPattern
|
3665
|
+
} = _t;
|
3666
|
+
function matchesPattern(pattern, allowPartial) {
|
3667
|
+
return _matchesPattern(this.node, pattern, allowPartial);
|
3668
|
+
}
|
3669
|
+
function isStatic() {
|
3670
|
+
return this.scope.isStatic(this.node);
|
3671
|
+
}
|
3672
|
+
function isNodeType(type) {
|
3673
|
+
return isType(this.type, type);
|
3674
|
+
}
|
3675
|
+
function canHaveVariableDeclarationOrExpression() {
|
3676
|
+
return (this.key === "init" || this.key === "left") && this.parentPath.isFor();
|
3677
|
+
}
|
3678
|
+
function canSwapBetweenExpressionAndStatement(replacement) {
|
3679
|
+
if (this.key !== "body" || !this.parentPath.isArrowFunctionExpression()) {
|
3680
|
+
return false;
|
3681
|
+
}
|
3682
|
+
if (this.isExpression()) {
|
3683
|
+
return isBlockStatement(replacement);
|
3684
|
+
} else if (this.isBlockStatement()) {
|
3685
|
+
return isExpression(replacement);
|
3242
3686
|
}
|
3243
3687
|
return false;
|
3244
3688
|
}
|
@@ -3293,7 +3737,7 @@ function referencesImport(moduleSource, importName) {
|
|
3293
3737
|
if (path.isImportNamespaceSpecifier() && importName === "*") {
|
3294
3738
|
return true;
|
3295
3739
|
}
|
3296
|
-
if (path.isImportSpecifier() && isIdentifier
|
3740
|
+
if (path.isImportSpecifier() && isIdentifier(path.node.imported, {
|
3297
3741
|
name: importName
|
3298
3742
|
})) {
|
3299
3743
|
return true;
|
@@ -3367,8 +3811,8 @@ function _guessExecutionStatusRelativeToCached(base, target, cache) {
|
|
3367
3811
|
target: target.getAncestry(),
|
3368
3812
|
this: base.getAncestry()
|
3369
3813
|
};
|
3370
|
-
if (paths.target.
|
3371
|
-
if (paths.this.
|
3814
|
+
if (paths.target.includes(base)) return "after";
|
3815
|
+
if (paths.this.includes(target)) return "before";
|
3372
3816
|
let commonPath;
|
3373
3817
|
const commonIndex = {
|
3374
3818
|
target: 0,
|
@@ -3448,10 +3892,10 @@ function _guessExecutionStatusRelativeToDifferentFunctionsCached(base, target, c
|
|
3448
3892
|
return result;
|
3449
3893
|
}
|
3450
3894
|
function resolve(dangerous, resolved) {
|
3451
|
-
return
|
3895
|
+
return _resolve.call(this, dangerous, resolved) || this;
|
3452
3896
|
}
|
3453
3897
|
function _resolve(dangerous, resolved) {
|
3454
|
-
if (resolved
|
3898
|
+
if (resolved?.includes(this)) return;
|
3455
3899
|
resolved = resolved || [];
|
3456
3900
|
resolved.push(this);
|
3457
3901
|
if (this.isVariableDeclarator()) {
|
@@ -3563,774 +4007,68 @@ function isInStrictMode() {
|
|
3563
4007
|
return !!strictParent;
|
3564
4008
|
}
|
3565
4009
|
|
3566
|
-
|
3567
|
-
|
3568
|
-
|
3569
|
-
|
3570
|
-
|
3571
|
-
|
3572
|
-
|
3573
|
-
|
3574
|
-
|
3575
|
-
|
3576
|
-
|
3577
|
-
|
3578
|
-
|
3579
|
-
|
3580
|
-
isStatementOrBlock: isStatementOrBlock,
|
3581
|
-
isStatic: isStatic,
|
3582
|
-
isnt: isnt,
|
3583
|
-
matchesPattern: matchesPattern,
|
3584
|
-
referencesImport: referencesImport,
|
3585
|
-
resolve: resolve,
|
3586
|
-
willIMaybeExecuteBefore: willIMaybeExecuteBefore
|
3587
|
-
});
|
3588
|
-
|
3589
|
-
function call(key) {
|
3590
|
-
const opts = this.opts;
|
3591
|
-
this.debug(key);
|
3592
|
-
if (this.node) {
|
3593
|
-
if (this._call(opts[key])) return true;
|
3594
|
-
}
|
3595
|
-
if (this.node) {
|
3596
|
-
return this._call(opts[this.node.type]?.[key]);
|
3597
|
-
}
|
3598
|
-
return false;
|
3599
|
-
}
|
3600
|
-
function _call(fns) {
|
3601
|
-
if (!fns) return false;
|
3602
|
-
for (const fn of fns) {
|
3603
|
-
if (!fn) continue;
|
3604
|
-
const node = this.node;
|
3605
|
-
if (!node) return true;
|
3606
|
-
const ret = fn.call(this.state, this, this.state);
|
3607
|
-
if (ret && typeof ret === "object" && typeof ret.then === "function") {
|
3608
|
-
throw new Error(`You appear to be using a plugin with an async traversal visitor, ` + `which your current version of Babel does not support. ` + `If you're using a published plugin, you may need to upgrade ` + `your @babel/core version.`);
|
3609
|
-
}
|
3610
|
-
if (ret) {
|
3611
|
-
throw new Error(`Unexpected return value from visitor method ${fn}`);
|
3612
|
-
}
|
3613
|
-
if (this.node !== node) return true;
|
3614
|
-
if (this._traverseFlags > 0) return true;
|
3615
|
-
}
|
3616
|
-
return false;
|
3617
|
-
}
|
3618
|
-
function isDenylisted() {
|
3619
|
-
const denylist = this.opts.denylist ?? this.opts.blacklist;
|
3620
|
-
return denylist && denylist.indexOf(this.node.type) > -1;
|
3621
|
-
}
|
3622
|
-
function restoreContext(path, context) {
|
3623
|
-
if (path.context !== context) {
|
3624
|
-
path.context = context;
|
3625
|
-
path.state = context.state;
|
3626
|
-
path.opts = context.opts;
|
3627
|
-
}
|
3628
|
-
}
|
3629
|
-
function visit() {
|
3630
|
-
if (!this.node) {
|
3631
|
-
return false;
|
3632
|
-
}
|
3633
|
-
if (this.isDenylisted()) {
|
3634
|
-
return false;
|
3635
|
-
}
|
3636
|
-
if (this.opts.shouldSkip?.(this)) {
|
3637
|
-
return false;
|
3638
|
-
}
|
3639
|
-
const currentContext = this.context;
|
3640
|
-
if (this.shouldSkip || this.call("enter")) {
|
3641
|
-
this.debug("Skip...");
|
3642
|
-
return this.shouldStop;
|
3643
|
-
}
|
3644
|
-
restoreContext(this, currentContext);
|
3645
|
-
this.debug("Recursing into...");
|
3646
|
-
this.shouldStop = traverseNode(this.node, this.opts, this.scope, this.state, this, this.skipKeys);
|
3647
|
-
restoreContext(this, currentContext);
|
3648
|
-
this.call("exit");
|
3649
|
-
return this.shouldStop;
|
3650
|
-
}
|
3651
|
-
function skip() {
|
3652
|
-
this.shouldSkip = true;
|
3653
|
-
}
|
3654
|
-
function skipKey(key) {
|
3655
|
-
if (this.skipKeys == null) {
|
3656
|
-
this.skipKeys = {};
|
3657
|
-
}
|
3658
|
-
this.skipKeys[key] = true;
|
3659
|
-
}
|
3660
|
-
function stop() {
|
3661
|
-
this._traverseFlags |= SHOULD_SKIP | SHOULD_STOP;
|
4010
|
+
const {
|
4011
|
+
getAssignmentIdentifiers: _getAssignmentIdentifiers,
|
4012
|
+
getBindingIdentifiers: _getBindingIdentifiers,
|
4013
|
+
getOuterBindingIdentifiers: _getOuterBindingIdentifiers,
|
4014
|
+
numericLiteral,
|
4015
|
+
unaryExpression
|
4016
|
+
} = _t;
|
4017
|
+
const NORMAL_COMPLETION = 0;
|
4018
|
+
const BREAK_COMPLETION = 1;
|
4019
|
+
function NormalCompletion(path) {
|
4020
|
+
return {
|
4021
|
+
type: NORMAL_COMPLETION,
|
4022
|
+
path
|
4023
|
+
};
|
3662
4024
|
}
|
3663
|
-
function
|
3664
|
-
|
3665
|
-
|
3666
|
-
|
3667
|
-
|
3668
|
-
}
|
3669
|
-
let target;
|
3670
|
-
while (path && !target) {
|
3671
|
-
if (path.opts?.noScope) return;
|
3672
|
-
target = path.scope;
|
3673
|
-
path = path.parentPath;
|
3674
|
-
}
|
3675
|
-
this.scope = this.getScope(target);
|
3676
|
-
this.scope?.init();
|
4025
|
+
function BreakCompletion(path) {
|
4026
|
+
return {
|
4027
|
+
type: BREAK_COMPLETION,
|
4028
|
+
path
|
4029
|
+
};
|
3677
4030
|
}
|
3678
|
-
function
|
3679
|
-
if (this.
|
3680
|
-
this.
|
3681
|
-
}
|
3682
|
-
|
3683
|
-
if (context) {
|
3684
|
-
this.context = context;
|
3685
|
-
this.state = context.state;
|
3686
|
-
this.opts = context.opts;
|
4031
|
+
function getOpposite() {
|
4032
|
+
if (this.key === "left") {
|
4033
|
+
return this.getSibling("right");
|
4034
|
+
} else if (this.key === "right") {
|
4035
|
+
return this.getSibling("left");
|
3687
4036
|
}
|
3688
|
-
|
3689
|
-
return this;
|
3690
|
-
}
|
3691
|
-
function resync() {
|
3692
|
-
if (this.removed) return;
|
3693
|
-
this._resyncParent();
|
3694
|
-
this._resyncList();
|
3695
|
-
this._resyncKey();
|
4037
|
+
return null;
|
3696
4038
|
}
|
3697
|
-
function
|
3698
|
-
if (
|
3699
|
-
|
4039
|
+
function addCompletionRecords(path, records, context) {
|
4040
|
+
if (path) {
|
4041
|
+
records.push(..._getCompletionRecords(path, context));
|
3700
4042
|
}
|
4043
|
+
return records;
|
3701
4044
|
}
|
3702
|
-
function
|
3703
|
-
|
3704
|
-
|
3705
|
-
|
3706
|
-
|
3707
|
-
|
3708
|
-
|
3709
|
-
|
3710
|
-
|
3711
|
-
|
4045
|
+
function completionRecordForSwitch(cases, records, context) {
|
4046
|
+
let lastNormalCompletions = [];
|
4047
|
+
for (let i = 0; i < cases.length; i++) {
|
4048
|
+
const casePath = cases[i];
|
4049
|
+
const caseCompletions = _getCompletionRecords(casePath, context);
|
4050
|
+
const normalCompletions = [];
|
4051
|
+
const breakCompletions = [];
|
4052
|
+
for (const c of caseCompletions) {
|
4053
|
+
if (c.type === NORMAL_COMPLETION) {
|
4054
|
+
normalCompletions.push(c);
|
3712
4055
|
}
|
3713
|
-
|
3714
|
-
|
3715
|
-
for (const key of Object.keys(this.container)) {
|
3716
|
-
if (this.container[key] === this.node) {
|
3717
|
-
this.setKey(key);
|
3718
|
-
return;
|
4056
|
+
if (c.type === BREAK_COMPLETION) {
|
4057
|
+
breakCompletions.push(c);
|
3719
4058
|
}
|
3720
4059
|
}
|
4060
|
+
if (normalCompletions.length) {
|
4061
|
+
lastNormalCompletions = normalCompletions;
|
4062
|
+
}
|
4063
|
+
records.push(...breakCompletions);
|
3721
4064
|
}
|
3722
|
-
|
3723
|
-
|
3724
|
-
function _resyncList() {
|
3725
|
-
if (!this.parent || !this.inList) return;
|
3726
|
-
const newContainer = this.parent[this.listKey];
|
3727
|
-
if (this.container === newContainer) return;
|
3728
|
-
this.container = newContainer || null;
|
4065
|
+
records.push(...lastNormalCompletions);
|
4066
|
+
return records;
|
3729
4067
|
}
|
3730
|
-
function
|
3731
|
-
|
3732
|
-
|
3733
|
-
}
|
3734
|
-
}
|
3735
|
-
function popContext() {
|
3736
|
-
this.contexts.pop();
|
3737
|
-
if (this.contexts.length > 0) {
|
3738
|
-
this.setContext(this.contexts[this.contexts.length - 1]);
|
3739
|
-
} else {
|
3740
|
-
this.setContext(undefined);
|
3741
|
-
}
|
3742
|
-
}
|
3743
|
-
function pushContext(context) {
|
3744
|
-
this.contexts.push(context);
|
3745
|
-
this.setContext(context);
|
3746
|
-
}
|
3747
|
-
function setup(parentPath, container, listKey, key) {
|
3748
|
-
this.listKey = listKey;
|
3749
|
-
this.container = container;
|
3750
|
-
this.parentPath = parentPath || this.parentPath;
|
3751
|
-
this.setKey(key);
|
3752
|
-
}
|
3753
|
-
function setKey(key) {
|
3754
|
-
this.key = key;
|
3755
|
-
this.node = this.container[this.key];
|
3756
|
-
this.type = this.node?.type;
|
3757
|
-
}
|
3758
|
-
function requeue(pathToQueue = this) {
|
3759
|
-
if (pathToQueue.removed) return;
|
3760
|
-
{
|
3761
|
-
pathToQueue.shouldSkip = false;
|
3762
|
-
}
|
3763
|
-
const contexts = this.contexts;
|
3764
|
-
for (const context of contexts) {
|
3765
|
-
context.maybeQueue(pathToQueue);
|
3766
|
-
}
|
3767
|
-
}
|
3768
|
-
function _getQueueContexts() {
|
3769
|
-
let path = this;
|
3770
|
-
let contexts = this.contexts;
|
3771
|
-
while (!contexts.length) {
|
3772
|
-
path = path.parentPath;
|
3773
|
-
if (!path) break;
|
3774
|
-
contexts = path.contexts;
|
3775
|
-
}
|
3776
|
-
return contexts;
|
3777
|
-
}
|
3778
|
-
|
3779
|
-
var NodePath_context = /*#__PURE__*/Object.freeze({
|
3780
|
-
__proto__: null,
|
3781
|
-
_call: _call,
|
3782
|
-
_getQueueContexts: _getQueueContexts,
|
3783
|
-
_resyncKey: _resyncKey,
|
3784
|
-
_resyncList: _resyncList,
|
3785
|
-
_resyncParent: _resyncParent,
|
3786
|
-
_resyncRemoved: _resyncRemoved,
|
3787
|
-
call: call,
|
3788
|
-
isBlacklisted: isDenylisted,
|
3789
|
-
isDenylisted: isDenylisted,
|
3790
|
-
popContext: popContext,
|
3791
|
-
pushContext: pushContext,
|
3792
|
-
requeue: requeue,
|
3793
|
-
resync: resync,
|
3794
|
-
setContext: setContext,
|
3795
|
-
setKey: setKey,
|
3796
|
-
setScope: setScope,
|
3797
|
-
setup: setup,
|
3798
|
-
skip: skip,
|
3799
|
-
skipKey: skipKey,
|
3800
|
-
stop: stop,
|
3801
|
-
visit: visit
|
3802
|
-
});
|
3803
|
-
|
3804
|
-
const hooks = [function (self, parent) {
|
3805
|
-
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();
|
3806
|
-
if (removeParent) {
|
3807
|
-
parent.remove();
|
3808
|
-
return true;
|
3809
|
-
}
|
3810
|
-
}, function (self, parent) {
|
3811
|
-
if (parent.isSequenceExpression() && parent.node.expressions.length === 1) {
|
3812
|
-
parent.replaceWith(parent.node.expressions[0]);
|
3813
|
-
return true;
|
3814
|
-
}
|
3815
|
-
}, function (self, parent) {
|
3816
|
-
if (parent.isBinary()) {
|
3817
|
-
if (self.key === "left") {
|
3818
|
-
parent.replaceWith(parent.node.right);
|
3819
|
-
} else {
|
3820
|
-
parent.replaceWith(parent.node.left);
|
3821
|
-
}
|
3822
|
-
return true;
|
3823
|
-
}
|
3824
|
-
}, function (self, parent) {
|
3825
|
-
if (parent.isIfStatement() && self.key === "consequent" || self.key === "body" && (parent.isLoop() || parent.isArrowFunctionExpression())) {
|
3826
|
-
self.replaceWith({
|
3827
|
-
type: "BlockStatement",
|
3828
|
-
body: []
|
3829
|
-
});
|
3830
|
-
return true;
|
3831
|
-
}
|
3832
|
-
}];
|
3833
|
-
|
3834
|
-
const {
|
3835
|
-
getBindingIdentifiers: getBindingIdentifiers$1
|
3836
|
-
} = _t;
|
3837
|
-
function remove() {
|
3838
|
-
this._assertUnremoved();
|
3839
|
-
this.resync();
|
3840
|
-
if (!this.opts?.noScope) {
|
3841
|
-
this._removeFromScope();
|
3842
|
-
}
|
3843
|
-
if (this._callRemovalHooks()) {
|
3844
|
-
this._markRemoved();
|
3845
|
-
return;
|
3846
|
-
}
|
3847
|
-
this.shareCommentsWithSiblings();
|
3848
|
-
this._remove();
|
3849
|
-
this._markRemoved();
|
3850
|
-
}
|
3851
|
-
function _removeFromScope() {
|
3852
|
-
const bindings = getBindingIdentifiers$1(this.node, false, false, true);
|
3853
|
-
Object.keys(bindings).forEach(name => this.scope.removeBinding(name));
|
3854
|
-
}
|
3855
|
-
function _callRemovalHooks() {
|
3856
|
-
if (this.parentPath) {
|
3857
|
-
for (const fn of hooks) {
|
3858
|
-
if (fn(this, this.parentPath)) return true;
|
3859
|
-
}
|
3860
|
-
}
|
3861
|
-
}
|
3862
|
-
function _remove() {
|
3863
|
-
if (Array.isArray(this.container)) {
|
3864
|
-
this.container.splice(this.key, 1);
|
3865
|
-
this.updateSiblingKeys(this.key, -1);
|
3866
|
-
} else {
|
3867
|
-
this._replaceWith(null);
|
3868
|
-
}
|
3869
|
-
}
|
3870
|
-
function _markRemoved() {
|
3871
|
-
this._traverseFlags |= SHOULD_SKIP | REMOVED;
|
3872
|
-
if (this.parent) {
|
3873
|
-
getCachedPaths(this.hub, this.parent).delete(this.node);
|
3874
|
-
}
|
3875
|
-
this.node = null;
|
3876
|
-
}
|
3877
|
-
function _assertUnremoved() {
|
3878
|
-
if (this.removed) {
|
3879
|
-
throw this.buildCodeFrameError("NodePath has been removed so is read-only.");
|
3880
|
-
}
|
3881
|
-
}
|
3882
|
-
|
3883
|
-
var NodePath_removal = /*#__PURE__*/Object.freeze({
|
3884
|
-
__proto__: null,
|
3885
|
-
_assertUnremoved: _assertUnremoved,
|
3886
|
-
_callRemovalHooks: _callRemovalHooks,
|
3887
|
-
_markRemoved: _markRemoved,
|
3888
|
-
_remove: _remove,
|
3889
|
-
_removeFromScope: _removeFromScope,
|
3890
|
-
remove: remove
|
3891
|
-
});
|
3892
|
-
|
3893
|
-
const {
|
3894
|
-
react
|
3895
|
-
} = _t;
|
3896
|
-
const {
|
3897
|
-
cloneNode: cloneNode$1,
|
3898
|
-
jsxExpressionContainer,
|
3899
|
-
variableDeclaration,
|
3900
|
-
variableDeclarator
|
3901
|
-
} = _t;
|
3902
|
-
const referenceVisitor = {
|
3903
|
-
ReferencedIdentifier(path, state) {
|
3904
|
-
if (path.isJSXIdentifier() && react.isCompatTag(path.node.name) && !path.parentPath.isJSXMemberExpression()) {
|
3905
|
-
return;
|
3906
|
-
}
|
3907
|
-
if (path.node.name === "this") {
|
3908
|
-
let scope = path.scope;
|
3909
|
-
do {
|
3910
|
-
if (scope.path.isFunction() && !scope.path.isArrowFunctionExpression()) {
|
3911
|
-
break;
|
3912
|
-
}
|
3913
|
-
} while (scope = scope.parent);
|
3914
|
-
if (scope) state.breakOnScopePaths.push(scope.path);
|
3915
|
-
}
|
3916
|
-
const binding = path.scope.getBinding(path.node.name);
|
3917
|
-
if (!binding) return;
|
3918
|
-
for (const violation of binding.constantViolations) {
|
3919
|
-
if (violation.scope !== binding.path.scope) {
|
3920
|
-
state.mutableBinding = true;
|
3921
|
-
path.stop();
|
3922
|
-
return;
|
3923
|
-
}
|
3924
|
-
}
|
3925
|
-
if (binding !== state.scope.getBinding(path.node.name)) return;
|
3926
|
-
state.bindings[path.node.name] = binding;
|
3927
|
-
}
|
3928
|
-
};
|
3929
|
-
class PathHoister {
|
3930
|
-
breakOnScopePaths;
|
3931
|
-
bindings;
|
3932
|
-
mutableBinding;
|
3933
|
-
scopes;
|
3934
|
-
scope;
|
3935
|
-
path;
|
3936
|
-
attachAfter;
|
3937
|
-
constructor(path, scope) {
|
3938
|
-
this.breakOnScopePaths = [];
|
3939
|
-
this.bindings = {};
|
3940
|
-
this.mutableBinding = false;
|
3941
|
-
this.scopes = [];
|
3942
|
-
this.scope = scope;
|
3943
|
-
this.path = path;
|
3944
|
-
this.attachAfter = false;
|
3945
|
-
}
|
3946
|
-
isCompatibleScope(scope) {
|
3947
|
-
for (const key of Object.keys(this.bindings)) {
|
3948
|
-
const binding = this.bindings[key];
|
3949
|
-
if (!scope.bindingIdentifierEquals(key, binding.identifier)) {
|
3950
|
-
return false;
|
3951
|
-
}
|
3952
|
-
}
|
3953
|
-
return true;
|
3954
|
-
}
|
3955
|
-
getCompatibleScopes() {
|
3956
|
-
let scope = this.path.scope;
|
3957
|
-
do {
|
3958
|
-
if (this.isCompatibleScope(scope)) {
|
3959
|
-
this.scopes.push(scope);
|
3960
|
-
} else {
|
3961
|
-
break;
|
3962
|
-
}
|
3963
|
-
if (this.breakOnScopePaths.indexOf(scope.path) >= 0) {
|
3964
|
-
break;
|
3965
|
-
}
|
3966
|
-
} while (scope = scope.parent);
|
3967
|
-
}
|
3968
|
-
getAttachmentPath() {
|
3969
|
-
let path = this._getAttachmentPath();
|
3970
|
-
if (!path) return;
|
3971
|
-
let targetScope = path.scope;
|
3972
|
-
if (targetScope.path === path) {
|
3973
|
-
targetScope = path.scope.parent;
|
3974
|
-
}
|
3975
|
-
if (targetScope.path.isProgram() || targetScope.path.isFunction()) {
|
3976
|
-
for (const name of Object.keys(this.bindings)) {
|
3977
|
-
if (!targetScope.hasOwnBinding(name)) continue;
|
3978
|
-
const binding = this.bindings[name];
|
3979
|
-
if (binding.kind === "param" || binding.path.parentKey === "params") {
|
3980
|
-
continue;
|
3981
|
-
}
|
3982
|
-
const bindingParentPath = this.getAttachmentParentForPath(binding.path);
|
3983
|
-
if (bindingParentPath.key >= path.key) {
|
3984
|
-
this.attachAfter = true;
|
3985
|
-
path = binding.path;
|
3986
|
-
for (const violationPath of binding.constantViolations) {
|
3987
|
-
if (this.getAttachmentParentForPath(violationPath).key > path.key) {
|
3988
|
-
path = violationPath;
|
3989
|
-
}
|
3990
|
-
}
|
3991
|
-
}
|
3992
|
-
}
|
3993
|
-
}
|
3994
|
-
return path;
|
3995
|
-
}
|
3996
|
-
_getAttachmentPath() {
|
3997
|
-
const scopes = this.scopes;
|
3998
|
-
const scope = scopes.pop();
|
3999
|
-
if (!scope) return;
|
4000
|
-
if (scope.path.isFunction()) {
|
4001
|
-
if (this.hasOwnParamBindings(scope)) {
|
4002
|
-
if (this.scope === scope) return;
|
4003
|
-
const bodies = scope.path.get("body").get("body");
|
4004
|
-
for (let i = 0; i < bodies.length; i++) {
|
4005
|
-
if (bodies[i].node._blockHoist) continue;
|
4006
|
-
return bodies[i];
|
4007
|
-
}
|
4008
|
-
} else {
|
4009
|
-
return this.getNextScopeAttachmentParent();
|
4010
|
-
}
|
4011
|
-
} else if (scope.path.isProgram()) {
|
4012
|
-
return this.getNextScopeAttachmentParent();
|
4013
|
-
}
|
4014
|
-
}
|
4015
|
-
getNextScopeAttachmentParent() {
|
4016
|
-
const scope = this.scopes.pop();
|
4017
|
-
if (scope) return this.getAttachmentParentForPath(scope.path);
|
4018
|
-
}
|
4019
|
-
getAttachmentParentForPath(path) {
|
4020
|
-
do {
|
4021
|
-
if (!path.parentPath || Array.isArray(path.container) && path.isStatement()) {
|
4022
|
-
return path;
|
4023
|
-
}
|
4024
|
-
} while (path = path.parentPath);
|
4025
|
-
}
|
4026
|
-
hasOwnParamBindings(scope) {
|
4027
|
-
for (const name of Object.keys(this.bindings)) {
|
4028
|
-
if (!scope.hasOwnBinding(name)) continue;
|
4029
|
-
const binding = this.bindings[name];
|
4030
|
-
if (binding.kind === "param" && binding.constant) return true;
|
4031
|
-
}
|
4032
|
-
return false;
|
4033
|
-
}
|
4034
|
-
run() {
|
4035
|
-
this.path.traverse(referenceVisitor, this);
|
4036
|
-
if (this.mutableBinding) return;
|
4037
|
-
this.getCompatibleScopes();
|
4038
|
-
const attachTo = this.getAttachmentPath();
|
4039
|
-
if (!attachTo) return;
|
4040
|
-
if (attachTo.getFunctionParent() === this.path.getFunctionParent()) return;
|
4041
|
-
let uid = attachTo.scope.generateUidIdentifier("ref");
|
4042
|
-
const declarator = variableDeclarator(uid, this.path.node);
|
4043
|
-
const insertFn = this.attachAfter ? "insertAfter" : "insertBefore";
|
4044
|
-
const [attached] = attachTo[insertFn]([attachTo.isVariableDeclarator() ? declarator : variableDeclaration("var", [declarator])]);
|
4045
|
-
const parent = this.path.parentPath;
|
4046
|
-
if (parent.isJSXElement() && this.path.container === parent.node.children) {
|
4047
|
-
uid = jsxExpressionContainer(uid);
|
4048
|
-
}
|
4049
|
-
this.path.replaceWith(cloneNode$1(uid));
|
4050
|
-
return attachTo.isVariableDeclarator() ? attached.get("init") : attached.get("declarations.0.init");
|
4051
|
-
}
|
4052
|
-
}
|
4053
|
-
|
4054
|
-
const {
|
4055
|
-
arrowFunctionExpression,
|
4056
|
-
assertExpression,
|
4057
|
-
assignmentExpression,
|
4058
|
-
blockStatement,
|
4059
|
-
callExpression,
|
4060
|
-
cloneNode,
|
4061
|
-
expressionStatement,
|
4062
|
-
isAssignmentExpression,
|
4063
|
-
isCallExpression,
|
4064
|
-
isExportNamedDeclaration,
|
4065
|
-
isExpression,
|
4066
|
-
isIdentifier,
|
4067
|
-
isSequenceExpression,
|
4068
|
-
isSuper,
|
4069
|
-
thisExpression
|
4070
|
-
} = _t;
|
4071
|
-
function insertBefore(nodes_) {
|
4072
|
-
this._assertUnremoved();
|
4073
|
-
const nodes = this._verifyNodeList(nodes_);
|
4074
|
-
const {
|
4075
|
-
parentPath,
|
4076
|
-
parent
|
4077
|
-
} = this;
|
4078
|
-
if (parentPath.isExpressionStatement() || parentPath.isLabeledStatement() || isExportNamedDeclaration(parent) || parentPath.isExportDefaultDeclaration() && this.isDeclaration()) {
|
4079
|
-
return parentPath.insertBefore(nodes);
|
4080
|
-
} else if (this.isNodeType("Expression") && !this.isJSXElement() || parentPath.isForStatement() && this.key === "init") {
|
4081
|
-
if (this.node) nodes.push(this.node);
|
4082
|
-
return this.replaceExpressionWithStatements(nodes);
|
4083
|
-
} else if (Array.isArray(this.container)) {
|
4084
|
-
return this._containerInsertBefore(nodes);
|
4085
|
-
} else if (this.isStatementOrBlock()) {
|
4086
|
-
const node = this.node;
|
4087
|
-
const shouldInsertCurrentNode = node && (!this.isExpressionStatement() || node.expression != null);
|
4088
|
-
this.replaceWith(blockStatement(shouldInsertCurrentNode ? [node] : []));
|
4089
|
-
return this.unshiftContainer("body", nodes);
|
4090
|
-
} else {
|
4091
|
-
throw new Error("We don't know what to do with this node type. " + "We were previously a Statement but we can't fit in here?");
|
4092
|
-
}
|
4093
|
-
}
|
4094
|
-
function _containerInsert(from, nodes) {
|
4095
|
-
this.updateSiblingKeys(from, nodes.length);
|
4096
|
-
const paths = [];
|
4097
|
-
this.container.splice(from, 0, ...nodes);
|
4098
|
-
for (let i = 0; i < nodes.length; i++) {
|
4099
|
-
const to = from + i;
|
4100
|
-
const path = this.getSibling(to);
|
4101
|
-
paths.push(path);
|
4102
|
-
if (this.context?.queue) {
|
4103
|
-
path.pushContext(this.context);
|
4104
|
-
}
|
4105
|
-
}
|
4106
|
-
const contexts = this._getQueueContexts();
|
4107
|
-
for (const path of paths) {
|
4108
|
-
path.setScope();
|
4109
|
-
path.debug("Inserted.");
|
4110
|
-
for (const context of contexts) {
|
4111
|
-
context.maybeQueue(path, true);
|
4112
|
-
}
|
4113
|
-
}
|
4114
|
-
return paths;
|
4115
|
-
}
|
4116
|
-
function _containerInsertBefore(nodes) {
|
4117
|
-
return this._containerInsert(this.key, nodes);
|
4118
|
-
}
|
4119
|
-
function _containerInsertAfter(nodes) {
|
4120
|
-
return this._containerInsert(this.key + 1, nodes);
|
4121
|
-
}
|
4122
|
-
const last = arr => arr[arr.length - 1];
|
4123
|
-
function isHiddenInSequenceExpression(path) {
|
4124
|
-
return isSequenceExpression(path.parent) && (last(path.parent.expressions) !== path.node || isHiddenInSequenceExpression(path.parentPath));
|
4125
|
-
}
|
4126
|
-
function isAlmostConstantAssignment(node, scope) {
|
4127
|
-
if (!isAssignmentExpression(node) || !isIdentifier(node.left)) {
|
4128
|
-
return false;
|
4129
|
-
}
|
4130
|
-
const blockScope = scope.getBlockParent();
|
4131
|
-
return blockScope.hasOwnBinding(node.left.name) && blockScope.getOwnBinding(node.left.name).constantViolations.length <= 1;
|
4132
|
-
}
|
4133
|
-
function insertAfter(nodes_) {
|
4134
|
-
this._assertUnremoved();
|
4135
|
-
if (this.isSequenceExpression()) {
|
4136
|
-
return last(this.get("expressions")).insertAfter(nodes_);
|
4137
|
-
}
|
4138
|
-
const nodes = this._verifyNodeList(nodes_);
|
4139
|
-
const {
|
4140
|
-
parentPath,
|
4141
|
-
parent
|
4142
|
-
} = this;
|
4143
|
-
if (parentPath.isExpressionStatement() || parentPath.isLabeledStatement() || isExportNamedDeclaration(parent) || parentPath.isExportDefaultDeclaration() && this.isDeclaration()) {
|
4144
|
-
return parentPath.insertAfter(nodes.map(node => {
|
4145
|
-
return isExpression(node) ? expressionStatement(node) : node;
|
4146
|
-
}));
|
4147
|
-
} else if (this.isNodeType("Expression") && !this.isJSXElement() && !parentPath.isJSXElement() || parentPath.isForStatement() && this.key === "init") {
|
4148
|
-
if (this.node) {
|
4149
|
-
const node = this.node;
|
4150
|
-
let {
|
4151
|
-
scope
|
4152
|
-
} = this;
|
4153
|
-
if (scope.path.isPattern()) {
|
4154
|
-
assertExpression(node);
|
4155
|
-
this.replaceWith(callExpression(arrowFunctionExpression([], node), []));
|
4156
|
-
this.get("callee.body").insertAfter(nodes);
|
4157
|
-
return [this];
|
4158
|
-
}
|
4159
|
-
if (isHiddenInSequenceExpression(this)) {
|
4160
|
-
nodes.unshift(node);
|
4161
|
-
} else if (isCallExpression(node) && isSuper(node.callee)) {
|
4162
|
-
nodes.unshift(node);
|
4163
|
-
nodes.push(thisExpression());
|
4164
|
-
} else if (isAlmostConstantAssignment(node, scope)) {
|
4165
|
-
nodes.unshift(node);
|
4166
|
-
nodes.push(cloneNode(node.left));
|
4167
|
-
} else if (scope.isPure(node, true)) {
|
4168
|
-
nodes.push(node);
|
4169
|
-
} else {
|
4170
|
-
if (parentPath.isMethod({
|
4171
|
-
computed: true,
|
4172
|
-
key: node
|
4173
|
-
})) {
|
4174
|
-
scope = scope.parent;
|
4175
|
-
}
|
4176
|
-
const temp = scope.generateDeclaredUidIdentifier();
|
4177
|
-
nodes.unshift(expressionStatement(assignmentExpression("=", cloneNode(temp), node)));
|
4178
|
-
nodes.push(expressionStatement(cloneNode(temp)));
|
4179
|
-
}
|
4180
|
-
}
|
4181
|
-
return this.replaceExpressionWithStatements(nodes);
|
4182
|
-
} else if (Array.isArray(this.container)) {
|
4183
|
-
return this._containerInsertAfter(nodes);
|
4184
|
-
} else if (this.isStatementOrBlock()) {
|
4185
|
-
const node = this.node;
|
4186
|
-
const shouldInsertCurrentNode = node && (!this.isExpressionStatement() || node.expression != null);
|
4187
|
-
this.replaceWith(blockStatement(shouldInsertCurrentNode ? [node] : []));
|
4188
|
-
return this.pushContainer("body", nodes);
|
4189
|
-
} else {
|
4190
|
-
throw new Error("We don't know what to do with this node type. " + "We were previously a Statement but we can't fit in here?");
|
4191
|
-
}
|
4192
|
-
}
|
4193
|
-
function updateSiblingKeys(fromIndex, incrementBy) {
|
4194
|
-
if (!this.parent) return;
|
4195
|
-
const paths = getCachedPaths(this.hub, this.parent) || [];
|
4196
|
-
for (const [, path] of paths) {
|
4197
|
-
if (typeof path.key === "number" && path.key >= fromIndex) {
|
4198
|
-
path.key += incrementBy;
|
4199
|
-
}
|
4200
|
-
}
|
4201
|
-
}
|
4202
|
-
function _verifyNodeList(nodes) {
|
4203
|
-
if (!nodes) {
|
4204
|
-
return [];
|
4205
|
-
}
|
4206
|
-
if (!Array.isArray(nodes)) {
|
4207
|
-
nodes = [nodes];
|
4208
|
-
}
|
4209
|
-
for (let i = 0; i < nodes.length; i++) {
|
4210
|
-
const node = nodes[i];
|
4211
|
-
let msg;
|
4212
|
-
if (!node) {
|
4213
|
-
msg = "has falsy node";
|
4214
|
-
} else if (typeof node !== "object") {
|
4215
|
-
msg = "contains a non-object node";
|
4216
|
-
} else if (!node.type) {
|
4217
|
-
msg = "without a type";
|
4218
|
-
} else if (node instanceof NodePath) {
|
4219
|
-
msg = "has a NodePath when it expected a raw object";
|
4220
|
-
}
|
4221
|
-
if (msg) {
|
4222
|
-
const type = Array.isArray(node) ? "array" : typeof node;
|
4223
|
-
throw new Error(`Node list ${msg} with the index of ${i} and type of ${type}`);
|
4224
|
-
}
|
4225
|
-
}
|
4226
|
-
return nodes;
|
4227
|
-
}
|
4228
|
-
function unshiftContainer(listKey, nodes) {
|
4229
|
-
this._assertUnremoved();
|
4230
|
-
nodes = this._verifyNodeList(nodes);
|
4231
|
-
const path = NodePath.get({
|
4232
|
-
parentPath: this,
|
4233
|
-
parent: this.node,
|
4234
|
-
container: this.node[listKey],
|
4235
|
-
listKey,
|
4236
|
-
key: 0
|
4237
|
-
}).setContext(this.context);
|
4238
|
-
return path._containerInsertBefore(nodes);
|
4239
|
-
}
|
4240
|
-
function pushContainer(listKey, nodes) {
|
4241
|
-
this._assertUnremoved();
|
4242
|
-
const verifiedNodes = this._verifyNodeList(nodes);
|
4243
|
-
const container = this.node[listKey];
|
4244
|
-
const path = NodePath.get({
|
4245
|
-
parentPath: this,
|
4246
|
-
parent: this.node,
|
4247
|
-
container: container,
|
4248
|
-
listKey,
|
4249
|
-
key: container.length
|
4250
|
-
}).setContext(this.context);
|
4251
|
-
return path.replaceWithMultiple(verifiedNodes);
|
4252
|
-
}
|
4253
|
-
function hoist(scope = this.scope) {
|
4254
|
-
const hoister = new PathHoister(this, scope);
|
4255
|
-
return hoister.run();
|
4256
|
-
}
|
4257
|
-
|
4258
|
-
var NodePath_modification = /*#__PURE__*/Object.freeze({
|
4259
|
-
__proto__: null,
|
4260
|
-
_containerInsert: _containerInsert,
|
4261
|
-
_containerInsertAfter: _containerInsertAfter,
|
4262
|
-
_containerInsertBefore: _containerInsertBefore,
|
4263
|
-
_verifyNodeList: _verifyNodeList,
|
4264
|
-
hoist: hoist,
|
4265
|
-
insertAfter: insertAfter,
|
4266
|
-
insertBefore: insertBefore,
|
4267
|
-
pushContainer: pushContainer,
|
4268
|
-
unshiftContainer: unshiftContainer,
|
4269
|
-
updateSiblingKeys: updateSiblingKeys
|
4270
|
-
});
|
4271
|
-
|
4272
|
-
const {
|
4273
|
-
getBindingIdentifiers: _getBindingIdentifiers,
|
4274
|
-
getOuterBindingIdentifiers: _getOuterBindingIdentifiers,
|
4275
|
-
isDeclaration,
|
4276
|
-
numericLiteral,
|
4277
|
-
unaryExpression
|
4278
|
-
} = _t;
|
4279
|
-
const NORMAL_COMPLETION = 0;
|
4280
|
-
const BREAK_COMPLETION = 1;
|
4281
|
-
function NormalCompletion(path) {
|
4282
|
-
return {
|
4283
|
-
type: NORMAL_COMPLETION,
|
4284
|
-
path
|
4285
|
-
};
|
4286
|
-
}
|
4287
|
-
function BreakCompletion(path) {
|
4288
|
-
return {
|
4289
|
-
type: BREAK_COMPLETION,
|
4290
|
-
path
|
4291
|
-
};
|
4292
|
-
}
|
4293
|
-
function getOpposite() {
|
4294
|
-
if (this.key === "left") {
|
4295
|
-
return this.getSibling("right");
|
4296
|
-
} else if (this.key === "right") {
|
4297
|
-
return this.getSibling("left");
|
4298
|
-
}
|
4299
|
-
return null;
|
4300
|
-
}
|
4301
|
-
function addCompletionRecords(path, records, context) {
|
4302
|
-
if (path) {
|
4303
|
-
records.push(..._getCompletionRecords(path, context));
|
4304
|
-
}
|
4305
|
-
return records;
|
4306
|
-
}
|
4307
|
-
function completionRecordForSwitch(cases, records, context) {
|
4308
|
-
let lastNormalCompletions = [];
|
4309
|
-
for (let i = 0; i < cases.length; i++) {
|
4310
|
-
const casePath = cases[i];
|
4311
|
-
const caseCompletions = _getCompletionRecords(casePath, context);
|
4312
|
-
const normalCompletions = [];
|
4313
|
-
const breakCompletions = [];
|
4314
|
-
for (const c of caseCompletions) {
|
4315
|
-
if (c.type === NORMAL_COMPLETION) {
|
4316
|
-
normalCompletions.push(c);
|
4317
|
-
}
|
4318
|
-
if (c.type === BREAK_COMPLETION) {
|
4319
|
-
breakCompletions.push(c);
|
4320
|
-
}
|
4321
|
-
}
|
4322
|
-
if (normalCompletions.length) {
|
4323
|
-
lastNormalCompletions = normalCompletions;
|
4324
|
-
}
|
4325
|
-
records.push(...breakCompletions);
|
4326
|
-
}
|
4327
|
-
records.push(...lastNormalCompletions);
|
4328
|
-
return records;
|
4329
|
-
}
|
4330
|
-
function normalCompletionToBreak(completions) {
|
4331
|
-
completions.forEach(c => {
|
4332
|
-
c.type = BREAK_COMPLETION;
|
4333
|
-
});
|
4068
|
+
function normalCompletionToBreak(completions) {
|
4069
|
+
completions.forEach(c => {
|
4070
|
+
c.type = BREAK_COMPLETION;
|
4071
|
+
});
|
4334
4072
|
}
|
4335
4073
|
function replaceBreakStatementInBreakCompletion(completions, reachable) {
|
4336
4074
|
completions.forEach(c => {
|
@@ -4368,12 +4106,16 @@ function getStatementListCompletion(paths, context) {
|
|
4368
4106
|
completions.push(...lastNormalCompletions);
|
4369
4107
|
if (lastNormalCompletions.some(c => c.path.isDeclaration())) {
|
4370
4108
|
completions.push(...statementCompletions);
|
4371
|
-
|
4109
|
+
if (!context.shouldPreserveBreak) {
|
4110
|
+
replaceBreakStatementInBreakCompletion(statementCompletions, true);
|
4111
|
+
}
|
4112
|
+
}
|
4113
|
+
if (!context.shouldPreserveBreak) {
|
4114
|
+
replaceBreakStatementInBreakCompletion(statementCompletions, false);
|
4372
4115
|
}
|
4373
|
-
replaceBreakStatementInBreakCompletion(statementCompletions, false);
|
4374
4116
|
} else {
|
4375
4117
|
completions.push(...statementCompletions);
|
4376
|
-
if (!context.shouldPopulateBreak) {
|
4118
|
+
if (!context.shouldPopulateBreak && !context.shouldPreserveBreak) {
|
4377
4119
|
replaceBreakStatementInBreakCompletion(statementCompletions, true);
|
4378
4120
|
}
|
4379
4121
|
}
|
@@ -4397,7 +4139,7 @@ function getStatementListCompletion(paths, context) {
|
|
4397
4139
|
} else if (paths.length) {
|
4398
4140
|
for (let i = paths.length - 1; i >= 0; i--) {
|
4399
4141
|
const pathCompletions = _getCompletionRecords(paths[i], context);
|
4400
|
-
if (pathCompletions.length > 1 || pathCompletions.length === 1 && !pathCompletions[0].path.isVariableDeclaration()) {
|
4142
|
+
if (pathCompletions.length > 1 || pathCompletions.length === 1 && !pathCompletions[0].path.isVariableDeclaration() && !pathCompletions[0].path.isEmptyStatement()) {
|
4401
4143
|
completions.push(...pathCompletions);
|
4402
4144
|
break;
|
4403
4145
|
}
|
@@ -4427,7 +4169,8 @@ function _getCompletionRecords(path, context) {
|
|
4427
4169
|
return getStatementListCompletion(path.get("consequent"), {
|
4428
4170
|
canHaveBreak: true,
|
4429
4171
|
shouldPopulateBreak: false,
|
4430
|
-
inCaseClause: true
|
4172
|
+
inCaseClause: true,
|
4173
|
+
shouldPreserveBreak: context.shouldPreserveBreak
|
4431
4174
|
});
|
4432
4175
|
} else if (path.isBreakStatement()) {
|
4433
4176
|
records.push(BreakCompletion(path));
|
@@ -4436,16 +4179,17 @@ function _getCompletionRecords(path, context) {
|
|
4436
4179
|
}
|
4437
4180
|
return records;
|
4438
4181
|
}
|
4439
|
-
function getCompletionRecords() {
|
4182
|
+
function getCompletionRecords(shouldPreserveBreak = false) {
|
4440
4183
|
const records = _getCompletionRecords(this, {
|
4441
4184
|
canHaveBreak: false,
|
4442
4185
|
shouldPopulateBreak: false,
|
4443
|
-
inCaseClause: false
|
4186
|
+
inCaseClause: false,
|
4187
|
+
shouldPreserveBreak
|
4444
4188
|
});
|
4445
4189
|
return records.map(r => r.path);
|
4446
4190
|
}
|
4447
4191
|
function getSibling(key) {
|
4448
|
-
return
|
4192
|
+
return NodePath_Final.get({
|
4449
4193
|
parentPath: this.parentPath,
|
4450
4194
|
parent: this.parent,
|
4451
4195
|
container: this.container,
|
@@ -4483,9 +4227,9 @@ function get(key, context = true) {
|
|
4483
4227
|
if (context === true) context = this.context;
|
4484
4228
|
const parts = key.split(".");
|
4485
4229
|
if (parts.length === 1) {
|
4486
|
-
return
|
4230
|
+
return _getKey.call(this, key, context);
|
4487
4231
|
} else {
|
4488
|
-
return
|
4232
|
+
return _getPattern.call(this, parts, context);
|
4489
4233
|
}
|
4490
4234
|
}
|
4491
4235
|
function _getKey(key, context) {
|
@@ -4493,7 +4237,7 @@ function _getKey(key, context) {
|
|
4493
4237
|
const container = node[key];
|
4494
4238
|
if (Array.isArray(container)) {
|
4495
4239
|
return container.map((_, i) => {
|
4496
|
-
return
|
4240
|
+
return NodePath_Final.get({
|
4497
4241
|
listKey: key,
|
4498
4242
|
parentPath: this,
|
4499
4243
|
parent: node,
|
@@ -4502,7 +4246,7 @@ function _getKey(key, context) {
|
|
4502
4246
|
}).setContext(context);
|
4503
4247
|
});
|
4504
4248
|
} else {
|
4505
|
-
return
|
4249
|
+
return NodePath_Final.get({
|
4506
4250
|
parentPath: this,
|
4507
4251
|
parent: node,
|
4508
4252
|
container: node,
|
@@ -4525,6 +4269,9 @@ function _getPattern(parts, context) {
|
|
4525
4269
|
}
|
4526
4270
|
return path;
|
4527
4271
|
}
|
4272
|
+
function getAssignmentIdentifiers() {
|
4273
|
+
return _getAssignmentIdentifiers(this.node);
|
4274
|
+
}
|
4528
4275
|
function getBindingIdentifiers(duplicates) {
|
4529
4276
|
return _getBindingIdentifiers(this.node, duplicates);
|
4530
4277
|
}
|
@@ -4551,7 +4298,7 @@ function getBindingIdentifierPaths(duplicates = false, outerOnly = false) {
|
|
4551
4298
|
}
|
4552
4299
|
if (id.isExportDeclaration()) {
|
4553
4300
|
const declaration = id.get("declaration");
|
4554
|
-
if (isDeclaration(
|
4301
|
+
if (declaration.isDeclaration()) {
|
4555
4302
|
search.push(declaration);
|
4556
4303
|
}
|
4557
4304
|
continue;
|
@@ -4583,24 +4330,6 @@ function getOuterBindingIdentifierPaths(duplicates = false) {
|
|
4583
4330
|
return this.getBindingIdentifierPaths(duplicates, true);
|
4584
4331
|
}
|
4585
4332
|
|
4586
|
-
var NodePath_family = /*#__PURE__*/Object.freeze({
|
4587
|
-
__proto__: null,
|
4588
|
-
_getKey: _getKey,
|
4589
|
-
_getPattern: _getPattern,
|
4590
|
-
get: get,
|
4591
|
-
getAllNextSiblings: getAllNextSiblings,
|
4592
|
-
getAllPrevSiblings: getAllPrevSiblings,
|
4593
|
-
getBindingIdentifierPaths: getBindingIdentifierPaths,
|
4594
|
-
getBindingIdentifiers: getBindingIdentifiers,
|
4595
|
-
getCompletionRecords: getCompletionRecords,
|
4596
|
-
getNextSibling: getNextSibling,
|
4597
|
-
getOpposite: getOpposite,
|
4598
|
-
getOuterBindingIdentifierPaths: getOuterBindingIdentifierPaths,
|
4599
|
-
getOuterBindingIdentifiers: getOuterBindingIdentifiers,
|
4600
|
-
getPrevSibling: getPrevSibling,
|
4601
|
-
getSibling: getSibling
|
4602
|
-
});
|
4603
|
-
|
4604
4333
|
const {
|
4605
4334
|
addComment: _addComment,
|
4606
4335
|
addComments: _addComments
|
@@ -4643,13 +4372,6 @@ function addComments(type, comments) {
|
|
4643
4372
|
_addComments(this.node, type, comments);
|
4644
4373
|
}
|
4645
4374
|
|
4646
|
-
var NodePath_comments = /*#__PURE__*/Object.freeze({
|
4647
|
-
__proto__: null,
|
4648
|
-
addComment: addComment,
|
4649
|
-
addComments: addComments,
|
4650
|
-
shareCommentsWithSiblings: shareCommentsWithSiblings
|
4651
|
-
});
|
4652
|
-
|
4653
4375
|
const {
|
4654
4376
|
validate
|
4655
4377
|
} = _t;
|
@@ -4657,7 +4379,7 @@ const debug = buildDebug("babel");
|
|
4657
4379
|
const REMOVED = 1 << 0;
|
4658
4380
|
const SHOULD_STOP = 1 << 1;
|
4659
4381
|
const SHOULD_SKIP = 1 << 2;
|
4660
|
-
class NodePath {
|
4382
|
+
const NodePath_Final = class NodePath {
|
4661
4383
|
constructor(hub, parent) {
|
4662
4384
|
this.parent = parent;
|
4663
4385
|
this.hub = hub;
|
@@ -4669,6 +4391,24 @@ class NodePath {
|
|
4669
4391
|
state = null;
|
4670
4392
|
opts = null;
|
4671
4393
|
_traverseFlags = 0;
|
4394
|
+
get removed() {
|
4395
|
+
return (this._traverseFlags & 1) > 0;
|
4396
|
+
}
|
4397
|
+
set removed(v) {
|
4398
|
+
if (v) this._traverseFlags |= 1;else this._traverseFlags &= -2;
|
4399
|
+
}
|
4400
|
+
get shouldStop() {
|
4401
|
+
return (this._traverseFlags & 2) > 0;
|
4402
|
+
}
|
4403
|
+
set shouldStop(v) {
|
4404
|
+
if (v) this._traverseFlags |= 2;else this._traverseFlags &= -3;
|
4405
|
+
}
|
4406
|
+
get shouldSkip() {
|
4407
|
+
return (this._traverseFlags & 4) > 0;
|
4408
|
+
}
|
4409
|
+
set shouldSkip(v) {
|
4410
|
+
if (v) this._traverseFlags |= 4;else this._traverseFlags &= -5;
|
4411
|
+
}
|
4672
4412
|
skipKeys = null;
|
4673
4413
|
parentPath = null;
|
4674
4414
|
container = null;
|
@@ -4676,6 +4416,7 @@ class NodePath {
|
|
4676
4416
|
key = null;
|
4677
4417
|
node = null;
|
4678
4418
|
type = null;
|
4419
|
+
_store = null;
|
4679
4420
|
static get({
|
4680
4421
|
hub,
|
4681
4422
|
parentPath,
|
@@ -4691,13 +4432,13 @@ class NodePath {
|
|
4691
4432
|
throw new Error("To get a node path the parent needs to exist");
|
4692
4433
|
}
|
4693
4434
|
const targetNode = container[key];
|
4694
|
-
const paths = getOrCreateCachedPaths(
|
4435
|
+
const paths = getOrCreateCachedPaths(parent, parentPath);
|
4695
4436
|
let path = paths.get(targetNode);
|
4696
4437
|
if (!path) {
|
4697
4438
|
path = new NodePath(hub, parent);
|
4698
4439
|
if (targetNode) paths.set(targetNode, path);
|
4699
4440
|
}
|
4700
|
-
|
4441
|
+
setup.call(path, parentPath, container, listKey, key);
|
4701
4442
|
return path;
|
4702
4443
|
}
|
4703
4444
|
getScope(scope) {
|
@@ -4758,51 +4499,94 @@ class NodePath {
|
|
4758
4499
|
get parentKey() {
|
4759
4500
|
return this.listKey || this.key;
|
4760
4501
|
}
|
4761
|
-
|
4762
|
-
|
4763
|
-
|
4764
|
-
|
4765
|
-
|
4766
|
-
|
4767
|
-
|
4768
|
-
|
4769
|
-
|
4770
|
-
|
4771
|
-
|
4772
|
-
|
4773
|
-
|
4774
|
-
|
4775
|
-
|
4776
|
-
|
4777
|
-
|
4778
|
-
|
4779
|
-
|
4780
|
-
|
4781
|
-
|
4782
|
-
|
4783
|
-
|
4784
|
-
|
4785
|
-
|
4786
|
-
|
4787
|
-
|
4788
|
-
|
4789
|
-
|
4790
|
-
|
4791
|
-
|
4792
|
-
|
4502
|
+
};
|
4503
|
+
const methods = {
|
4504
|
+
findParent: findParent,
|
4505
|
+
find: find,
|
4506
|
+
getFunctionParent: getFunctionParent,
|
4507
|
+
getStatementParent: getStatementParent,
|
4508
|
+
getEarliestCommonAncestorFrom: getEarliestCommonAncestorFrom,
|
4509
|
+
getDeepestCommonAncestorFrom: getDeepestCommonAncestorFrom,
|
4510
|
+
getAncestry: getAncestry,
|
4511
|
+
isAncestor: isAncestor,
|
4512
|
+
isDescendant: isDescendant,
|
4513
|
+
inType: inType,
|
4514
|
+
getTypeAnnotation: getTypeAnnotation,
|
4515
|
+
isBaseType: isBaseType,
|
4516
|
+
couldBeBaseType: couldBeBaseType,
|
4517
|
+
baseTypeStrictlyMatches: baseTypeStrictlyMatches,
|
4518
|
+
isGenericType: isGenericType,
|
4519
|
+
replaceWithMultiple: replaceWithMultiple,
|
4520
|
+
replaceWithSourceString: replaceWithSourceString,
|
4521
|
+
replaceWith: replaceWith,
|
4522
|
+
replaceExpressionWithStatements: replaceExpressionWithStatements,
|
4523
|
+
replaceInline: replaceInline,
|
4524
|
+
evaluateTruthy: evaluateTruthy,
|
4525
|
+
evaluate: evaluate,
|
4526
|
+
toComputedKey: toComputedKey,
|
4527
|
+
ensureBlock: ensureBlock,
|
4528
|
+
unwrapFunctionEnvironment: unwrapFunctionEnvironment,
|
4529
|
+
arrowFunctionToExpression: arrowFunctionToExpression,
|
4530
|
+
splitExportDeclaration: splitExportDeclaration,
|
4531
|
+
ensureFunctionName: ensureFunctionName,
|
4532
|
+
matchesPattern: matchesPattern,
|
4533
|
+
isStatic: isStatic,
|
4534
|
+
isNodeType: isNodeType,
|
4535
|
+
canHaveVariableDeclarationOrExpression: canHaveVariableDeclarationOrExpression,
|
4536
|
+
canSwapBetweenExpressionAndStatement: canSwapBetweenExpressionAndStatement,
|
4537
|
+
isCompletionRecord: isCompletionRecord,
|
4538
|
+
isStatementOrBlock: isStatementOrBlock,
|
4539
|
+
referencesImport: referencesImport,
|
4540
|
+
getSource: getSource,
|
4541
|
+
willIMaybeExecuteBefore: willIMaybeExecuteBefore,
|
4542
|
+
_guessExecutionStatusRelativeTo: _guessExecutionStatusRelativeTo,
|
4543
|
+
resolve: resolve,
|
4544
|
+
isConstantExpression: isConstantExpression,
|
4545
|
+
isInStrictMode: isInStrictMode,
|
4546
|
+
isDenylisted: isDenylisted,
|
4547
|
+
visit: visit,
|
4548
|
+
skip: skip,
|
4549
|
+
skipKey: skipKey,
|
4550
|
+
stop: stop,
|
4551
|
+
setContext: setContext,
|
4552
|
+
requeue: requeue,
|
4553
|
+
requeueComputedKeyAndDecorators: requeueComputedKeyAndDecorators,
|
4554
|
+
remove: remove,
|
4555
|
+
insertBefore: insertBefore,
|
4556
|
+
insertAfter: insertAfter,
|
4557
|
+
unshiftContainer: unshiftContainer,
|
4558
|
+
pushContainer: pushContainer,
|
4559
|
+
getOpposite: getOpposite,
|
4560
|
+
getCompletionRecords: getCompletionRecords,
|
4561
|
+
getSibling: getSibling,
|
4562
|
+
getPrevSibling: getPrevSibling,
|
4563
|
+
getNextSibling: getNextSibling,
|
4564
|
+
getAllNextSiblings: getAllNextSiblings,
|
4565
|
+
getAllPrevSiblings: getAllPrevSiblings,
|
4566
|
+
get: get,
|
4567
|
+
getAssignmentIdentifiers: getAssignmentIdentifiers,
|
4568
|
+
getBindingIdentifiers: getBindingIdentifiers,
|
4569
|
+
getOuterBindingIdentifiers: getOuterBindingIdentifiers,
|
4570
|
+
getBindingIdentifierPaths: getBindingIdentifierPaths,
|
4571
|
+
getOuterBindingIdentifierPaths: getOuterBindingIdentifierPaths,
|
4572
|
+
shareCommentsWithSiblings: shareCommentsWithSiblings,
|
4573
|
+
addComment: addComment,
|
4574
|
+
addComments: addComments
|
4575
|
+
};
|
4576
|
+
Object.assign(NodePath_Final.prototype, methods);
|
4793
4577
|
for (const type of _t.TYPES) {
|
4794
4578
|
const typeKey = `is${type}`;
|
4795
4579
|
const fn = _t[typeKey];
|
4796
|
-
|
4580
|
+
NodePath_Final.prototype[typeKey] = function (opts) {
|
4797
4581
|
return fn(this.node, opts);
|
4798
4582
|
};
|
4799
|
-
|
4583
|
+
NodePath_Final.prototype[`assert${type}`] = function (opts) {
|
4800
4584
|
if (!fn(this.node, opts)) {
|
4801
4585
|
throw new TypeError(`Expected node path of type ${type}`);
|
4802
4586
|
}
|
4803
4587
|
};
|
4804
4588
|
}
|
4805
|
-
Object.assign(
|
4589
|
+
Object.assign(NodePath_Final.prototype, NodePath_virtual_types_validator);
|
4806
4590
|
for (const type of Object.keys(virtualTypes)) {
|
4807
4591
|
if (type[0] === "_") continue;
|
4808
4592
|
if (!_t.TYPES.includes(type)) _t.TYPES.push(type);
|
@@ -4834,7 +4618,7 @@ class TraversalContext {
|
|
4834
4618
|
return false;
|
4835
4619
|
}
|
4836
4620
|
create(node, container, key, listKey) {
|
4837
|
-
return
|
4621
|
+
return NodePath_Final.get({
|
4838
4622
|
parentPath: this.parentPath,
|
4839
4623
|
parent: node,
|
4840
4624
|
container,
|
@@ -4878,9 +4662,9 @@ class TraversalContext {
|
|
4878
4662
|
for (; visitIndex < queue.length;) {
|
4879
4663
|
const path = queue[visitIndex];
|
4880
4664
|
visitIndex++;
|
4881
|
-
|
4665
|
+
resync.call(path);
|
4882
4666
|
if (path.contexts.length === 0 || path.contexts[path.contexts.length - 1] !== this) {
|
4883
|
-
|
4667
|
+
pushContext.call(path, this);
|
4884
4668
|
}
|
4885
4669
|
if (path.key === null) continue;
|
4886
4670
|
const {
|
@@ -4900,7 +4684,7 @@ class TraversalContext {
|
|
4900
4684
|
}
|
4901
4685
|
}
|
4902
4686
|
for (let i = 0; i < visitIndex; i++) {
|
4903
|
-
queue[i]
|
4687
|
+
popContext.call(queue[i]);
|
4904
4688
|
}
|
4905
4689
|
this.queue = null;
|
4906
4690
|
return stop;
|
@@ -4919,22 +4703,313 @@ class TraversalContext {
|
|
4919
4703
|
const {
|
4920
4704
|
VISITOR_KEYS: VISITOR_KEYS$1
|
4921
4705
|
} = _t;
|
4922
|
-
function
|
4706
|
+
function _visitPaths(ctx, paths) {
|
4707
|
+
ctx.queue = paths;
|
4708
|
+
ctx.priorityQueue = [];
|
4709
|
+
const visited = new Set();
|
4710
|
+
let stop = false;
|
4711
|
+
let visitIndex = 0;
|
4712
|
+
for (; visitIndex < paths.length;) {
|
4713
|
+
const path = paths[visitIndex];
|
4714
|
+
visitIndex++;
|
4715
|
+
resync.call(path);
|
4716
|
+
if (path.contexts.length === 0 || path.contexts[path.contexts.length - 1] !== ctx) {
|
4717
|
+
pushContext.call(path, ctx);
|
4718
|
+
}
|
4719
|
+
if (path.key === null) continue;
|
4720
|
+
const {
|
4721
|
+
node
|
4722
|
+
} = path;
|
4723
|
+
if (visited.has(node)) continue;
|
4724
|
+
if (node) visited.add(node);
|
4725
|
+
if (_visit(ctx, path)) {
|
4726
|
+
stop = true;
|
4727
|
+
break;
|
4728
|
+
}
|
4729
|
+
if (ctx.priorityQueue.length) {
|
4730
|
+
stop = _visitPaths(ctx, ctx.priorityQueue);
|
4731
|
+
ctx.priorityQueue = [];
|
4732
|
+
ctx.queue = paths;
|
4733
|
+
if (stop) break;
|
4734
|
+
}
|
4735
|
+
}
|
4736
|
+
for (let i = 0; i < visitIndex; i++) {
|
4737
|
+
popContext.call(paths[i]);
|
4738
|
+
}
|
4739
|
+
ctx.queue = null;
|
4740
|
+
return stop;
|
4741
|
+
}
|
4742
|
+
function _visit(ctx, path) {
|
4743
|
+
const node = path.node;
|
4744
|
+
if (!node) {
|
4745
|
+
return false;
|
4746
|
+
}
|
4747
|
+
const opts = ctx.opts;
|
4748
|
+
const denylist = opts.denylist ?? opts.blacklist;
|
4749
|
+
if (denylist?.includes(node.type)) {
|
4750
|
+
return false;
|
4751
|
+
}
|
4752
|
+
if (opts.shouldSkip?.(path)) {
|
4753
|
+
return false;
|
4754
|
+
}
|
4755
|
+
if (path.shouldSkip) return path.shouldStop;
|
4756
|
+
if (_call.call(path, opts.enter)) return path.shouldStop;
|
4757
|
+
if (path.node) {
|
4758
|
+
if (_call.call(path, opts[node.type]?.enter)) return path.shouldStop;
|
4759
|
+
}
|
4760
|
+
path.shouldStop = _traverse(path.node, opts, path.scope, ctx.state, path, path.skipKeys);
|
4761
|
+
if (path.node) {
|
4762
|
+
if (_call.call(path, opts.exit)) return true;
|
4763
|
+
}
|
4764
|
+
if (path.node) {
|
4765
|
+
_call.call(path, opts[node.type]?.exit);
|
4766
|
+
}
|
4767
|
+
return path.shouldStop;
|
4768
|
+
}
|
4769
|
+
function _traverse(node, opts, scope, state, path, skipKeys, visitSelf) {
|
4923
4770
|
const keys = VISITOR_KEYS$1[node.type];
|
4924
|
-
if (!keys) return false;
|
4925
|
-
const
|
4771
|
+
if (!keys?.length) return false;
|
4772
|
+
const ctx = new TraversalContext(scope, opts, state, path);
|
4926
4773
|
if (visitSelf) {
|
4927
4774
|
if (skipKeys?.[path.parentKey]) return false;
|
4928
|
-
return
|
4775
|
+
return _visitPaths(ctx, [path]);
|
4929
4776
|
}
|
4930
4777
|
for (const key of keys) {
|
4931
4778
|
if (skipKeys?.[key]) continue;
|
4932
|
-
|
4933
|
-
|
4779
|
+
const prop = node[key];
|
4780
|
+
if (!prop) continue;
|
4781
|
+
if (Array.isArray(prop)) {
|
4782
|
+
if (!prop.length) continue;
|
4783
|
+
const paths = [];
|
4784
|
+
for (let i = 0; i < prop.length; i++) {
|
4785
|
+
const childPath = NodePath_Final.get({
|
4786
|
+
parentPath: path,
|
4787
|
+
parent: node,
|
4788
|
+
container: prop,
|
4789
|
+
key: i,
|
4790
|
+
listKey: key
|
4791
|
+
});
|
4792
|
+
paths.push(childPath);
|
4793
|
+
}
|
4794
|
+
if (_visitPaths(ctx, paths)) return true;
|
4795
|
+
} else {
|
4796
|
+
if (_visitPaths(ctx, [NodePath_Final.get({
|
4797
|
+
parentPath: path,
|
4798
|
+
parent: node,
|
4799
|
+
container: node,
|
4800
|
+
key,
|
4801
|
+
listKey: null
|
4802
|
+
})])) {
|
4803
|
+
return true;
|
4804
|
+
}
|
4934
4805
|
}
|
4935
4806
|
}
|
4936
4807
|
return false;
|
4937
4808
|
}
|
4809
|
+
function traverseNode(node, opts, scope, state, path, skipKeys, visitSelf) {
|
4810
|
+
{
|
4811
|
+
return _traverse(node, opts, scope, state, path, skipKeys, visitSelf);
|
4812
|
+
}
|
4813
|
+
}
|
4814
|
+
|
4815
|
+
function call(key) {
|
4816
|
+
const opts = this.opts;
|
4817
|
+
this.debug(key);
|
4818
|
+
if (this.node) {
|
4819
|
+
if (_call.call(this, opts[key])) return true;
|
4820
|
+
}
|
4821
|
+
if (this.node) {
|
4822
|
+
return _call.call(this, opts[this.node.type]?.[key]);
|
4823
|
+
}
|
4824
|
+
return false;
|
4825
|
+
}
|
4826
|
+
function _call(fns) {
|
4827
|
+
if (!fns) return false;
|
4828
|
+
for (const fn of fns) {
|
4829
|
+
if (!fn) continue;
|
4830
|
+
const node = this.node;
|
4831
|
+
if (!node) return true;
|
4832
|
+
const ret = fn.call(this.state, this, this.state);
|
4833
|
+
if (ret && typeof ret === "object" && typeof ret.then === "function") {
|
4834
|
+
throw new Error(`You appear to be using a plugin with an async traversal visitor, ` + `which your current version of Babel does not support. ` + `If you're using a published plugin, you may need to upgrade ` + `your @babel/core version.`);
|
4835
|
+
}
|
4836
|
+
if (ret) {
|
4837
|
+
throw new Error(`Unexpected return value from visitor method ${fn}`);
|
4838
|
+
}
|
4839
|
+
if (this.node !== node) return true;
|
4840
|
+
if (this._traverseFlags > 0) return true;
|
4841
|
+
}
|
4842
|
+
return false;
|
4843
|
+
}
|
4844
|
+
function isDenylisted() {
|
4845
|
+
const denylist = this.opts.denylist ?? this.opts.blacklist;
|
4846
|
+
return denylist?.includes(this.node.type);
|
4847
|
+
}
|
4848
|
+
function restoreContext(path, context) {
|
4849
|
+
if (path.context !== context) {
|
4850
|
+
path.context = context;
|
4851
|
+
path.state = context.state;
|
4852
|
+
path.opts = context.opts;
|
4853
|
+
}
|
4854
|
+
}
|
4855
|
+
function visit() {
|
4856
|
+
if (!this.node) {
|
4857
|
+
return false;
|
4858
|
+
}
|
4859
|
+
if (this.isDenylisted()) {
|
4860
|
+
return false;
|
4861
|
+
}
|
4862
|
+
if (this.opts.shouldSkip?.(this)) {
|
4863
|
+
return false;
|
4864
|
+
}
|
4865
|
+
const currentContext = this.context;
|
4866
|
+
if (this.shouldSkip || call.call(this, "enter")) {
|
4867
|
+
this.debug("Skip...");
|
4868
|
+
return this.shouldStop;
|
4869
|
+
}
|
4870
|
+
restoreContext(this, currentContext);
|
4871
|
+
this.debug("Recursing into...");
|
4872
|
+
this.shouldStop = traverseNode(this.node, this.opts, this.scope, this.state, this, this.skipKeys);
|
4873
|
+
restoreContext(this, currentContext);
|
4874
|
+
call.call(this, "exit");
|
4875
|
+
return this.shouldStop;
|
4876
|
+
}
|
4877
|
+
function skip() {
|
4878
|
+
this.shouldSkip = true;
|
4879
|
+
}
|
4880
|
+
function skipKey(key) {
|
4881
|
+
if (this.skipKeys == null) {
|
4882
|
+
this.skipKeys = {};
|
4883
|
+
}
|
4884
|
+
this.skipKeys[key] = true;
|
4885
|
+
}
|
4886
|
+
function stop() {
|
4887
|
+
this._traverseFlags |= SHOULD_SKIP | SHOULD_STOP;
|
4888
|
+
}
|
4889
|
+
function setScope() {
|
4890
|
+
if (this.opts?.noScope) return;
|
4891
|
+
let path = this.parentPath;
|
4892
|
+
if ((this.key === "key" || this.listKey === "decorators") && path.isMethod() || this.key === "discriminant" && path.isSwitchStatement()) {
|
4893
|
+
path = path.parentPath;
|
4894
|
+
}
|
4895
|
+
let target;
|
4896
|
+
while (path && !target) {
|
4897
|
+
if (path.opts?.noScope) return;
|
4898
|
+
target = path.scope;
|
4899
|
+
path = path.parentPath;
|
4900
|
+
}
|
4901
|
+
this.scope = this.getScope(target);
|
4902
|
+
this.scope?.init();
|
4903
|
+
}
|
4904
|
+
function setContext(context) {
|
4905
|
+
if (this.skipKeys != null) {
|
4906
|
+
this.skipKeys = {};
|
4907
|
+
}
|
4908
|
+
this._traverseFlags = 0;
|
4909
|
+
if (context) {
|
4910
|
+
this.context = context;
|
4911
|
+
this.state = context.state;
|
4912
|
+
this.opts = context.opts;
|
4913
|
+
}
|
4914
|
+
setScope.call(this);
|
4915
|
+
return this;
|
4916
|
+
}
|
4917
|
+
function resync() {
|
4918
|
+
if (this.removed) return;
|
4919
|
+
_resyncParent.call(this);
|
4920
|
+
_resyncList.call(this);
|
4921
|
+
_resyncKey.call(this);
|
4922
|
+
}
|
4923
|
+
function _resyncParent() {
|
4924
|
+
if (this.parentPath) {
|
4925
|
+
this.parent = this.parentPath.node;
|
4926
|
+
}
|
4927
|
+
}
|
4928
|
+
function _resyncKey() {
|
4929
|
+
if (!this.container) return;
|
4930
|
+
if (this.node === this.container[this.key]) {
|
4931
|
+
return;
|
4932
|
+
}
|
4933
|
+
if (Array.isArray(this.container)) {
|
4934
|
+
for (let i = 0; i < this.container.length; i++) {
|
4935
|
+
if (this.container[i] === this.node) {
|
4936
|
+
setKey.call(this, i);
|
4937
|
+
return;
|
4938
|
+
}
|
4939
|
+
}
|
4940
|
+
} else {
|
4941
|
+
for (const key of Object.keys(this.container)) {
|
4942
|
+
if (this.container[key] === this.node) {
|
4943
|
+
setKey.call(this, key);
|
4944
|
+
return;
|
4945
|
+
}
|
4946
|
+
}
|
4947
|
+
}
|
4948
|
+
this.key = null;
|
4949
|
+
}
|
4950
|
+
function _resyncList() {
|
4951
|
+
if (!this.parent || !this.inList) return;
|
4952
|
+
const newContainer = this.parent[this.listKey];
|
4953
|
+
if (this.container === newContainer) return;
|
4954
|
+
this.container = newContainer || null;
|
4955
|
+
}
|
4956
|
+
function popContext() {
|
4957
|
+
this.contexts.pop();
|
4958
|
+
if (this.contexts.length > 0) {
|
4959
|
+
this.setContext(this.contexts[this.contexts.length - 1]);
|
4960
|
+
} else {
|
4961
|
+
this.setContext(undefined);
|
4962
|
+
}
|
4963
|
+
}
|
4964
|
+
function pushContext(context) {
|
4965
|
+
this.contexts.push(context);
|
4966
|
+
this.setContext(context);
|
4967
|
+
}
|
4968
|
+
function setup(parentPath, container, listKey, key) {
|
4969
|
+
this.listKey = listKey;
|
4970
|
+
this.container = container;
|
4971
|
+
this.parentPath = parentPath || this.parentPath;
|
4972
|
+
setKey.call(this, key);
|
4973
|
+
}
|
4974
|
+
function setKey(key) {
|
4975
|
+
this.key = key;
|
4976
|
+
this.node = this.container[this.key];
|
4977
|
+
this.type = this.node?.type;
|
4978
|
+
}
|
4979
|
+
function requeue(pathToQueue = this) {
|
4980
|
+
if (pathToQueue.removed) return;
|
4981
|
+
{
|
4982
|
+
pathToQueue.shouldSkip = false;
|
4983
|
+
}
|
4984
|
+
const contexts = this.contexts;
|
4985
|
+
for (const context of contexts) {
|
4986
|
+
context.maybeQueue(pathToQueue);
|
4987
|
+
}
|
4988
|
+
}
|
4989
|
+
function requeueComputedKeyAndDecorators() {
|
4990
|
+
const {
|
4991
|
+
context,
|
4992
|
+
node
|
4993
|
+
} = this;
|
4994
|
+
if (!_t.isPrivate(node) && node.computed) {
|
4995
|
+
context.maybeQueue(this.get("key"));
|
4996
|
+
}
|
4997
|
+
if (node.decorators) {
|
4998
|
+
for (const decorator of this.get("decorators")) {
|
4999
|
+
context.maybeQueue(decorator);
|
5000
|
+
}
|
5001
|
+
}
|
5002
|
+
}
|
5003
|
+
function _getQueueContexts() {
|
5004
|
+
let path = this;
|
5005
|
+
let contexts = this.contexts;
|
5006
|
+
while (!contexts.length) {
|
5007
|
+
path = path.parentPath;
|
5008
|
+
if (!path) break;
|
5009
|
+
contexts = path.contexts;
|
5010
|
+
}
|
5011
|
+
return contexts;
|
5012
|
+
}
|
4938
5013
|
|
4939
5014
|
class Hub {
|
4940
5015
|
getCode() {}
|
@@ -4965,12 +5040,12 @@ function traverse(parent, opts = {}, scope, state, parentPath, visitSelf) {
|
|
4965
5040
|
if (!VISITOR_KEYS[parent.type]) {
|
4966
5041
|
return;
|
4967
5042
|
}
|
4968
|
-
explode(opts);
|
5043
|
+
explode$1(opts);
|
4969
5044
|
traverseNode(parent, opts, scope, state, parentPath, null, visitSelf);
|
4970
5045
|
}
|
4971
5046
|
traverse.visitors = visitors;
|
4972
|
-
traverse.verify = verify;
|
4973
|
-
traverse.explode = explode;
|
5047
|
+
traverse.verify = verify$1;
|
5048
|
+
traverse.explode = explode$1;
|
4974
5049
|
traverse.cheap = function (node, enter) {
|
4975
5050
|
traverseFast(node, enter);
|
4976
5051
|
return;
|
@@ -4985,27 +5060,19 @@ traverse.removeProperties = function (tree, opts) {
|
|
4985
5060
|
traverseFast(tree, traverse.clearNode, opts);
|
4986
5061
|
return tree;
|
4987
5062
|
};
|
4988
|
-
function hasDenylistedType(path, state) {
|
4989
|
-
if (path.node.type === state.type) {
|
4990
|
-
state.has = true;
|
4991
|
-
path.stop();
|
4992
|
-
}
|
4993
|
-
}
|
4994
5063
|
traverse.hasType = function (tree, type, denylistTypes) {
|
4995
5064
|
if (denylistTypes?.includes(tree.type)) return false;
|
4996
5065
|
if (tree.type === type) return true;
|
4997
|
-
|
4998
|
-
|
4999
|
-
|
5000
|
-
|
5001
|
-
|
5002
|
-
|
5003
|
-
|
5004
|
-
|
5005
|
-
}, null, state);
|
5006
|
-
return state.has;
|
5066
|
+
return traverseFast(tree, function (node) {
|
5067
|
+
if (denylistTypes?.includes(node.type)) {
|
5068
|
+
return traverseFast.skip;
|
5069
|
+
}
|
5070
|
+
if (node.type === type) {
|
5071
|
+
return traverseFast.stop;
|
5072
|
+
}
|
5073
|
+
});
|
5007
5074
|
};
|
5008
5075
|
traverse.cache = cache;
|
5009
5076
|
|
5010
|
-
export { Hub, NodePath, Scope, traverse as default, visitors };
|
5077
|
+
export { Hub, NodePath_Final as NodePath, Scope, traverse as default, visitors };
|
5011
5078
|
//# sourceMappingURL=index.js.map
|