@babel/traverse 8.0.0-alpha.4 → 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.
Files changed (3) hide show
  1. package/lib/index.js +258 -196
  2. package/lib/index.js.map +1 -1
  3. 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[`is${nodeType}`]()) {
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$1,
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$6,
491
- isImportDeclaration: isImportDeclaration$1,
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: isExportDeclaration$1,
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$1(node) || isExportDeclaration$1(node)) {
525
- if ((isExportAllDeclaration(node) || isExportNamedDeclaration$1(node) || isImportDeclaration$1(node)) && node.source) {
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$1(node)) && node.specifiers?.length) {
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$1(decl))) {
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$6(node)) {
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$6(node)) {
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$6(node, {
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$6(node)) {
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$5
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$5(callee, {
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$4,
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$4(type.id, {
2114
+ return isGenericTypeAnnotation(type) && isIdentifier$3(type.id, {
1963
2115
  name: genericName
1964
- }) || isTSTypeReference(type) && isIdentifier$4(type.typeName, {
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
- isExpression: isExpression$3,
2147
+ isBlockStatement: isBlockStatement$1,
2148
+ isEmptyStatement,
2149
+ isExpression: isExpression$2,
2150
+ isExpressionStatement,
2151
+ isIfStatement,
1993
2152
  isProgram,
1994
- isStatement: isStatement$1,
2153
+ isStatement,
2154
+ isVariableDeclaration,
1995
2155
  removeComments,
1996
2156
  returnStatement: returnStatement$1,
1997
- toSequenceExpression,
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$3(replacement)) {
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$1(replacement)) {
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 nodesAsSequenceExpression = toSequenceExpression(nodes, this.scope);
2099
- if (nodesAsSequenceExpression) {
2100
- return this.replaceWith(nodesAsSequenceExpression)[0].get("expressions");
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)) {
@@ -2524,7 +2735,7 @@ const {
2524
2735
  conditionalExpression,
2525
2736
  expressionStatement: expressionStatement$1,
2526
2737
  identifier,
2527
- isIdentifier: isIdentifier$3,
2738
+ isIdentifier: isIdentifier$2,
2528
2739
  jsxIdentifier,
2529
2740
  logicalExpression,
2530
2741
  LOGICAL_OPERATORS,
@@ -2552,7 +2763,7 @@ function toComputedKey() {
2552
2763
  throw new ReferenceError("todo");
2553
2764
  }
2554
2765
  if (!this.node.computed) {
2555
- if (isIdentifier$3(key)) key = stringLiteral(key.name);
2766
+ if (isIdentifier$2(key)) key = stringLiteral(key.name);
2556
2767
  }
2557
2768
  return key;
2558
2769
  }
@@ -2974,8 +3185,8 @@ const {
2974
3185
  STATEMENT_OR_BLOCK_KEYS,
2975
3186
  VISITOR_KEYS: VISITOR_KEYS$3,
2976
3187
  isBlockStatement,
2977
- isExpression: isExpression$2,
2978
- isIdentifier: isIdentifier$2,
3188
+ isExpression: isExpression$1,
3189
+ isIdentifier: isIdentifier$1,
2979
3190
  isLiteral,
2980
3191
  isStringLiteral,
2981
3192
  isType,
@@ -3015,7 +3226,7 @@ function canSwapBetweenExpressionAndStatement(replacement) {
3015
3226
  if (this.isExpression()) {
3016
3227
  return isBlockStatement(replacement);
3017
3228
  } else if (this.isBlockStatement()) {
3018
- return isExpression$2(replacement);
3229
+ return isExpression$1(replacement);
3019
3230
  }
3020
3231
  return false;
3021
3232
  }
@@ -3070,7 +3281,7 @@ function referencesImport(moduleSource, importName) {
3070
3281
  if (path.isImportNamespaceSpecifier() && importName === "*") {
3071
3282
  return true;
3072
3283
  }
3073
- if (path.isImportSpecifier() && isIdentifier$2(path.node.imported, {
3284
+ if (path.isImportSpecifier() && isIdentifier$1(path.node.imported, {
3074
3285
  name: importName
3075
3286
  })) {
3076
3287
  return true;
@@ -3596,6 +3807,9 @@ const hooks = [function (self, parent) {
3596
3807
  }
3597
3808
  }];
3598
3809
 
3810
+ const {
3811
+ getBindingIdentifiers: getBindingIdentifiers$1
3812
+ } = _t;
3599
3813
  function remove() {
3600
3814
  this._assertUnremoved();
3601
3815
  this.resync();
@@ -3611,7 +3825,7 @@ function remove() {
3611
3825
  this._markRemoved();
3612
3826
  }
3613
3827
  function _removeFromScope() {
3614
- const bindings = this.getBindingIdentifiers();
3828
+ const bindings = getBindingIdentifiers$1(this.node, false, false, true);
3615
3829
  Object.keys(bindings).forEach(name => this.scope.removeBinding(name));
3616
3830
  }
3617
3831
  function _callRemovalHooks() {
@@ -3651,7 +3865,7 @@ var NodePath_removal = /*#__PURE__*/Object.freeze({
3651
3865
  });
3652
3866
 
3653
3867
  const {
3654
- react: react$1
3868
+ react
3655
3869
  } = _t;
3656
3870
  const {
3657
3871
  cloneNode: cloneNode$1,
@@ -3661,7 +3875,7 @@ const {
3661
3875
  } = _t;
3662
3876
  const referenceVisitor = {
3663
3877
  ReferencedIdentifier(path, state) {
3664
- if (path.isJSXIdentifier() && react$1.isCompatTag(path.node.name) && !path.parentPath.isJSXMemberExpression()) {
3878
+ if (path.isJSXIdentifier() && react.isCompatTag(path.node.name) && !path.parentPath.isJSXMemberExpression()) {
3665
3879
  return;
3666
3880
  }
3667
3881
  if (path.node.name === "this") {
@@ -3822,8 +4036,8 @@ const {
3822
4036
  isAssignmentExpression,
3823
4037
  isCallExpression,
3824
4038
  isExportNamedDeclaration,
3825
- isExpression: isExpression$1,
3826
- isIdentifier: isIdentifier$1,
4039
+ isExpression,
4040
+ isIdentifier,
3827
4041
  isSequenceExpression,
3828
4042
  isSuper,
3829
4043
  thisExpression
@@ -3884,7 +4098,7 @@ function isHiddenInSequenceExpression(path) {
3884
4098
  return isSequenceExpression(path.parent) && (last(path.parent.expressions) !== path.node || isHiddenInSequenceExpression(path.parentPath));
3885
4099
  }
3886
4100
  function isAlmostConstantAssignment(node, scope) {
3887
- if (!isAssignmentExpression(node) || !isIdentifier$1(node.left)) {
4101
+ if (!isAssignmentExpression(node) || !isIdentifier(node.left)) {
3888
4102
  return false;
3889
4103
  }
3890
4104
  const blockScope = scope.getBlockParent();
@@ -3902,7 +4116,7 @@ function insertAfter(nodes_) {
3902
4116
  } = this;
3903
4117
  if (parentPath.isExpressionStatement() || parentPath.isLabeledStatement() || isExportNamedDeclaration(parent) || parentPath.isExportDefaultDeclaration() && this.isDeclaration()) {
3904
4118
  return parentPath.insertAfter(nodes.map(node => {
3905
- return isExpression$1(node) ? expressionStatement(node) : node;
4119
+ return isExpression(node) ? expressionStatement(node) : node;
3906
4120
  }));
3907
4121
  } else if (this.isNodeType("Expression") && !this.isJSXElement() && !parentPath.isJSXElement() || parentPath.isForStatement() && this.key === "init") {
3908
4122
  if (this.node) {
@@ -4390,12 +4604,10 @@ function shareCommentsWithSiblings() {
4390
4604
  }
4391
4605
  }
4392
4606
  function removeIfExisting(list, toRemove) {
4393
- if (!toRemove) return list;
4394
- let lastFoundIndex = -1;
4607
+ if (!toRemove?.length) return list;
4608
+ const set = new Set(toRemove);
4395
4609
  return list.filter(el => {
4396
- const i = toRemove.indexOf(el, lastFoundIndex);
4397
- if (i === -1) return true;
4398
- lastFoundIndex = i;
4610
+ return !set.has(el);
4399
4611
  });
4400
4612
  }
4401
4613
  function addComment(type, content, line) {
@@ -4412,156 +4624,6 @@ var NodePath_comments = /*#__PURE__*/Object.freeze({
4412
4624
  shareCommentsWithSiblings: shareCommentsWithSiblings
4413
4625
  });
4414
4626
 
4415
- const {
4416
- isBinding,
4417
- isBlockScoped: nodeIsBlockScoped,
4418
- isExportDeclaration,
4419
- isExpression: nodeIsExpression,
4420
- isFlow: nodeIsFlow,
4421
- isForStatement,
4422
- isForXStatement,
4423
- isIdentifier,
4424
- isImportDeclaration,
4425
- isImportSpecifier,
4426
- isJSXIdentifier,
4427
- isJSXMemberExpression,
4428
- isMemberExpression,
4429
- isRestElement: nodeIsRestElement,
4430
- isReferenced: nodeIsReferenced,
4431
- isScope: nodeIsScope,
4432
- isStatement: nodeIsStatement,
4433
- isVar: nodeIsVar,
4434
- isVariableDeclaration,
4435
- react,
4436
- isForOfStatement
4437
- } = _t;
4438
- const {
4439
- isCompatTag
4440
- } = react;
4441
- function isReferencedIdentifier(opts) {
4442
- const {
4443
- node,
4444
- parent
4445
- } = this;
4446
- if (!isIdentifier(node, opts) && !isJSXMemberExpression(parent, opts)) {
4447
- if (isJSXIdentifier(node, opts)) {
4448
- if (isCompatTag(node.name)) return false;
4449
- } else {
4450
- return false;
4451
- }
4452
- }
4453
- return nodeIsReferenced(node, parent, this.parentPath.parent);
4454
- }
4455
- function isReferencedMemberExpression() {
4456
- const {
4457
- node,
4458
- parent
4459
- } = this;
4460
- return isMemberExpression(node) && nodeIsReferenced(node, parent);
4461
- }
4462
- function isBindingIdentifier() {
4463
- const {
4464
- node,
4465
- parent
4466
- } = this;
4467
- const grandparent = this.parentPath.parent;
4468
- return isIdentifier(node) && isBinding(node, parent, grandparent);
4469
- }
4470
- function isStatement() {
4471
- const {
4472
- node,
4473
- parent
4474
- } = this;
4475
- if (nodeIsStatement(node)) {
4476
- if (isVariableDeclaration(node)) {
4477
- if (isForXStatement(parent, {
4478
- left: node
4479
- })) return false;
4480
- if (isForStatement(parent, {
4481
- init: node
4482
- })) return false;
4483
- }
4484
- return true;
4485
- } else {
4486
- return false;
4487
- }
4488
- }
4489
- function isExpression() {
4490
- if (this.isIdentifier()) {
4491
- return this.isReferencedIdentifier();
4492
- } else {
4493
- return nodeIsExpression(this.node);
4494
- }
4495
- }
4496
- function isScope() {
4497
- return nodeIsScope(this.node, this.parent);
4498
- }
4499
- function isReferenced() {
4500
- return nodeIsReferenced(this.node, this.parent);
4501
- }
4502
- function isBlockScoped() {
4503
- return nodeIsBlockScoped(this.node);
4504
- }
4505
- function isVar() {
4506
- return nodeIsVar(this.node);
4507
- }
4508
- function isUser() {
4509
- return this.node && !!this.node.loc;
4510
- }
4511
- function isGenerated() {
4512
- return !this.isUser();
4513
- }
4514
- function isPure(constantsOnly) {
4515
- return this.scope.isPure(this.node, constantsOnly);
4516
- }
4517
- function isFlow() {
4518
- const {
4519
- node
4520
- } = this;
4521
- if (nodeIsFlow(node)) {
4522
- return true;
4523
- } else if (isImportDeclaration(node)) {
4524
- return node.importKind === "type" || node.importKind === "typeof";
4525
- } else if (isExportDeclaration(node)) {
4526
- return node.exportKind === "type";
4527
- } else if (isImportSpecifier(node)) {
4528
- return node.importKind === "type" || node.importKind === "typeof";
4529
- } else {
4530
- return false;
4531
- }
4532
- }
4533
- function isRestProperty() {
4534
- return nodeIsRestElement(this.node) && this.parentPath && this.parentPath.isObjectPattern();
4535
- }
4536
- function isSpreadProperty() {
4537
- return nodeIsRestElement(this.node) && this.parentPath && this.parentPath.isObjectExpression();
4538
- }
4539
- function isForAwaitStatement() {
4540
- return isForOfStatement(this.node, {
4541
- await: true
4542
- });
4543
- }
4544
-
4545
- var NodePath_virtual_types_validator = /*#__PURE__*/Object.freeze({
4546
- __proto__: null,
4547
- isBindingIdentifier: isBindingIdentifier,
4548
- isBlockScoped: isBlockScoped,
4549
- isExpression: isExpression,
4550
- isFlow: isFlow,
4551
- isForAwaitStatement: isForAwaitStatement,
4552
- isGenerated: isGenerated,
4553
- isPure: isPure,
4554
- isReferenced: isReferenced,
4555
- isReferencedIdentifier: isReferencedIdentifier,
4556
- isReferencedMemberExpression: isReferencedMemberExpression,
4557
- isRestProperty: isRestProperty,
4558
- isScope: isScope,
4559
- isSpreadProperty: isSpreadProperty,
4560
- isStatement: isStatement,
4561
- isUser: isUser,
4562
- isVar: isVar
4563
- });
4564
-
4565
4627
  const {
4566
4628
  validate
4567
4629
  } = _t;