@babel/traverse 8.0.0-alpha.1 → 8.0.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +171 -160
- package/lib/index.js.map +1 -1
- package/package.json +11 -10
- package/lib/cache.js +0 -14
- package/lib/cache.js.map +0 -1
- package/lib/context.js +0 -108
- package/lib/context.js.map +0 -1
- package/lib/hub.js +0 -12
- package/lib/hub.js.map +0 -1
- package/lib/path/ancestry.js +0 -126
- package/lib/path/ancestry.js.map +0 -1
- package/lib/path/comments.js +0 -46
- package/lib/path/comments.js.map +0 -1
- package/lib/path/context.js +0 -194
- package/lib/path/context.js.map +0 -1
- package/lib/path/conversion.js +0 -453
- package/lib/path/conversion.js.map +0 -1
- package/lib/path/evaluation.js +0 -333
- package/lib/path/evaluation.js.map +0 -1
- package/lib/path/family.js +0 -322
- package/lib/path/family.js.map +0 -1
- package/lib/path/index.js +0 -185
- package/lib/path/index.js.map +0 -1
- package/lib/path/inference/index.js +0 -137
- package/lib/path/inference/index.js.map +0 -1
- package/lib/path/inference/inferer-reference.js +0 -145
- package/lib/path/inference/inferer-reference.js.map +0 -1
- package/lib/path/inference/inferers.js +0 -172
- package/lib/path/inference/inferers.js.map +0 -1
- package/lib/path/inference/util.js +0 -20
- package/lib/path/inference/util.js.map +0 -1
- package/lib/path/introspection.js +0 -360
- package/lib/path/introspection.js.map +0 -1
- package/lib/path/lib/hoister.js +0 -164
- package/lib/path/lib/hoister.js.map +0 -1
- package/lib/path/lib/removal-hooks.js +0 -31
- package/lib/path/lib/removal-hooks.js.map +0 -1
- package/lib/path/lib/virtual-types-validator.js +0 -138
- package/lib/path/lib/virtual-types-validator.js.map +0 -1
- package/lib/path/lib/virtual-types.js +0 -20
- package/lib/path/lib/virtual-types.js.map +0 -1
- package/lib/path/modification.js +0 -209
- package/lib/path/modification.js.map +0 -1
- package/lib/path/removal.js +0 -46
- package/lib/path/removal.js.map +0 -1
- package/lib/path/replacement.js +0 -192
- package/lib/path/replacement.js.map +0 -1
- package/lib/scope/binding.js +0 -78
- package/lib/scope/binding.js.map +0 -1
- package/lib/scope/index.js +0 -870
- package/lib/scope/index.js.map +0 -1
- package/lib/scope/lib/renamer.js +0 -105
- package/lib/scope/lib/renamer.js.map +0 -1
- package/lib/traverse-node.js +0 -19
- package/lib/traverse-node.js.map +0 -1
- package/lib/types.js +0 -3
- package/lib/types.js.map +0 -1
- package/lib/visitors.js +0 -210
- package/lib/visitors.js.map +0 -1
package/lib/index.js
CHANGED
@@ -30,24 +30,24 @@ const ForAwaitStatement = ["ForOfStatement"];
|
|
30
30
|
|
31
31
|
var virtualTypes = /*#__PURE__*/Object.freeze({
|
32
32
|
__proto__: null,
|
33
|
-
ReferencedIdentifier: ReferencedIdentifier,
|
34
|
-
ReferencedMemberExpression: ReferencedMemberExpression,
|
35
33
|
BindingIdentifier: BindingIdentifier,
|
36
|
-
Statement: Statement,
|
37
|
-
Expression: Expression,
|
38
|
-
Scope: Scope$1,
|
39
|
-
Referenced: Referenced,
|
40
34
|
BlockScoped: BlockScoped,
|
41
|
-
|
42
|
-
|
35
|
+
ExistentialTypeParam: ExistentialTypeParam,
|
36
|
+
Expression: Expression,
|
37
|
+
Flow: Flow,
|
38
|
+
ForAwaitStatement: ForAwaitStatement,
|
43
39
|
Generated: Generated,
|
40
|
+
NumericLiteralTypeAnnotation: NumericLiteralTypeAnnotation,
|
44
41
|
Pure: Pure,
|
45
|
-
|
42
|
+
Referenced: Referenced,
|
43
|
+
ReferencedIdentifier: ReferencedIdentifier,
|
44
|
+
ReferencedMemberExpression: ReferencedMemberExpression,
|
46
45
|
RestProperty: RestProperty,
|
46
|
+
Scope: Scope$1,
|
47
47
|
SpreadProperty: SpreadProperty,
|
48
|
-
|
49
|
-
|
50
|
-
|
48
|
+
Statement: Statement,
|
49
|
+
User: User,
|
50
|
+
Var: Var
|
51
51
|
});
|
52
52
|
|
53
53
|
const {
|
@@ -257,32 +257,45 @@ function mergePair(dest, src) {
|
|
257
257
|
|
258
258
|
var visitors = /*#__PURE__*/Object.freeze({
|
259
259
|
__proto__: null,
|
260
|
-
isExplodedVisitor: isExplodedVisitor,
|
261
260
|
explode: explode,
|
262
|
-
|
263
|
-
merge: merge
|
261
|
+
isExplodedVisitor: isExplodedVisitor,
|
262
|
+
merge: merge,
|
263
|
+
verify: verify
|
264
264
|
});
|
265
265
|
|
266
|
-
let
|
266
|
+
let pathsCache = new WeakMap();
|
267
267
|
let scope = new WeakMap();
|
268
268
|
function clear() {
|
269
269
|
clearPath();
|
270
270
|
clearScope();
|
271
271
|
}
|
272
272
|
function clearPath() {
|
273
|
-
|
273
|
+
pathsCache = new WeakMap();
|
274
274
|
}
|
275
275
|
function clearScope() {
|
276
276
|
scope = new WeakMap();
|
277
277
|
}
|
278
|
+
const nullHub = Object.freeze({});
|
279
|
+
function getCachedPaths(hub, parent) {
|
280
|
+
return pathsCache.get(hub ?? nullHub)?.get(parent);
|
281
|
+
}
|
282
|
+
function getOrCreateCachedPaths(hub, parent) {
|
283
|
+
let parents = pathsCache.get(hub ?? nullHub);
|
284
|
+
if (!parents) pathsCache.set(hub ?? nullHub, parents = new WeakMap());
|
285
|
+
let paths = parents.get(parent);
|
286
|
+
if (!paths) parents.set(parent, paths = new Map());
|
287
|
+
return paths;
|
288
|
+
}
|
278
289
|
|
279
290
|
var cache = /*#__PURE__*/Object.freeze({
|
280
291
|
__proto__: null,
|
281
|
-
get path () { return path; },
|
282
|
-
get scope () { return scope; },
|
283
292
|
clear: clear,
|
284
293
|
clearPath: clearPath,
|
285
|
-
clearScope: clearScope
|
294
|
+
clearScope: clearScope,
|
295
|
+
getCachedPaths: getCachedPaths,
|
296
|
+
getOrCreateCachedPaths: getOrCreateCachedPaths,
|
297
|
+
get path () { return pathsCache; },
|
298
|
+
get scope () { return scope; }
|
286
299
|
});
|
287
300
|
|
288
301
|
const renameVisitor = {
|
@@ -399,9 +412,7 @@ class Binding {
|
|
399
412
|
this.scope = scope;
|
400
413
|
this.path = path;
|
401
414
|
this.kind = kind;
|
402
|
-
if ((kind === "var" || kind === "hoisted") && isDeclaredInLoop(path
|
403
|
-
throw new Error("Internal Babel error: unreachable ");
|
404
|
-
})())) {
|
415
|
+
if ((kind === "var" || kind === "hoisted") && isDeclaredInLoop(path)) {
|
405
416
|
this.reassign(path);
|
406
417
|
}
|
407
418
|
this.clearValue();
|
@@ -496,7 +507,6 @@ const {
|
|
496
507
|
memberExpression: memberExpression$1,
|
497
508
|
numericLiteral: numericLiteral$2,
|
498
509
|
toIdentifier,
|
499
|
-
unaryExpression: unaryExpression$2,
|
500
510
|
variableDeclaration: variableDeclaration$1,
|
501
511
|
variableDeclarator: variableDeclarator$1,
|
502
512
|
isRecordExpression,
|
@@ -505,7 +515,8 @@ const {
|
|
505
515
|
isTopicReference,
|
506
516
|
isMetaProperty,
|
507
517
|
isPrivateName,
|
508
|
-
isExportDeclaration: isExportDeclaration$1
|
518
|
+
isExportDeclaration: isExportDeclaration$1,
|
519
|
+
buildUndefinedNode
|
509
520
|
} = _t;
|
510
521
|
function gatherNodeParts(node, parts) {
|
511
522
|
switch (node?.type) {
|
@@ -955,7 +966,7 @@ class Scope {
|
|
955
966
|
}
|
956
967
|
}
|
957
968
|
buildUndefinedNode() {
|
958
|
-
return
|
969
|
+
return buildUndefinedNode();
|
959
970
|
}
|
960
971
|
registerConstantViolation(path) {
|
961
972
|
const ids = path.getBindingIdentifiers();
|
@@ -1448,16 +1459,16 @@ function inType(...candidateTypes) {
|
|
1448
1459
|
|
1449
1460
|
var NodePath_ancestry = /*#__PURE__*/Object.freeze({
|
1450
1461
|
__proto__: null,
|
1451
|
-
findParent: findParent,
|
1452
1462
|
find: find,
|
1463
|
+
findParent: findParent,
|
1464
|
+
getAncestry: getAncestry,
|
1465
|
+
getDeepestCommonAncestorFrom: getDeepestCommonAncestorFrom,
|
1466
|
+
getEarliestCommonAncestorFrom: getEarliestCommonAncestorFrom,
|
1453
1467
|
getFunctionParent: getFunctionParent,
|
1454
1468
|
getStatementParent: getStatementParent,
|
1455
|
-
|
1456
|
-
getDeepestCommonAncestorFrom: getDeepestCommonAncestorFrom,
|
1457
|
-
getAncestry: getAncestry,
|
1469
|
+
inType: inType,
|
1458
1470
|
isAncestor: isAncestor,
|
1459
|
-
isDescendant: isDescendant
|
1460
|
-
inType: inType
|
1471
|
+
isDescendant: isDescendant
|
1461
1472
|
});
|
1462
1473
|
|
1463
1474
|
const {
|
@@ -1789,36 +1800,36 @@ function resolveCall(callee) {
|
|
1789
1800
|
|
1790
1801
|
var inferers = /*#__PURE__*/Object.freeze({
|
1791
1802
|
__proto__: null,
|
1792
|
-
|
1793
|
-
|
1794
|
-
TSAsExpression: TSAsExpression,
|
1795
|
-
TSNonNullExpression: TSNonNullExpression,
|
1796
|
-
NewExpression: NewExpression,
|
1797
|
-
TemplateLiteral: TemplateLiteral,
|
1798
|
-
UnaryExpression: UnaryExpression,
|
1799
|
-
BinaryExpression: BinaryExpression,
|
1800
|
-
LogicalExpression: LogicalExpression,
|
1801
|
-
ConditionalExpression: ConditionalExpression,
|
1802
|
-
SequenceExpression: SequenceExpression,
|
1803
|
-
ParenthesizedExpression: ParenthesizedExpression,
|
1803
|
+
ArrayExpression: ArrayExpression,
|
1804
|
+
ArrowFunctionExpression: Func,
|
1804
1805
|
AssignmentExpression: AssignmentExpression,
|
1805
|
-
|
1806
|
-
StringLiteral: StringLiteral,
|
1807
|
-
NumericLiteral: NumericLiteral,
|
1806
|
+
BinaryExpression: BinaryExpression,
|
1808
1807
|
BooleanLiteral: BooleanLiteral,
|
1808
|
+
CallExpression: CallExpression,
|
1809
|
+
ClassDeclaration: Func,
|
1810
|
+
ClassExpression: Func,
|
1811
|
+
ConditionalExpression: ConditionalExpression,
|
1812
|
+
FunctionDeclaration: Func,
|
1813
|
+
FunctionExpression: Func,
|
1814
|
+
Identifier: infererReference,
|
1815
|
+
LogicalExpression: LogicalExpression,
|
1816
|
+
NewExpression: NewExpression,
|
1809
1817
|
NullLiteral: NullLiteral,
|
1810
|
-
|
1818
|
+
NumericLiteral: NumericLiteral,
|
1811
1819
|
ObjectExpression: ObjectExpression,
|
1812
|
-
|
1820
|
+
ParenthesizedExpression: ParenthesizedExpression,
|
1821
|
+
RegExpLiteral: RegExpLiteral,
|
1813
1822
|
RestElement: RestElement,
|
1814
|
-
|
1815
|
-
|
1816
|
-
|
1817
|
-
|
1818
|
-
ClassDeclaration: Func,
|
1819
|
-
CallExpression: CallExpression,
|
1823
|
+
SequenceExpression: SequenceExpression,
|
1824
|
+
StringLiteral: StringLiteral,
|
1825
|
+
TSAsExpression: TSAsExpression,
|
1826
|
+
TSNonNullExpression: TSNonNullExpression,
|
1820
1827
|
TaggedTemplateExpression: TaggedTemplateExpression,
|
1821
|
-
|
1828
|
+
TemplateLiteral: TemplateLiteral,
|
1829
|
+
TypeCastExpression: TypeCastExpression,
|
1830
|
+
UnaryExpression: UnaryExpression,
|
1831
|
+
UpdateExpression: UpdateExpression,
|
1832
|
+
VariableDeclarator: VariableDeclarator
|
1822
1833
|
});
|
1823
1834
|
|
1824
1835
|
const {
|
@@ -1957,11 +1968,11 @@ function isGenericType(genericName) {
|
|
1957
1968
|
|
1958
1969
|
var NodePath_inference = /*#__PURE__*/Object.freeze({
|
1959
1970
|
__proto__: null,
|
1960
|
-
getTypeAnnotation: getTypeAnnotation,
|
1961
1971
|
_getTypeAnnotation: _getTypeAnnotation,
|
1962
|
-
isBaseType: isBaseType,
|
1963
|
-
couldBeBaseType: couldBeBaseType,
|
1964
1972
|
baseTypeStrictlyMatches: baseTypeStrictlyMatches,
|
1973
|
+
couldBeBaseType: couldBeBaseType,
|
1974
|
+
getTypeAnnotation: getTypeAnnotation,
|
1975
|
+
isBaseType: isBaseType,
|
1965
1976
|
isGenericType: isGenericType
|
1966
1977
|
});
|
1967
1978
|
|
@@ -1992,7 +2003,7 @@ function replaceWithMultiple(nodes) {
|
|
1992
2003
|
nodes = this._verifyNodeList(nodes);
|
1993
2004
|
inheritLeadingComments(nodes[0], this.node);
|
1994
2005
|
inheritTrailingComments(nodes[nodes.length - 1], this.node);
|
1995
|
-
|
2006
|
+
getCachedPaths(this.hub, this.parent)?.delete(this.node);
|
1996
2007
|
this.node = this.container[this.key] = null;
|
1997
2008
|
const paths = this.insertAfter(nodes);
|
1998
2009
|
if (this.node) {
|
@@ -2079,7 +2090,7 @@ function _replaceWith(node) {
|
|
2079
2090
|
validate$1(this.parent, this.key, node);
|
2080
2091
|
}
|
2081
2092
|
this.debug(`Replace with ${node?.type}`);
|
2082
|
-
|
2093
|
+
getCachedPaths(this.hub, this.parent)?.set(node, this).delete(this.node);
|
2083
2094
|
this.node = this.container[this.key] = node;
|
2084
2095
|
}
|
2085
2096
|
function replaceExpressionWithStatements(nodes) {
|
@@ -2151,18 +2162,22 @@ function replaceInline(nodes) {
|
|
2151
2162
|
|
2152
2163
|
var NodePath_replacement = /*#__PURE__*/Object.freeze({
|
2153
2164
|
__proto__: null,
|
2154
|
-
replaceWithMultiple: replaceWithMultiple,
|
2155
|
-
replaceWithSourceString: replaceWithSourceString,
|
2156
|
-
replaceWith: replaceWith,
|
2157
2165
|
_replaceWith: _replaceWith,
|
2158
2166
|
replaceExpressionWithStatements: replaceExpressionWithStatements,
|
2159
|
-
replaceInline: replaceInline
|
2167
|
+
replaceInline: replaceInline,
|
2168
|
+
replaceWith: replaceWith,
|
2169
|
+
replaceWithMultiple: replaceWithMultiple,
|
2170
|
+
replaceWithSourceString: replaceWithSourceString
|
2160
2171
|
});
|
2161
2172
|
|
2162
|
-
const
|
2173
|
+
const VALID_OBJECT_CALLEES = ["Number", "String", "Math"];
|
2174
|
+
const VALID_IDENTIFIER_CALLEES = ["isFinite", "isNaN", "parseFloat", "parseInt", "decodeURI", "decodeURIComponent", "encodeURI", "encodeURIComponent", "btoa", "atob"];
|
2163
2175
|
const INVALID_METHODS = ["random"];
|
2164
|
-
function
|
2165
|
-
return
|
2176
|
+
function isValidObjectCallee(val) {
|
2177
|
+
return VALID_OBJECT_CALLEES.includes(val);
|
2178
|
+
}
|
2179
|
+
function isValidIdentifierCallee(val) {
|
2180
|
+
return VALID_IDENTIFIER_CALLEES.includes(val);
|
2166
2181
|
}
|
2167
2182
|
function isInvalidMethod(val) {
|
2168
2183
|
return INVALID_METHODS.includes(val);
|
@@ -2437,13 +2452,13 @@ function _evaluate(path, state) {
|
|
2437
2452
|
const callee = path.get("callee");
|
2438
2453
|
let context;
|
2439
2454
|
let func;
|
2440
|
-
if (callee.isIdentifier() && !path.scope.getBinding(callee.node.name) &&
|
2455
|
+
if (callee.isIdentifier() && !path.scope.getBinding(callee.node.name) && (isValidObjectCallee(callee.node.name) || isValidIdentifierCallee(callee.node.name))) {
|
2441
2456
|
func = global[callee.node.name];
|
2442
2457
|
}
|
2443
2458
|
if (callee.isMemberExpression()) {
|
2444
2459
|
const object = callee.get("object");
|
2445
2460
|
const property = callee.get("property");
|
2446
|
-
if (object.isIdentifier() && property.isIdentifier() &&
|
2461
|
+
if (object.isIdentifier() && property.isIdentifier() && isValidObjectCallee(object.node.name) && !isInvalidMethod(property.node.name)) {
|
2447
2462
|
context = global[object.node.name];
|
2448
2463
|
func = context[property.node.name];
|
2449
2464
|
}
|
@@ -2493,8 +2508,8 @@ function evaluate() {
|
|
2493
2508
|
|
2494
2509
|
var NodePath_evaluation = /*#__PURE__*/Object.freeze({
|
2495
2510
|
__proto__: null,
|
2496
|
-
|
2497
|
-
|
2511
|
+
evaluate: evaluate,
|
2512
|
+
evaluateTruthy: evaluateTruthy
|
2498
2513
|
});
|
2499
2514
|
|
2500
2515
|
const {
|
@@ -2946,10 +2961,10 @@ function getScopeInformation(fnPath) {
|
|
2946
2961
|
|
2947
2962
|
var NodePath_conversion = /*#__PURE__*/Object.freeze({
|
2948
2963
|
__proto__: null,
|
2949
|
-
|
2964
|
+
arrowFunctionToExpression: arrowFunctionToExpression,
|
2950
2965
|
ensureBlock: ensureBlock,
|
2951
|
-
|
2952
|
-
|
2966
|
+
toComputedKey: toComputedKey,
|
2967
|
+
unwrapFunctionEnvironment: unwrapFunctionEnvironment
|
2953
2968
|
});
|
2954
2969
|
|
2955
2970
|
const {
|
@@ -3312,25 +3327,25 @@ function isInStrictMode() {
|
|
3312
3327
|
|
3313
3328
|
var NodePath_introspection = /*#__PURE__*/Object.freeze({
|
3314
3329
|
__proto__: null,
|
3315
|
-
|
3316
|
-
|
3317
|
-
isStatic: isStatic,
|
3318
|
-
is: is,
|
3319
|
-
isnt: isnt,
|
3320
|
-
equals: equals,
|
3321
|
-
isNodeType: isNodeType,
|
3330
|
+
_guessExecutionStatusRelativeTo: _guessExecutionStatusRelativeTo,
|
3331
|
+
_resolve: _resolve,
|
3322
3332
|
canHaveVariableDeclarationOrExpression: canHaveVariableDeclarationOrExpression,
|
3323
3333
|
canSwapBetweenExpressionAndStatement: canSwapBetweenExpressionAndStatement,
|
3334
|
+
equals: equals,
|
3335
|
+
getSource: getSource,
|
3336
|
+
has: has,
|
3337
|
+
is: is,
|
3324
3338
|
isCompletionRecord: isCompletionRecord,
|
3339
|
+
isConstantExpression: isConstantExpression,
|
3340
|
+
isInStrictMode: isInStrictMode,
|
3341
|
+
isNodeType: isNodeType,
|
3325
3342
|
isStatementOrBlock: isStatementOrBlock,
|
3343
|
+
isStatic: isStatic,
|
3344
|
+
isnt: isnt,
|
3345
|
+
matchesPattern: matchesPattern,
|
3326
3346
|
referencesImport: referencesImport,
|
3327
|
-
getSource: getSource,
|
3328
|
-
willIMaybeExecuteBefore: willIMaybeExecuteBefore,
|
3329
|
-
_guessExecutionStatusRelativeTo: _guessExecutionStatusRelativeTo,
|
3330
3347
|
resolve: resolve,
|
3331
|
-
|
3332
|
-
isConstantExpression: isConstantExpression,
|
3333
|
-
isInStrictMode: isInStrictMode
|
3348
|
+
willIMaybeExecuteBefore: willIMaybeExecuteBefore
|
3334
3349
|
});
|
3335
3350
|
|
3336
3351
|
function call(key) {
|
@@ -3525,27 +3540,27 @@ function _getQueueContexts() {
|
|
3525
3540
|
|
3526
3541
|
var NodePath_context = /*#__PURE__*/Object.freeze({
|
3527
3542
|
__proto__: null,
|
3528
|
-
call: call,
|
3529
3543
|
_call: _call,
|
3530
|
-
|
3531
|
-
isBlacklisted: isDenylisted,
|
3532
|
-
visit: visit,
|
3533
|
-
skip: skip,
|
3534
|
-
skipKey: skipKey,
|
3535
|
-
stop: stop,
|
3536
|
-
setScope: setScope,
|
3537
|
-
setContext: setContext,
|
3538
|
-
resync: resync,
|
3539
|
-
_resyncParent: _resyncParent,
|
3544
|
+
_getQueueContexts: _getQueueContexts,
|
3540
3545
|
_resyncKey: _resyncKey,
|
3541
3546
|
_resyncList: _resyncList,
|
3547
|
+
_resyncParent: _resyncParent,
|
3542
3548
|
_resyncRemoved: _resyncRemoved,
|
3549
|
+
call: call,
|
3550
|
+
isBlacklisted: isDenylisted,
|
3551
|
+
isDenylisted: isDenylisted,
|
3543
3552
|
popContext: popContext,
|
3544
3553
|
pushContext: pushContext,
|
3545
|
-
setup: setup,
|
3546
|
-
setKey: setKey,
|
3547
3554
|
requeue: requeue,
|
3548
|
-
|
3555
|
+
resync: resync,
|
3556
|
+
setContext: setContext,
|
3557
|
+
setKey: setKey,
|
3558
|
+
setScope: setScope,
|
3559
|
+
setup: setup,
|
3560
|
+
skip: skip,
|
3561
|
+
skipKey: skipKey,
|
3562
|
+
stop: stop,
|
3563
|
+
visit: visit
|
3549
3564
|
});
|
3550
3565
|
|
3551
3566
|
const hooks = [function (self, parent) {
|
@@ -3611,7 +3626,9 @@ function _remove() {
|
|
3611
3626
|
}
|
3612
3627
|
function _markRemoved() {
|
3613
3628
|
this._traverseFlags |= SHOULD_SKIP | REMOVED;
|
3614
|
-
if (this.parent)
|
3629
|
+
if (this.parent) {
|
3630
|
+
getCachedPaths(this.hub, this.parent).delete(this.node);
|
3631
|
+
}
|
3615
3632
|
this.node = null;
|
3616
3633
|
}
|
3617
3634
|
function _assertUnremoved() {
|
@@ -3622,12 +3639,12 @@ function _assertUnremoved() {
|
|
3622
3639
|
|
3623
3640
|
var NodePath_removal = /*#__PURE__*/Object.freeze({
|
3624
3641
|
__proto__: null,
|
3625
|
-
|
3626
|
-
_removeFromScope: _removeFromScope,
|
3642
|
+
_assertUnremoved: _assertUnremoved,
|
3627
3643
|
_callRemovalHooks: _callRemovalHooks,
|
3628
|
-
_remove: _remove,
|
3629
3644
|
_markRemoved: _markRemoved,
|
3630
|
-
|
3645
|
+
_remove: _remove,
|
3646
|
+
_removeFromScope: _removeFromScope,
|
3647
|
+
remove: remove
|
3631
3648
|
});
|
3632
3649
|
|
3633
3650
|
const {
|
@@ -3932,7 +3949,7 @@ function insertAfter(nodes_) {
|
|
3932
3949
|
}
|
3933
3950
|
function updateSiblingKeys(fromIndex, incrementBy) {
|
3934
3951
|
if (!this.parent) return;
|
3935
|
-
const paths =
|
3952
|
+
const paths = getCachedPaths(this.hub, this.parent) || [];
|
3936
3953
|
for (const [, path] of paths) {
|
3937
3954
|
if (typeof path.key === "number" && path.key >= fromIndex) {
|
3938
3955
|
path.key += incrementBy;
|
@@ -3997,16 +4014,16 @@ function hoist(scope = this.scope) {
|
|
3997
4014
|
|
3998
4015
|
var NodePath_modification = /*#__PURE__*/Object.freeze({
|
3999
4016
|
__proto__: null,
|
4000
|
-
insertBefore: insertBefore,
|
4001
4017
|
_containerInsert: _containerInsert,
|
4002
|
-
_containerInsertBefore: _containerInsertBefore,
|
4003
4018
|
_containerInsertAfter: _containerInsertAfter,
|
4004
|
-
|
4005
|
-
updateSiblingKeys: updateSiblingKeys,
|
4019
|
+
_containerInsertBefore: _containerInsertBefore,
|
4006
4020
|
_verifyNodeList: _verifyNodeList,
|
4007
|
-
|
4021
|
+
hoist: hoist,
|
4022
|
+
insertAfter: insertAfter,
|
4023
|
+
insertBefore: insertBefore,
|
4008
4024
|
pushContainer: pushContainer,
|
4009
|
-
|
4025
|
+
unshiftContainer: unshiftContainer,
|
4026
|
+
updateSiblingKeys: updateSiblingKeys
|
4010
4027
|
});
|
4011
4028
|
|
4012
4029
|
const {
|
@@ -4325,20 +4342,20 @@ function getOuterBindingIdentifierPaths(duplicates = false) {
|
|
4325
4342
|
|
4326
4343
|
var NodePath_family = /*#__PURE__*/Object.freeze({
|
4327
4344
|
__proto__: null,
|
4328
|
-
getOpposite: getOpposite,
|
4329
|
-
getCompletionRecords: getCompletionRecords,
|
4330
|
-
getSibling: getSibling,
|
4331
|
-
getPrevSibling: getPrevSibling,
|
4332
|
-
getNextSibling: getNextSibling,
|
4333
|
-
getAllNextSiblings: getAllNextSiblings,
|
4334
|
-
getAllPrevSiblings: getAllPrevSiblings,
|
4335
|
-
get: get,
|
4336
4345
|
_getKey: _getKey,
|
4337
4346
|
_getPattern: _getPattern,
|
4347
|
+
get: get,
|
4348
|
+
getAllNextSiblings: getAllNextSiblings,
|
4349
|
+
getAllPrevSiblings: getAllPrevSiblings,
|
4350
|
+
getBindingIdentifierPaths: getBindingIdentifierPaths,
|
4338
4351
|
getBindingIdentifiers: getBindingIdentifiers,
|
4352
|
+
getCompletionRecords: getCompletionRecords,
|
4353
|
+
getNextSibling: getNextSibling,
|
4354
|
+
getOpposite: getOpposite,
|
4355
|
+
getOuterBindingIdentifierPaths: getOuterBindingIdentifierPaths,
|
4339
4356
|
getOuterBindingIdentifiers: getOuterBindingIdentifiers,
|
4340
|
-
|
4341
|
-
|
4357
|
+
getPrevSibling: getPrevSibling,
|
4358
|
+
getSibling: getSibling
|
4342
4359
|
});
|
4343
4360
|
|
4344
4361
|
const {
|
@@ -4387,9 +4404,9 @@ function addComments(type, comments) {
|
|
4387
4404
|
|
4388
4405
|
var NodePath_comments = /*#__PURE__*/Object.freeze({
|
4389
4406
|
__proto__: null,
|
4390
|
-
shareCommentsWithSiblings: shareCommentsWithSiblings,
|
4391
4407
|
addComment: addComment,
|
4392
|
-
addComments: addComments
|
4408
|
+
addComments: addComments,
|
4409
|
+
shareCommentsWithSiblings: shareCommentsWithSiblings
|
4393
4410
|
});
|
4394
4411
|
|
4395
4412
|
const {
|
@@ -4521,33 +4538,25 @@ function isForAwaitStatement() {
|
|
4521
4538
|
await: true
|
4522
4539
|
});
|
4523
4540
|
}
|
4524
|
-
function isExistentialTypeParam() {
|
4525
|
-
throw new Error("`path.isExistentialTypeParam` has been renamed to `path.isExistsTypeAnnotation()` in Babel 7.");
|
4526
|
-
}
|
4527
|
-
function isNumericLiteralTypeAnnotation() {
|
4528
|
-
throw new Error("`path.isNumericLiteralTypeAnnotation()` has been renamed to `path.isNumberLiteralTypeAnnotation()` in Babel 7.");
|
4529
|
-
}
|
4530
4541
|
|
4531
4542
|
var NodePath_virtual_types_validator = /*#__PURE__*/Object.freeze({
|
4532
4543
|
__proto__: null,
|
4533
|
-
isReferencedIdentifier: isReferencedIdentifier,
|
4534
|
-
isReferencedMemberExpression: isReferencedMemberExpression,
|
4535
4544
|
isBindingIdentifier: isBindingIdentifier,
|
4536
|
-
isStatement: isStatement,
|
4537
|
-
isExpression: isExpression,
|
4538
|
-
isScope: isScope,
|
4539
|
-
isReferenced: isReferenced,
|
4540
4545
|
isBlockScoped: isBlockScoped,
|
4541
|
-
|
4542
|
-
|
4546
|
+
isExpression: isExpression,
|
4547
|
+
isFlow: isFlow,
|
4548
|
+
isForAwaitStatement: isForAwaitStatement,
|
4543
4549
|
isGenerated: isGenerated,
|
4544
4550
|
isPure: isPure,
|
4545
|
-
|
4551
|
+
isReferenced: isReferenced,
|
4552
|
+
isReferencedIdentifier: isReferencedIdentifier,
|
4553
|
+
isReferencedMemberExpression: isReferencedMemberExpression,
|
4546
4554
|
isRestProperty: isRestProperty,
|
4555
|
+
isScope: isScope,
|
4547
4556
|
isSpreadProperty: isSpreadProperty,
|
4548
|
-
|
4549
|
-
|
4550
|
-
|
4557
|
+
isStatement: isStatement,
|
4558
|
+
isUser: isUser,
|
4559
|
+
isVar: isVar
|
4551
4560
|
});
|
4552
4561
|
|
4553
4562
|
const {
|
@@ -4591,18 +4600,14 @@ class NodePath {
|
|
4591
4600
|
throw new Error("To get a node path the parent needs to exist");
|
4592
4601
|
}
|
4593
4602
|
const targetNode = container[key];
|
4594
|
-
|
4595
|
-
|
4596
|
-
|
4597
|
-
path
|
4598
|
-
|
4599
|
-
let path$1 = paths.get(targetNode);
|
4600
|
-
if (!path$1) {
|
4601
|
-
path$1 = new NodePath(hub, parent);
|
4602
|
-
if (targetNode) paths.set(targetNode, path$1);
|
4603
|
+
const paths = getOrCreateCachedPaths(hub, parent);
|
4604
|
+
let path = paths.get(targetNode);
|
4605
|
+
if (!path) {
|
4606
|
+
path = new NodePath(hub, parent);
|
4607
|
+
if (targetNode) paths.set(targetNode, path);
|
4603
4608
|
}
|
4604
|
-
path
|
4605
|
-
return path
|
4609
|
+
path.setup(parentPath, container, listKey, key);
|
4610
|
+
return path;
|
4606
4611
|
}
|
4607
4612
|
getScope(scope) {
|
4608
4613
|
return this.isScope() ? new Scope(this) : scope;
|
@@ -4820,12 +4825,16 @@ class TraversalContext {
|
|
4820
4825
|
const {
|
4821
4826
|
VISITOR_KEYS: VISITOR_KEYS$1
|
4822
4827
|
} = _t;
|
4823
|
-
function traverseNode(node, opts, scope, state, path, skipKeys) {
|
4828
|
+
function traverseNode(node, opts, scope, state, path, skipKeys, visitSelf) {
|
4824
4829
|
const keys = VISITOR_KEYS$1[node.type];
|
4825
4830
|
if (!keys) return false;
|
4826
4831
|
const context = new TraversalContext(scope, opts, state, path);
|
4832
|
+
if (visitSelf) {
|
4833
|
+
if (skipKeys?.[path.parentKey]) return false;
|
4834
|
+
return context.visitQueue([path]);
|
4835
|
+
}
|
4827
4836
|
for (const key of keys) {
|
4828
|
-
if (skipKeys
|
4837
|
+
if (skipKeys?.[key]) continue;
|
4829
4838
|
if (context.visit(node, key)) {
|
4830
4839
|
return true;
|
4831
4840
|
}
|
@@ -4849,18 +4858,21 @@ const {
|
|
4849
4858
|
removeProperties,
|
4850
4859
|
traverseFast
|
4851
4860
|
} = _t;
|
4852
|
-
function traverse(parent, opts = {}, scope, state, parentPath) {
|
4861
|
+
function traverse(parent, opts = {}, scope, state, parentPath, visitSelf) {
|
4853
4862
|
if (!parent) return;
|
4854
4863
|
if (!opts.noScope && !scope) {
|
4855
4864
|
if (parent.type !== "Program" && parent.type !== "File") {
|
4856
4865
|
throw new Error("You must pass a scope and parentPath unless traversing a Program/File. " + `Instead of that you tried to traverse a ${parent.type} node without ` + "passing scope and parentPath.");
|
4857
4866
|
}
|
4858
4867
|
}
|
4868
|
+
if (!parentPath && visitSelf) {
|
4869
|
+
throw new Error("visitSelf can only be used when providing a NodePath.");
|
4870
|
+
}
|
4859
4871
|
if (!VISITOR_KEYS[parent.type]) {
|
4860
4872
|
return;
|
4861
4873
|
}
|
4862
4874
|
explode(opts);
|
4863
|
-
traverseNode(parent, opts, scope, state, parentPath);
|
4875
|
+
traverseNode(parent, opts, scope, state, parentPath, null, visitSelf);
|
4864
4876
|
}
|
4865
4877
|
traverse.visitors = visitors;
|
4866
4878
|
traverse.verify = verify;
|
@@ -4874,7 +4886,6 @@ traverse.node = function (node, opts, scope, state, path, skipKeys) {
|
|
4874
4886
|
};
|
4875
4887
|
traverse.clearNode = function (node, opts) {
|
4876
4888
|
removeProperties(node, opts);
|
4877
|
-
path.delete(node);
|
4878
4889
|
};
|
4879
4890
|
traverse.removeProperties = function (tree, opts) {
|
4880
4891
|
traverseFast(tree, traverse.clearNode, opts);
|