@babel/traverse 8.0.0-alpha.3 → 8.0.0-alpha.5
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 +262 -197
- package/lib/index.js.map +1 -1
- package/package.json +12 -12
package/lib/index.js
CHANGED
@@ -50,6 +50,156 @@ var virtualTypes = /*#__PURE__*/Object.freeze({
|
|
50
50
|
Var: Var
|
51
51
|
});
|
52
52
|
|
53
|
+
const {
|
54
|
+
isBinding,
|
55
|
+
isBlockScoped: nodeIsBlockScoped,
|
56
|
+
isExportDeclaration: isExportDeclaration$1,
|
57
|
+
isExpression: nodeIsExpression,
|
58
|
+
isFlow: nodeIsFlow,
|
59
|
+
isForStatement,
|
60
|
+
isForXStatement,
|
61
|
+
isIdentifier: isIdentifier$6,
|
62
|
+
isImportDeclaration: isImportDeclaration$1,
|
63
|
+
isImportSpecifier,
|
64
|
+
isJSXIdentifier,
|
65
|
+
isJSXMemberExpression,
|
66
|
+
isMemberExpression,
|
67
|
+
isRestElement: nodeIsRestElement,
|
68
|
+
isReferenced: nodeIsReferenced,
|
69
|
+
isScope: nodeIsScope,
|
70
|
+
isStatement: nodeIsStatement,
|
71
|
+
isVar: nodeIsVar,
|
72
|
+
isVariableDeclaration: isVariableDeclaration$2,
|
73
|
+
react: react$1,
|
74
|
+
isForOfStatement
|
75
|
+
} = _t;
|
76
|
+
const {
|
77
|
+
isCompatTag
|
78
|
+
} = react$1;
|
79
|
+
function isReferencedIdentifier(opts) {
|
80
|
+
const {
|
81
|
+
node,
|
82
|
+
parent
|
83
|
+
} = this;
|
84
|
+
if (!isIdentifier$6(node, opts) && !isJSXMemberExpression(parent, opts)) {
|
85
|
+
if (isJSXIdentifier(node, opts)) {
|
86
|
+
if (isCompatTag(node.name)) return false;
|
87
|
+
} else {
|
88
|
+
return false;
|
89
|
+
}
|
90
|
+
}
|
91
|
+
return nodeIsReferenced(node, parent, this.parentPath.parent);
|
92
|
+
}
|
93
|
+
function isReferencedMemberExpression() {
|
94
|
+
const {
|
95
|
+
node,
|
96
|
+
parent
|
97
|
+
} = this;
|
98
|
+
return isMemberExpression(node) && nodeIsReferenced(node, parent);
|
99
|
+
}
|
100
|
+
function isBindingIdentifier() {
|
101
|
+
const {
|
102
|
+
node,
|
103
|
+
parent
|
104
|
+
} = this;
|
105
|
+
const grandparent = this.parentPath.parent;
|
106
|
+
return isIdentifier$6(node) && isBinding(node, parent, grandparent);
|
107
|
+
}
|
108
|
+
function isStatement$1() {
|
109
|
+
const {
|
110
|
+
node,
|
111
|
+
parent
|
112
|
+
} = this;
|
113
|
+
if (nodeIsStatement(node)) {
|
114
|
+
if (isVariableDeclaration$2(node)) {
|
115
|
+
if (isForXStatement(parent, {
|
116
|
+
left: node
|
117
|
+
})) return false;
|
118
|
+
if (isForStatement(parent, {
|
119
|
+
init: node
|
120
|
+
})) return false;
|
121
|
+
}
|
122
|
+
return true;
|
123
|
+
} else {
|
124
|
+
return false;
|
125
|
+
}
|
126
|
+
}
|
127
|
+
function isExpression$3() {
|
128
|
+
if (this.isIdentifier()) {
|
129
|
+
return this.isReferencedIdentifier();
|
130
|
+
} else {
|
131
|
+
return nodeIsExpression(this.node);
|
132
|
+
}
|
133
|
+
}
|
134
|
+
function isScope() {
|
135
|
+
return nodeIsScope(this.node, this.parent);
|
136
|
+
}
|
137
|
+
function isReferenced() {
|
138
|
+
return nodeIsReferenced(this.node, this.parent);
|
139
|
+
}
|
140
|
+
function isBlockScoped() {
|
141
|
+
return nodeIsBlockScoped(this.node);
|
142
|
+
}
|
143
|
+
function isVar() {
|
144
|
+
return nodeIsVar(this.node);
|
145
|
+
}
|
146
|
+
function isUser() {
|
147
|
+
return this.node && !!this.node.loc;
|
148
|
+
}
|
149
|
+
function isGenerated() {
|
150
|
+
return !this.isUser();
|
151
|
+
}
|
152
|
+
function isPure(constantsOnly) {
|
153
|
+
return this.scope.isPure(this.node, constantsOnly);
|
154
|
+
}
|
155
|
+
function isFlow() {
|
156
|
+
const {
|
157
|
+
node
|
158
|
+
} = this;
|
159
|
+
if (nodeIsFlow(node)) {
|
160
|
+
return true;
|
161
|
+
} else if (isImportDeclaration$1(node)) {
|
162
|
+
return node.importKind === "type" || node.importKind === "typeof";
|
163
|
+
} else if (isExportDeclaration$1(node)) {
|
164
|
+
return node.exportKind === "type";
|
165
|
+
} else if (isImportSpecifier(node)) {
|
166
|
+
return node.importKind === "type" || node.importKind === "typeof";
|
167
|
+
} else {
|
168
|
+
return false;
|
169
|
+
}
|
170
|
+
}
|
171
|
+
function isRestProperty() {
|
172
|
+
return nodeIsRestElement(this.node) && this.parentPath && this.parentPath.isObjectPattern();
|
173
|
+
}
|
174
|
+
function isSpreadProperty() {
|
175
|
+
return nodeIsRestElement(this.node) && this.parentPath && this.parentPath.isObjectExpression();
|
176
|
+
}
|
177
|
+
function isForAwaitStatement() {
|
178
|
+
return isForOfStatement(this.node, {
|
179
|
+
await: true
|
180
|
+
});
|
181
|
+
}
|
182
|
+
|
183
|
+
var NodePath_virtual_types_validator = /*#__PURE__*/Object.freeze({
|
184
|
+
__proto__: null,
|
185
|
+
isBindingIdentifier: isBindingIdentifier,
|
186
|
+
isBlockScoped: isBlockScoped,
|
187
|
+
isExpression: isExpression$3,
|
188
|
+
isFlow: isFlow,
|
189
|
+
isForAwaitStatement: isForAwaitStatement,
|
190
|
+
isGenerated: isGenerated,
|
191
|
+
isPure: isPure,
|
192
|
+
isReferenced: isReferenced,
|
193
|
+
isReferencedIdentifier: isReferencedIdentifier,
|
194
|
+
isReferencedMemberExpression: isReferencedMemberExpression,
|
195
|
+
isRestProperty: isRestProperty,
|
196
|
+
isScope: isScope,
|
197
|
+
isSpreadProperty: isSpreadProperty,
|
198
|
+
isStatement: isStatement$1,
|
199
|
+
isUser: isUser,
|
200
|
+
isVar: isVar
|
201
|
+
});
|
202
|
+
|
53
203
|
const {
|
54
204
|
DEPRECATED_KEYS,
|
55
205
|
DEPRECATED_ALIASES,
|
@@ -232,8 +382,10 @@ function ensureCallbackArrays(obj) {
|
|
232
382
|
if (obj.exit && !Array.isArray(obj.exit)) obj.exit = [obj.exit];
|
233
383
|
}
|
234
384
|
function wrapCheck(nodeType, fn) {
|
385
|
+
const fnKey = `is${nodeType}`;
|
386
|
+
const validator = NodePath_virtual_types_validator[fnKey];
|
235
387
|
const newFn = function (path) {
|
236
|
-
if (path
|
388
|
+
if (validator.call(path)) {
|
237
389
|
return fn.apply(this, arguments);
|
238
390
|
}
|
239
391
|
};
|
@@ -476,7 +628,7 @@ const {
|
|
476
628
|
NOT_LOCAL_BINDING,
|
477
629
|
callExpression: callExpression$3,
|
478
630
|
cloneNode: cloneNode$3,
|
479
|
-
getBindingIdentifiers: getBindingIdentifiers$
|
631
|
+
getBindingIdentifiers: getBindingIdentifiers$3,
|
480
632
|
identifier: identifier$3,
|
481
633
|
isArrayExpression,
|
482
634
|
isBinary,
|
@@ -487,8 +639,8 @@ const {
|
|
487
639
|
isExportDefaultDeclaration,
|
488
640
|
isExportNamedDeclaration: isExportNamedDeclaration$1,
|
489
641
|
isFunctionDeclaration,
|
490
|
-
isIdentifier: isIdentifier$
|
491
|
-
isImportDeclaration
|
642
|
+
isIdentifier: isIdentifier$5,
|
643
|
+
isImportDeclaration,
|
492
644
|
isLiteral: isLiteral$1,
|
493
645
|
isMethod,
|
494
646
|
isModuleSpecifier,
|
@@ -515,16 +667,16 @@ const {
|
|
515
667
|
isTopicReference,
|
516
668
|
isMetaProperty,
|
517
669
|
isPrivateName,
|
518
|
-
isExportDeclaration
|
519
|
-
buildUndefinedNode
|
670
|
+
isExportDeclaration,
|
671
|
+
buildUndefinedNode: buildUndefinedNode$1
|
520
672
|
} = _t;
|
521
673
|
function gatherNodeParts(node, parts) {
|
522
674
|
switch (node?.type) {
|
523
675
|
default:
|
524
|
-
if (isImportDeclaration
|
525
|
-
if ((isExportAllDeclaration(node) || isExportNamedDeclaration$1(node) || isImportDeclaration
|
676
|
+
if (isImportDeclaration(node) || isExportDeclaration(node)) {
|
677
|
+
if ((isExportAllDeclaration(node) || isExportNamedDeclaration$1(node) || isImportDeclaration(node)) && node.source) {
|
526
678
|
gatherNodeParts(node.source, parts);
|
527
|
-
} else if ((isExportNamedDeclaration$1(node) || isImportDeclaration
|
679
|
+
} else if ((isExportNamedDeclaration$1(node) || isImportDeclaration(node)) && node.specifiers?.length) {
|
528
680
|
for (const e of node.specifiers) gatherNodeParts(e, parts);
|
529
681
|
} else if ((isExportDefaultDeclaration(node) || isExportNamedDeclaration$1(node)) && node.declaration) {
|
530
682
|
gatherNodeParts(node.declaration, parts);
|
@@ -684,7 +836,7 @@ const collectorVisitor = {
|
|
684
836
|
binding?.reference(path);
|
685
837
|
} else if (isVariableDeclaration$1(declar)) {
|
686
838
|
for (const decl of declar.declarations) {
|
687
|
-
for (const name of Object.keys(getBindingIdentifiers$
|
839
|
+
for (const name of Object.keys(getBindingIdentifiers$3(decl))) {
|
688
840
|
const binding = scope.getBinding(name);
|
689
841
|
binding?.reference(path);
|
690
842
|
}
|
@@ -827,7 +979,7 @@ class Scope {
|
|
827
979
|
if (isThisExpression(node) || isSuper$1(node) || isTopicReference(node)) {
|
828
980
|
return true;
|
829
981
|
}
|
830
|
-
if (isIdentifier$
|
982
|
+
if (isIdentifier$5(node)) {
|
831
983
|
const binding = this.getBinding(node.name);
|
832
984
|
if (binding) {
|
833
985
|
return binding.constant;
|
@@ -894,7 +1046,7 @@ class Scope {
|
|
894
1046
|
console.log(sep);
|
895
1047
|
}
|
896
1048
|
toArray(node, i, arrayLikeIsIterable) {
|
897
|
-
if (isIdentifier$
|
1049
|
+
if (isIdentifier$5(node)) {
|
898
1050
|
const binding = this.getBinding(node.name);
|
899
1051
|
if (binding?.constant && binding.path.isGenericType("Array")) {
|
900
1052
|
return node;
|
@@ -903,7 +1055,7 @@ class Scope {
|
|
903
1055
|
if (isArrayExpression(node)) {
|
904
1056
|
return node;
|
905
1057
|
}
|
906
|
-
if (isIdentifier$
|
1058
|
+
if (isIdentifier$5(node, {
|
907
1059
|
name: "arguments"
|
908
1060
|
})) {
|
909
1061
|
return callExpression$3(memberExpression$1(memberExpression$1(memberExpression$1(identifier$3("Array"), identifier$3("prototype")), identifier$3("slice")), identifier$3("call")), [node]);
|
@@ -966,7 +1118,7 @@ class Scope {
|
|
966
1118
|
}
|
967
1119
|
}
|
968
1120
|
buildUndefinedNode() {
|
969
|
-
return buildUndefinedNode();
|
1121
|
+
return buildUndefinedNode$1();
|
970
1122
|
}
|
971
1123
|
registerConstantViolation(path) {
|
972
1124
|
const ids = path.getBindingIdentifiers();
|
@@ -1027,7 +1179,7 @@ class Scope {
|
|
1027
1179
|
return !!this.getProgramParent().references[name];
|
1028
1180
|
}
|
1029
1181
|
isPure(node, constantsOnly) {
|
1030
|
-
if (isIdentifier$
|
1182
|
+
if (isIdentifier$5(node)) {
|
1031
1183
|
const binding = this.getBinding(node.name);
|
1032
1184
|
if (!binding) return false;
|
1033
1185
|
if (constantsOnly) return binding.constant;
|
@@ -1649,7 +1801,7 @@ const {
|
|
1649
1801
|
tupleTypeAnnotation,
|
1650
1802
|
unionTypeAnnotation,
|
1651
1803
|
voidTypeAnnotation: voidTypeAnnotation$1,
|
1652
|
-
isIdentifier: isIdentifier$
|
1804
|
+
isIdentifier: isIdentifier$4
|
1653
1805
|
} = _t;
|
1654
1806
|
function VariableDeclarator() {
|
1655
1807
|
if (!this.get("id").isIdentifier()) return;
|
@@ -1764,7 +1916,7 @@ function CallExpression() {
|
|
1764
1916
|
} = this.node;
|
1765
1917
|
if (isObjectKeys(callee)) {
|
1766
1918
|
return arrayTypeAnnotation(stringTypeAnnotation$1());
|
1767
|
-
} else if (isArrayFrom(callee) || isObjectValues(callee) || isIdentifier$
|
1919
|
+
} else if (isArrayFrom(callee) || isObjectValues(callee) || isIdentifier$4(callee, {
|
1768
1920
|
name: "Array"
|
1769
1921
|
})) {
|
1770
1922
|
return arrayTypeAnnotation(anyTypeAnnotation$1());
|
@@ -1840,7 +1992,7 @@ const {
|
|
1840
1992
|
isEmptyTypeAnnotation,
|
1841
1993
|
isFlowBaseAnnotation,
|
1842
1994
|
isGenericTypeAnnotation,
|
1843
|
-
isIdentifier: isIdentifier$
|
1995
|
+
isIdentifier: isIdentifier$3,
|
1844
1996
|
isMixedTypeAnnotation,
|
1845
1997
|
isNumberTypeAnnotation,
|
1846
1998
|
isStringTypeAnnotation,
|
@@ -1959,9 +2111,9 @@ function isGenericType(genericName) {
|
|
1959
2111
|
return true;
|
1960
2112
|
}
|
1961
2113
|
}
|
1962
|
-
return isGenericTypeAnnotation(type) && isIdentifier$
|
2114
|
+
return isGenericTypeAnnotation(type) && isIdentifier$3(type.id, {
|
1963
2115
|
name: genericName
|
1964
|
-
}) || isTSTypeReference(type) && isIdentifier$
|
2116
|
+
}) || isTSTypeReference(type) && isIdentifier$3(type.typeName, {
|
1965
2117
|
name: genericName
|
1966
2118
|
});
|
1967
2119
|
}
|
@@ -1982,19 +2134,27 @@ const {
|
|
1982
2134
|
assignmentExpression: assignmentExpression$2,
|
1983
2135
|
awaitExpression,
|
1984
2136
|
blockStatement: blockStatement$2,
|
2137
|
+
buildUndefinedNode,
|
1985
2138
|
callExpression: callExpression$2,
|
1986
2139
|
cloneNode: cloneNode$2,
|
2140
|
+
conditionalExpression: conditionalExpression$1,
|
1987
2141
|
expressionStatement: expressionStatement$2,
|
2142
|
+
getBindingIdentifiers: getBindingIdentifiers$2,
|
1988
2143
|
identifier: identifier$1,
|
1989
2144
|
inheritLeadingComments,
|
1990
2145
|
inheritTrailingComments,
|
1991
2146
|
inheritsComments,
|
1992
|
-
|
2147
|
+
isBlockStatement: isBlockStatement$1,
|
2148
|
+
isEmptyStatement,
|
2149
|
+
isExpression: isExpression$2,
|
2150
|
+
isExpressionStatement,
|
2151
|
+
isIfStatement,
|
1993
2152
|
isProgram,
|
1994
|
-
isStatement
|
2153
|
+
isStatement,
|
2154
|
+
isVariableDeclaration,
|
1995
2155
|
removeComments,
|
1996
2156
|
returnStatement: returnStatement$1,
|
1997
|
-
|
2157
|
+
sequenceExpression: sequenceExpression$1,
|
1998
2158
|
validate: validate$1,
|
1999
2159
|
yieldExpression
|
2000
2160
|
} = _t;
|
@@ -2058,13 +2218,13 @@ function replaceWith(replacementPath) {
|
|
2058
2218
|
throw new Error("Don't use `path.replaceWith()` with a source string, use `path.replaceWithSourceString()`");
|
2059
2219
|
}
|
2060
2220
|
let nodePath = "";
|
2061
|
-
if (this.isNodeType("Statement") && isExpression$
|
2221
|
+
if (this.isNodeType("Statement") && isExpression$2(replacement)) {
|
2062
2222
|
if (!this.canHaveVariableDeclarationOrExpression() && !this.canSwapBetweenExpressionAndStatement(replacement) && !this.parentPath.isExportDefaultDeclaration()) {
|
2063
2223
|
replacement = expressionStatement$2(replacement);
|
2064
2224
|
nodePath = "expression";
|
2065
2225
|
}
|
2066
2226
|
}
|
2067
|
-
if (this.isNodeType("Expression") && isStatement
|
2227
|
+
if (this.isNodeType("Expression") && isStatement(replacement)) {
|
2068
2228
|
if (!this.canHaveVariableDeclarationOrExpression() && !this.canSwapBetweenExpressionAndStatement(replacement)) {
|
2069
2229
|
return this.replaceExpressionWithStatements([replacement]);
|
2070
2230
|
}
|
@@ -2095,9 +2255,13 @@ function _replaceWith(node) {
|
|
2095
2255
|
}
|
2096
2256
|
function replaceExpressionWithStatements(nodes) {
|
2097
2257
|
this.resync();
|
2098
|
-
const
|
2099
|
-
|
2100
|
-
|
2258
|
+
const declars = [];
|
2259
|
+
const nodesAsSingleExpression = gatherSequenceExpressions(nodes, declars);
|
2260
|
+
if (nodesAsSingleExpression) {
|
2261
|
+
for (const id of declars) this.scope.push({
|
2262
|
+
id
|
2263
|
+
});
|
2264
|
+
return this.replaceWith(nodesAsSingleExpression)[0].get("expressions");
|
2101
2265
|
}
|
2102
2266
|
const functionParent = this.getFunctionParent();
|
2103
2267
|
const isParentAsync = functionParent?.is("async");
|
@@ -2144,6 +2308,53 @@ function replaceExpressionWithStatements(nodes) {
|
|
2144
2308
|
}
|
2145
2309
|
return newCallee.get("body.body");
|
2146
2310
|
}
|
2311
|
+
function gatherSequenceExpressions(nodes, declars) {
|
2312
|
+
const exprs = [];
|
2313
|
+
let ensureLastUndefined = true;
|
2314
|
+
for (const node of nodes) {
|
2315
|
+
if (!isEmptyStatement(node)) {
|
2316
|
+
ensureLastUndefined = false;
|
2317
|
+
}
|
2318
|
+
if (isExpression$2(node)) {
|
2319
|
+
exprs.push(node);
|
2320
|
+
} else if (isExpressionStatement(node)) {
|
2321
|
+
exprs.push(node.expression);
|
2322
|
+
} else if (isVariableDeclaration(node)) {
|
2323
|
+
if (node.kind !== "var") return;
|
2324
|
+
for (const declar of node.declarations) {
|
2325
|
+
const bindings = getBindingIdentifiers$2(declar);
|
2326
|
+
for (const key of Object.keys(bindings)) {
|
2327
|
+
declars.push(cloneNode$2(bindings[key]));
|
2328
|
+
}
|
2329
|
+
if (declar.init) {
|
2330
|
+
exprs.push(assignmentExpression$2("=", declar.id, declar.init));
|
2331
|
+
}
|
2332
|
+
}
|
2333
|
+
ensureLastUndefined = true;
|
2334
|
+
} else if (isIfStatement(node)) {
|
2335
|
+
const consequent = node.consequent ? gatherSequenceExpressions([node.consequent], declars) : buildUndefinedNode();
|
2336
|
+
const alternate = node.alternate ? gatherSequenceExpressions([node.alternate], declars) : buildUndefinedNode();
|
2337
|
+
if (!consequent || !alternate) return;
|
2338
|
+
exprs.push(conditionalExpression$1(node.test, consequent, alternate));
|
2339
|
+
} else if (isBlockStatement$1(node)) {
|
2340
|
+
const body = gatherSequenceExpressions(node.body, declars);
|
2341
|
+
if (!body) return;
|
2342
|
+
exprs.push(body);
|
2343
|
+
} else if (isEmptyStatement(node)) {
|
2344
|
+
if (nodes.indexOf(node) === 0) {
|
2345
|
+
ensureLastUndefined = true;
|
2346
|
+
}
|
2347
|
+
} else {
|
2348
|
+
return;
|
2349
|
+
}
|
2350
|
+
}
|
2351
|
+
if (ensureLastUndefined) exprs.push(buildUndefinedNode());
|
2352
|
+
if (exprs.length === 1) {
|
2353
|
+
return exprs[0];
|
2354
|
+
} else {
|
2355
|
+
return sequenceExpression$1(exprs);
|
2356
|
+
}
|
2357
|
+
}
|
2147
2358
|
function replaceInline(nodes) {
|
2148
2359
|
this.resync();
|
2149
2360
|
if (Array.isArray(nodes)) {
|
@@ -2460,7 +2671,10 @@ function _evaluate(path, state) {
|
|
2460
2671
|
const property = callee.get("property");
|
2461
2672
|
if (object.isIdentifier() && property.isIdentifier() && isValidObjectCallee(object.node.name) && !isInvalidMethod(property.node.name)) {
|
2462
2673
|
context = global[object.node.name];
|
2463
|
-
|
2674
|
+
const key = property.node.name;
|
2675
|
+
if (Object.hasOwnProperty.call(context, key)) {
|
2676
|
+
func = context[key];
|
2677
|
+
}
|
2464
2678
|
}
|
2465
2679
|
if (object.isLiteral() && property.isIdentifier()) {
|
2466
2680
|
const type = typeof object.node.value;
|
@@ -2521,7 +2735,7 @@ const {
|
|
2521
2735
|
conditionalExpression,
|
2522
2736
|
expressionStatement: expressionStatement$1,
|
2523
2737
|
identifier,
|
2524
|
-
isIdentifier: isIdentifier$
|
2738
|
+
isIdentifier: isIdentifier$2,
|
2525
2739
|
jsxIdentifier,
|
2526
2740
|
logicalExpression,
|
2527
2741
|
LOGICAL_OPERATORS,
|
@@ -2549,7 +2763,7 @@ function toComputedKey() {
|
|
2549
2763
|
throw new ReferenceError("todo");
|
2550
2764
|
}
|
2551
2765
|
if (!this.node.computed) {
|
2552
|
-
if (isIdentifier$
|
2766
|
+
if (isIdentifier$2(key)) key = stringLiteral(key.name);
|
2553
2767
|
}
|
2554
2768
|
return key;
|
2555
2769
|
}
|
@@ -2971,8 +3185,8 @@ const {
|
|
2971
3185
|
STATEMENT_OR_BLOCK_KEYS,
|
2972
3186
|
VISITOR_KEYS: VISITOR_KEYS$3,
|
2973
3187
|
isBlockStatement,
|
2974
|
-
isExpression: isExpression$
|
2975
|
-
isIdentifier: isIdentifier$
|
3188
|
+
isExpression: isExpression$1,
|
3189
|
+
isIdentifier: isIdentifier$1,
|
2976
3190
|
isLiteral,
|
2977
3191
|
isStringLiteral,
|
2978
3192
|
isType,
|
@@ -3012,7 +3226,7 @@ function canSwapBetweenExpressionAndStatement(replacement) {
|
|
3012
3226
|
if (this.isExpression()) {
|
3013
3227
|
return isBlockStatement(replacement);
|
3014
3228
|
} else if (this.isBlockStatement()) {
|
3015
|
-
return isExpression$
|
3229
|
+
return isExpression$1(replacement);
|
3016
3230
|
}
|
3017
3231
|
return false;
|
3018
3232
|
}
|
@@ -3067,7 +3281,7 @@ function referencesImport(moduleSource, importName) {
|
|
3067
3281
|
if (path.isImportNamespaceSpecifier() && importName === "*") {
|
3068
3282
|
return true;
|
3069
3283
|
}
|
3070
|
-
if (path.isImportSpecifier() && isIdentifier$
|
3284
|
+
if (path.isImportSpecifier() && isIdentifier$1(path.node.imported, {
|
3071
3285
|
name: importName
|
3072
3286
|
})) {
|
3073
3287
|
return true;
|
@@ -3593,6 +3807,9 @@ const hooks = [function (self, parent) {
|
|
3593
3807
|
}
|
3594
3808
|
}];
|
3595
3809
|
|
3810
|
+
const {
|
3811
|
+
getBindingIdentifiers: getBindingIdentifiers$1
|
3812
|
+
} = _t;
|
3596
3813
|
function remove() {
|
3597
3814
|
this._assertUnremoved();
|
3598
3815
|
this.resync();
|
@@ -3608,7 +3825,7 @@ function remove() {
|
|
3608
3825
|
this._markRemoved();
|
3609
3826
|
}
|
3610
3827
|
function _removeFromScope() {
|
3611
|
-
const bindings = this.
|
3828
|
+
const bindings = getBindingIdentifiers$1(this.node, false, false, true);
|
3612
3829
|
Object.keys(bindings).forEach(name => this.scope.removeBinding(name));
|
3613
3830
|
}
|
3614
3831
|
function _callRemovalHooks() {
|
@@ -3648,7 +3865,7 @@ var NodePath_removal = /*#__PURE__*/Object.freeze({
|
|
3648
3865
|
});
|
3649
3866
|
|
3650
3867
|
const {
|
3651
|
-
react
|
3868
|
+
react
|
3652
3869
|
} = _t;
|
3653
3870
|
const {
|
3654
3871
|
cloneNode: cloneNode$1,
|
@@ -3658,7 +3875,7 @@ const {
|
|
3658
3875
|
} = _t;
|
3659
3876
|
const referenceVisitor = {
|
3660
3877
|
ReferencedIdentifier(path, state) {
|
3661
|
-
if (path.isJSXIdentifier() && react
|
3878
|
+
if (path.isJSXIdentifier() && react.isCompatTag(path.node.name) && !path.parentPath.isJSXMemberExpression()) {
|
3662
3879
|
return;
|
3663
3880
|
}
|
3664
3881
|
if (path.node.name === "this") {
|
@@ -3819,8 +4036,8 @@ const {
|
|
3819
4036
|
isAssignmentExpression,
|
3820
4037
|
isCallExpression,
|
3821
4038
|
isExportNamedDeclaration,
|
3822
|
-
isExpression
|
3823
|
-
isIdentifier
|
4039
|
+
isExpression,
|
4040
|
+
isIdentifier,
|
3824
4041
|
isSequenceExpression,
|
3825
4042
|
isSuper,
|
3826
4043
|
thisExpression
|
@@ -3881,7 +4098,7 @@ function isHiddenInSequenceExpression(path) {
|
|
3881
4098
|
return isSequenceExpression(path.parent) && (last(path.parent.expressions) !== path.node || isHiddenInSequenceExpression(path.parentPath));
|
3882
4099
|
}
|
3883
4100
|
function isAlmostConstantAssignment(node, scope) {
|
3884
|
-
if (!isAssignmentExpression(node) || !isIdentifier
|
4101
|
+
if (!isAssignmentExpression(node) || !isIdentifier(node.left)) {
|
3885
4102
|
return false;
|
3886
4103
|
}
|
3887
4104
|
const blockScope = scope.getBlockParent();
|
@@ -3899,7 +4116,7 @@ function insertAfter(nodes_) {
|
|
3899
4116
|
} = this;
|
3900
4117
|
if (parentPath.isExpressionStatement() || parentPath.isLabeledStatement() || isExportNamedDeclaration(parent) || parentPath.isExportDefaultDeclaration() && this.isDeclaration()) {
|
3901
4118
|
return parentPath.insertAfter(nodes.map(node => {
|
3902
|
-
return isExpression
|
4119
|
+
return isExpression(node) ? expressionStatement(node) : node;
|
3903
4120
|
}));
|
3904
4121
|
} else if (this.isNodeType("Expression") && !this.isJSXElement() && !parentPath.isJSXElement() || parentPath.isForStatement() && this.key === "init") {
|
3905
4122
|
if (this.node) {
|
@@ -4387,12 +4604,10 @@ function shareCommentsWithSiblings() {
|
|
4387
4604
|
}
|
4388
4605
|
}
|
4389
4606
|
function removeIfExisting(list, toRemove) {
|
4390
|
-
if (!toRemove) return list;
|
4391
|
-
|
4607
|
+
if (!toRemove?.length) return list;
|
4608
|
+
const set = new Set(toRemove);
|
4392
4609
|
return list.filter(el => {
|
4393
|
-
|
4394
|
-
if (i === -1) return true;
|
4395
|
-
lastFoundIndex = i;
|
4610
|
+
return !set.has(el);
|
4396
4611
|
});
|
4397
4612
|
}
|
4398
4613
|
function addComment(type, content, line) {
|
@@ -4409,156 +4624,6 @@ var NodePath_comments = /*#__PURE__*/Object.freeze({
|
|
4409
4624
|
shareCommentsWithSiblings: shareCommentsWithSiblings
|
4410
4625
|
});
|
4411
4626
|
|
4412
|
-
const {
|
4413
|
-
isBinding,
|
4414
|
-
isBlockScoped: nodeIsBlockScoped,
|
4415
|
-
isExportDeclaration,
|
4416
|
-
isExpression: nodeIsExpression,
|
4417
|
-
isFlow: nodeIsFlow,
|
4418
|
-
isForStatement,
|
4419
|
-
isForXStatement,
|
4420
|
-
isIdentifier,
|
4421
|
-
isImportDeclaration,
|
4422
|
-
isImportSpecifier,
|
4423
|
-
isJSXIdentifier,
|
4424
|
-
isJSXMemberExpression,
|
4425
|
-
isMemberExpression,
|
4426
|
-
isRestElement: nodeIsRestElement,
|
4427
|
-
isReferenced: nodeIsReferenced,
|
4428
|
-
isScope: nodeIsScope,
|
4429
|
-
isStatement: nodeIsStatement,
|
4430
|
-
isVar: nodeIsVar,
|
4431
|
-
isVariableDeclaration,
|
4432
|
-
react,
|
4433
|
-
isForOfStatement
|
4434
|
-
} = _t;
|
4435
|
-
const {
|
4436
|
-
isCompatTag
|
4437
|
-
} = react;
|
4438
|
-
function isReferencedIdentifier(opts) {
|
4439
|
-
const {
|
4440
|
-
node,
|
4441
|
-
parent
|
4442
|
-
} = this;
|
4443
|
-
if (!isIdentifier(node, opts) && !isJSXMemberExpression(parent, opts)) {
|
4444
|
-
if (isJSXIdentifier(node, opts)) {
|
4445
|
-
if (isCompatTag(node.name)) return false;
|
4446
|
-
} else {
|
4447
|
-
return false;
|
4448
|
-
}
|
4449
|
-
}
|
4450
|
-
return nodeIsReferenced(node, parent, this.parentPath.parent);
|
4451
|
-
}
|
4452
|
-
function isReferencedMemberExpression() {
|
4453
|
-
const {
|
4454
|
-
node,
|
4455
|
-
parent
|
4456
|
-
} = this;
|
4457
|
-
return isMemberExpression(node) && nodeIsReferenced(node, parent);
|
4458
|
-
}
|
4459
|
-
function isBindingIdentifier() {
|
4460
|
-
const {
|
4461
|
-
node,
|
4462
|
-
parent
|
4463
|
-
} = this;
|
4464
|
-
const grandparent = this.parentPath.parent;
|
4465
|
-
return isIdentifier(node) && isBinding(node, parent, grandparent);
|
4466
|
-
}
|
4467
|
-
function isStatement() {
|
4468
|
-
const {
|
4469
|
-
node,
|
4470
|
-
parent
|
4471
|
-
} = this;
|
4472
|
-
if (nodeIsStatement(node)) {
|
4473
|
-
if (isVariableDeclaration(node)) {
|
4474
|
-
if (isForXStatement(parent, {
|
4475
|
-
left: node
|
4476
|
-
})) return false;
|
4477
|
-
if (isForStatement(parent, {
|
4478
|
-
init: node
|
4479
|
-
})) return false;
|
4480
|
-
}
|
4481
|
-
return true;
|
4482
|
-
} else {
|
4483
|
-
return false;
|
4484
|
-
}
|
4485
|
-
}
|
4486
|
-
function isExpression() {
|
4487
|
-
if (this.isIdentifier()) {
|
4488
|
-
return this.isReferencedIdentifier();
|
4489
|
-
} else {
|
4490
|
-
return nodeIsExpression(this.node);
|
4491
|
-
}
|
4492
|
-
}
|
4493
|
-
function isScope() {
|
4494
|
-
return nodeIsScope(this.node, this.parent);
|
4495
|
-
}
|
4496
|
-
function isReferenced() {
|
4497
|
-
return nodeIsReferenced(this.node, this.parent);
|
4498
|
-
}
|
4499
|
-
function isBlockScoped() {
|
4500
|
-
return nodeIsBlockScoped(this.node);
|
4501
|
-
}
|
4502
|
-
function isVar() {
|
4503
|
-
return nodeIsVar(this.node);
|
4504
|
-
}
|
4505
|
-
function isUser() {
|
4506
|
-
return this.node && !!this.node.loc;
|
4507
|
-
}
|
4508
|
-
function isGenerated() {
|
4509
|
-
return !this.isUser();
|
4510
|
-
}
|
4511
|
-
function isPure(constantsOnly) {
|
4512
|
-
return this.scope.isPure(this.node, constantsOnly);
|
4513
|
-
}
|
4514
|
-
function isFlow() {
|
4515
|
-
const {
|
4516
|
-
node
|
4517
|
-
} = this;
|
4518
|
-
if (nodeIsFlow(node)) {
|
4519
|
-
return true;
|
4520
|
-
} else if (isImportDeclaration(node)) {
|
4521
|
-
return node.importKind === "type" || node.importKind === "typeof";
|
4522
|
-
} else if (isExportDeclaration(node)) {
|
4523
|
-
return node.exportKind === "type";
|
4524
|
-
} else if (isImportSpecifier(node)) {
|
4525
|
-
return node.importKind === "type" || node.importKind === "typeof";
|
4526
|
-
} else {
|
4527
|
-
return false;
|
4528
|
-
}
|
4529
|
-
}
|
4530
|
-
function isRestProperty() {
|
4531
|
-
return nodeIsRestElement(this.node) && this.parentPath && this.parentPath.isObjectPattern();
|
4532
|
-
}
|
4533
|
-
function isSpreadProperty() {
|
4534
|
-
return nodeIsRestElement(this.node) && this.parentPath && this.parentPath.isObjectExpression();
|
4535
|
-
}
|
4536
|
-
function isForAwaitStatement() {
|
4537
|
-
return isForOfStatement(this.node, {
|
4538
|
-
await: true
|
4539
|
-
});
|
4540
|
-
}
|
4541
|
-
|
4542
|
-
var NodePath_virtual_types_validator = /*#__PURE__*/Object.freeze({
|
4543
|
-
__proto__: null,
|
4544
|
-
isBindingIdentifier: isBindingIdentifier,
|
4545
|
-
isBlockScoped: isBlockScoped,
|
4546
|
-
isExpression: isExpression,
|
4547
|
-
isFlow: isFlow,
|
4548
|
-
isForAwaitStatement: isForAwaitStatement,
|
4549
|
-
isGenerated: isGenerated,
|
4550
|
-
isPure: isPure,
|
4551
|
-
isReferenced: isReferenced,
|
4552
|
-
isReferencedIdentifier: isReferencedIdentifier,
|
4553
|
-
isReferencedMemberExpression: isReferencedMemberExpression,
|
4554
|
-
isRestProperty: isRestProperty,
|
4555
|
-
isScope: isScope,
|
4556
|
-
isSpreadProperty: isSpreadProperty,
|
4557
|
-
isStatement: isStatement,
|
4558
|
-
isUser: isUser,
|
4559
|
-
isVar: isVar
|
4560
|
-
});
|
4561
|
-
|
4562
4627
|
const {
|
4563
4628
|
validate
|
4564
4629
|
} = _t;
|