@eslint-react/ast 2.0.0-next.0 → 2.0.0-next.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,23 +1,21 @@
1
- 'use strict';
2
-
3
- var types = require('@typescript-eslint/types');
4
- var eff = require('@eslint-react/eff');
5
- var utils = require('@typescript-eslint/utils');
6
- var typescriptEstree = require('@typescript-eslint/typescript-estree');
7
- var stringTs = require('string-ts');
1
+ import { AST_NODE_TYPES } from '@typescript-eslint/types';
2
+ import { or, dual, _ } from '@eslint-react/eff';
3
+ import { ASTUtils } from '@typescript-eslint/utils';
4
+ import { simpleTraverse } from '@typescript-eslint/typescript-estree';
5
+ import { toLowerCase, delimiterCase, replace } from 'string-ts';
8
6
 
9
7
  // src/ast-array-method.ts
10
8
  function isArrayFromCall(node, loose = true) {
11
- if (node.type !== types.AST_NODE_TYPES.CallExpression) return false;
12
- if (node.callee.type !== types.AST_NODE_TYPES.MemberExpression) return false;
13
- if (node.callee.property.type !== types.AST_NODE_TYPES.Identifier) return false;
9
+ if (node.type !== AST_NODE_TYPES.CallExpression) return false;
10
+ if (node.callee.type !== AST_NODE_TYPES.MemberExpression) return false;
11
+ if (node.callee.property.type !== AST_NODE_TYPES.Identifier) return false;
14
12
  const name = node.callee.property.name;
15
13
  return name === "from" || loose && name.startsWith("from");
16
14
  }
17
15
  function isArrayMapCall(node, loose = true) {
18
- if (node.type !== types.AST_NODE_TYPES.CallExpression) return false;
19
- if (node.callee.type !== types.AST_NODE_TYPES.MemberExpression) return false;
20
- if (node.callee.property.type !== types.AST_NODE_TYPES.Identifier) return false;
16
+ if (node.type !== AST_NODE_TYPES.CallExpression) return false;
17
+ if (node.callee.type !== AST_NODE_TYPES.MemberExpression) return false;
18
+ if (node.callee.property.type !== AST_NODE_TYPES.Identifier) return false;
21
19
  const name = node.callee.property.name;
22
20
  return name === "map" || loose && name.endsWith("Map");
23
21
  }
@@ -40,155 +38,162 @@ var indexParamPosition = /* @__PURE__ */ new Map([
40
38
  function getArrayMethodCallbackIndexParamPosition(methodName) {
41
39
  return indexParamPosition.get(methodName) ?? -1;
42
40
  }
41
+ function getArrayPatternElementNameAt(node, at) {
42
+ const { parent } = node;
43
+ if (!("id" in parent) || parent.id?.type !== AST_NODE_TYPES.ArrayPattern) return true;
44
+ const element = parent.id.elements[at];
45
+ if (element?.type !== AST_NODE_TYPES.Identifier) return _;
46
+ return element.name;
47
+ }
43
48
  function getClassId(node) {
44
49
  if (node.id != null) return node.id;
45
- if (node.parent.type === types.AST_NODE_TYPES.VariableDeclarator && node.parent.id.type === types.AST_NODE_TYPES.Identifier) {
50
+ if (node.parent.type === AST_NODE_TYPES.VariableDeclarator && node.parent.id.type === AST_NODE_TYPES.Identifier) {
46
51
  return node.parent.id;
47
52
  }
48
- return eff._;
53
+ return _;
49
54
  }
50
- var is = utils.ASTUtils.isNodeOfType;
51
- var isOneOf = utils.ASTUtils.isNodeOfTypes;
55
+ var is = ASTUtils.isNodeOfType;
56
+ var isOneOf = ASTUtils.isNodeOfTypes;
52
57
  var isFunction = isOneOf([
53
- types.AST_NODE_TYPES.ArrowFunctionExpression,
54
- types.AST_NODE_TYPES.FunctionDeclaration,
55
- types.AST_NODE_TYPES.FunctionExpression
58
+ AST_NODE_TYPES.ArrowFunctionExpression,
59
+ AST_NODE_TYPES.FunctionDeclaration,
60
+ AST_NODE_TYPES.FunctionExpression
56
61
  ]);
57
62
  var isFunctionType = isOneOf([
58
- types.AST_NODE_TYPES.ArrowFunctionExpression,
59
- types.AST_NODE_TYPES.FunctionDeclaration,
60
- types.AST_NODE_TYPES.FunctionExpression,
61
- types.AST_NODE_TYPES.TSCallSignatureDeclaration,
62
- types.AST_NODE_TYPES.TSConstructSignatureDeclaration,
63
- types.AST_NODE_TYPES.TSDeclareFunction,
64
- types.AST_NODE_TYPES.TSEmptyBodyFunctionExpression,
65
- types.AST_NODE_TYPES.TSFunctionType,
66
- types.AST_NODE_TYPES.TSMethodSignature
63
+ AST_NODE_TYPES.ArrowFunctionExpression,
64
+ AST_NODE_TYPES.FunctionDeclaration,
65
+ AST_NODE_TYPES.FunctionExpression,
66
+ AST_NODE_TYPES.TSCallSignatureDeclaration,
67
+ AST_NODE_TYPES.TSConstructSignatureDeclaration,
68
+ AST_NODE_TYPES.TSDeclareFunction,
69
+ AST_NODE_TYPES.TSEmptyBodyFunctionExpression,
70
+ AST_NODE_TYPES.TSFunctionType,
71
+ AST_NODE_TYPES.TSMethodSignature
67
72
  ]);
68
- var isClass = isOneOf([types.AST_NODE_TYPES.ClassDeclaration, types.AST_NODE_TYPES.ClassExpression]);
73
+ var isClass = isOneOf([AST_NODE_TYPES.ClassDeclaration, AST_NODE_TYPES.ClassExpression]);
69
74
  var isMethodOrProperty = isOneOf([
70
- types.AST_NODE_TYPES.PropertyDefinition,
71
- types.AST_NODE_TYPES.MethodDefinition
75
+ AST_NODE_TYPES.PropertyDefinition,
76
+ AST_NODE_TYPES.MethodDefinition
72
77
  ]);
73
78
  var isLoop = isOneOf([
74
- types.AST_NODE_TYPES.DoWhileStatement,
75
- types.AST_NODE_TYPES.ForInStatement,
76
- types.AST_NODE_TYPES.ForOfStatement,
77
- types.AST_NODE_TYPES.ForStatement,
78
- types.AST_NODE_TYPES.WhileStatement
79
+ AST_NODE_TYPES.DoWhileStatement,
80
+ AST_NODE_TYPES.ForInStatement,
81
+ AST_NODE_TYPES.ForOfStatement,
82
+ AST_NODE_TYPES.ForStatement,
83
+ AST_NODE_TYPES.WhileStatement
79
84
  ]);
80
- var isControlFlow = eff.or(
85
+ var isControlFlow = or(
81
86
  isLoop,
82
87
  isOneOf([
83
- types.AST_NODE_TYPES.IfStatement,
84
- types.AST_NODE_TYPES.SwitchStatement
88
+ AST_NODE_TYPES.IfStatement,
89
+ AST_NODE_TYPES.SwitchStatement
85
90
  ])
86
91
  );
87
- var isConditional = eff.or(
92
+ var isConditional = or(
88
93
  isControlFlow,
89
94
  isOneOf([
90
- types.AST_NODE_TYPES.LogicalExpression,
91
- types.AST_NODE_TYPES.ConditionalExpression
95
+ AST_NODE_TYPES.LogicalExpression,
96
+ AST_NODE_TYPES.ConditionalExpression
92
97
  ])
93
98
  );
94
- var isArrayTupleType = isOneOf([types.AST_NODE_TYPES.TSArrayType, types.AST_NODE_TYPES.TSTupleType]);
99
+ var isArrayTupleType = isOneOf([AST_NODE_TYPES.TSArrayType, AST_NODE_TYPES.TSTupleType]);
95
100
  var isProperty = isOneOf([
96
- types.AST_NODE_TYPES.PropertyDefinition,
97
- types.AST_NODE_TYPES.TSIndexSignature,
98
- types.AST_NODE_TYPES.TSParameterProperty,
99
- types.AST_NODE_TYPES.TSPropertySignature
101
+ AST_NODE_TYPES.PropertyDefinition,
102
+ AST_NODE_TYPES.TSIndexSignature,
103
+ AST_NODE_TYPES.TSParameterProperty,
104
+ AST_NODE_TYPES.TSPropertySignature
100
105
  ]);
101
- var isJSXElement = is(types.AST_NODE_TYPES.JSXElement);
102
- var isJSXFragment = is(types.AST_NODE_TYPES.JSXFragment);
106
+ var isJSXElement = is(AST_NODE_TYPES.JSXElement);
107
+ var isJSXFragment = is(AST_NODE_TYPES.JSXFragment);
103
108
  var isJSXTagNameExpression = isOneOf([
104
- types.AST_NODE_TYPES.JSXIdentifier,
105
- types.AST_NODE_TYPES.JSXMemberExpression,
106
- types.AST_NODE_TYPES.JSXNamespacedName
109
+ AST_NODE_TYPES.JSXIdentifier,
110
+ AST_NODE_TYPES.JSXMemberExpression,
111
+ AST_NODE_TYPES.JSXNamespacedName
107
112
  ]);
108
113
  var isJSX = isOneOf([
109
- types.AST_NODE_TYPES.JSXAttribute,
110
- types.AST_NODE_TYPES.JSXClosingElement,
111
- types.AST_NODE_TYPES.JSXClosingFragment,
112
- types.AST_NODE_TYPES.JSXElement,
113
- types.AST_NODE_TYPES.JSXEmptyExpression,
114
- types.AST_NODE_TYPES.JSXExpressionContainer,
115
- types.AST_NODE_TYPES.JSXFragment,
116
- types.AST_NODE_TYPES.JSXIdentifier,
117
- types.AST_NODE_TYPES.JSXMemberExpression,
118
- types.AST_NODE_TYPES.JSXNamespacedName,
119
- types.AST_NODE_TYPES.JSXOpeningElement,
120
- types.AST_NODE_TYPES.JSXOpeningFragment,
121
- types.AST_NODE_TYPES.JSXSpreadAttribute,
122
- types.AST_NODE_TYPES.JSXSpreadChild,
123
- types.AST_NODE_TYPES.JSXText
114
+ AST_NODE_TYPES.JSXAttribute,
115
+ AST_NODE_TYPES.JSXClosingElement,
116
+ AST_NODE_TYPES.JSXClosingFragment,
117
+ AST_NODE_TYPES.JSXElement,
118
+ AST_NODE_TYPES.JSXEmptyExpression,
119
+ AST_NODE_TYPES.JSXExpressionContainer,
120
+ AST_NODE_TYPES.JSXFragment,
121
+ AST_NODE_TYPES.JSXIdentifier,
122
+ AST_NODE_TYPES.JSXMemberExpression,
123
+ AST_NODE_TYPES.JSXNamespacedName,
124
+ AST_NODE_TYPES.JSXOpeningElement,
125
+ AST_NODE_TYPES.JSXOpeningFragment,
126
+ AST_NODE_TYPES.JSXSpreadAttribute,
127
+ AST_NODE_TYPES.JSXSpreadChild,
128
+ AST_NODE_TYPES.JSXText
124
129
  ]);
125
130
  var isDestructuringPattern = isOneOf([
126
- types.AST_NODE_TYPES.ArrayPattern,
127
- types.AST_NODE_TYPES.AssignmentPattern,
128
- types.AST_NODE_TYPES.ObjectPattern,
129
- types.AST_NODE_TYPES.RestElement
131
+ AST_NODE_TYPES.ArrayPattern,
132
+ AST_NODE_TYPES.AssignmentPattern,
133
+ AST_NODE_TYPES.ObjectPattern,
134
+ AST_NODE_TYPES.RestElement
130
135
  ]);
131
136
  var isTypeDeclaration = isOneOf([
132
- types.AST_NODE_TYPES.TSInterfaceDeclaration,
133
- types.AST_NODE_TYPES.TSTypeAliasDeclaration
137
+ AST_NODE_TYPES.TSInterfaceDeclaration,
138
+ AST_NODE_TYPES.TSTypeAliasDeclaration
134
139
  ]);
135
140
  var isLeftHandSideExpression = isOneOf([
136
- types.AST_NODE_TYPES.ArrayExpression,
137
- types.AST_NODE_TYPES.ArrayPattern,
138
- types.AST_NODE_TYPES.ArrowFunctionExpression,
139
- types.AST_NODE_TYPES.CallExpression,
140
- types.AST_NODE_TYPES.ClassExpression,
141
- types.AST_NODE_TYPES.FunctionExpression,
142
- types.AST_NODE_TYPES.Identifier,
143
- types.AST_NODE_TYPES.JSXElement,
144
- types.AST_NODE_TYPES.JSXFragment,
145
- types.AST_NODE_TYPES.Literal,
146
- types.AST_NODE_TYPES.TemplateLiteral,
147
- types.AST_NODE_TYPES.MemberExpression,
148
- types.AST_NODE_TYPES.MetaProperty,
149
- types.AST_NODE_TYPES.ObjectExpression,
150
- types.AST_NODE_TYPES.ObjectPattern,
151
- types.AST_NODE_TYPES.SequenceExpression,
152
- types.AST_NODE_TYPES.Super,
153
- types.AST_NODE_TYPES.TaggedTemplateExpression,
154
- types.AST_NODE_TYPES.ThisExpression
141
+ AST_NODE_TYPES.ArrayExpression,
142
+ AST_NODE_TYPES.ArrayPattern,
143
+ AST_NODE_TYPES.ArrowFunctionExpression,
144
+ AST_NODE_TYPES.CallExpression,
145
+ AST_NODE_TYPES.ClassExpression,
146
+ AST_NODE_TYPES.FunctionExpression,
147
+ AST_NODE_TYPES.Identifier,
148
+ AST_NODE_TYPES.JSXElement,
149
+ AST_NODE_TYPES.JSXFragment,
150
+ AST_NODE_TYPES.Literal,
151
+ AST_NODE_TYPES.TemplateLiteral,
152
+ AST_NODE_TYPES.MemberExpression,
153
+ AST_NODE_TYPES.MetaProperty,
154
+ AST_NODE_TYPES.ObjectExpression,
155
+ AST_NODE_TYPES.ObjectPattern,
156
+ AST_NODE_TYPES.SequenceExpression,
157
+ AST_NODE_TYPES.Super,
158
+ AST_NODE_TYPES.TaggedTemplateExpression,
159
+ AST_NODE_TYPES.ThisExpression
155
160
  ]);
156
161
  var isLeftHandSideExpressionType = isOneOf([
157
- types.AST_NODE_TYPES.ArrayExpression,
158
- types.AST_NODE_TYPES.ArrayPattern,
159
- types.AST_NODE_TYPES.ArrowFunctionExpression,
160
- types.AST_NODE_TYPES.CallExpression,
161
- types.AST_NODE_TYPES.ClassExpression,
162
- types.AST_NODE_TYPES.FunctionExpression,
163
- types.AST_NODE_TYPES.Identifier,
164
- types.AST_NODE_TYPES.JSXElement,
165
- types.AST_NODE_TYPES.JSXFragment,
166
- types.AST_NODE_TYPES.Literal,
167
- types.AST_NODE_TYPES.TemplateLiteral,
168
- types.AST_NODE_TYPES.MemberExpression,
169
- types.AST_NODE_TYPES.MetaProperty,
170
- types.AST_NODE_TYPES.ObjectExpression,
171
- types.AST_NODE_TYPES.ObjectPattern,
172
- types.AST_NODE_TYPES.SequenceExpression,
173
- types.AST_NODE_TYPES.Super,
174
- types.AST_NODE_TYPES.TaggedTemplateExpression,
175
- types.AST_NODE_TYPES.ThisExpression,
176
- types.AST_NODE_TYPES.TSAsExpression,
177
- types.AST_NODE_TYPES.TSNonNullExpression,
178
- types.AST_NODE_TYPES.TSTypeAssertion
162
+ AST_NODE_TYPES.ArrayExpression,
163
+ AST_NODE_TYPES.ArrayPattern,
164
+ AST_NODE_TYPES.ArrowFunctionExpression,
165
+ AST_NODE_TYPES.CallExpression,
166
+ AST_NODE_TYPES.ClassExpression,
167
+ AST_NODE_TYPES.FunctionExpression,
168
+ AST_NODE_TYPES.Identifier,
169
+ AST_NODE_TYPES.JSXElement,
170
+ AST_NODE_TYPES.JSXFragment,
171
+ AST_NODE_TYPES.Literal,
172
+ AST_NODE_TYPES.TemplateLiteral,
173
+ AST_NODE_TYPES.MemberExpression,
174
+ AST_NODE_TYPES.MetaProperty,
175
+ AST_NODE_TYPES.ObjectExpression,
176
+ AST_NODE_TYPES.ObjectPattern,
177
+ AST_NODE_TYPES.SequenceExpression,
178
+ AST_NODE_TYPES.Super,
179
+ AST_NODE_TYPES.TaggedTemplateExpression,
180
+ AST_NODE_TYPES.ThisExpression,
181
+ AST_NODE_TYPES.TSAsExpression,
182
+ AST_NODE_TYPES.TSNonNullExpression,
183
+ AST_NODE_TYPES.TSTypeAssertion
179
184
  ]);
180
185
  var isTypeExpression = isOneOf([
181
- types.AST_NODE_TYPES.TSAsExpression,
182
- types.AST_NODE_TYPES.TSTypeAssertion,
183
- types.AST_NODE_TYPES.TSNonNullExpression,
184
- types.AST_NODE_TYPES.TSSatisfiesExpression,
185
- types.AST_NODE_TYPES.TSInstantiationExpression
186
+ AST_NODE_TYPES.TSAsExpression,
187
+ AST_NODE_TYPES.TSTypeAssertion,
188
+ AST_NODE_TYPES.TSNonNullExpression,
189
+ AST_NODE_TYPES.TSSatisfiesExpression,
190
+ AST_NODE_TYPES.TSInstantiationExpression
186
191
  ]);
187
192
  var isTypeAssertionExpression = isOneOf([
188
- types.AST_NODE_TYPES.TSAsExpression,
189
- types.AST_NODE_TYPES.TSTypeAssertion,
190
- types.AST_NODE_TYPES.TSNonNullExpression,
191
- types.AST_NODE_TYPES.TSSatisfiesExpression
193
+ AST_NODE_TYPES.TSAsExpression,
194
+ AST_NODE_TYPES.TSTypeAssertion,
195
+ AST_NODE_TYPES.TSNonNullExpression,
196
+ AST_NODE_TYPES.TSSatisfiesExpression
192
197
  ]);
193
198
 
194
199
  // src/ast-expression.ts
@@ -199,7 +204,7 @@ function getJSExpression(node) {
199
204
  return node;
200
205
  }
201
206
  function isThisExpression(node) {
202
- return getJSExpression(node).type === types.AST_NODE_TYPES.ThisExpression;
207
+ return getJSExpression(node).type === AST_NODE_TYPES.ThisExpression;
203
208
  }
204
209
  function getFunctionId(node) {
205
210
  switch (true) {
@@ -207,24 +212,24 @@ function getFunctionId(node) {
207
212
  case ("id" in node && node.id != null):
208
213
  return node.id;
209
214
  // const whatever = function MaybeComponent() {};
210
- case (node.parent.type === types.AST_NODE_TYPES.VariableDeclarator && node.parent.init === node && node.parent.id.type === types.AST_NODE_TYPES.Identifier):
215
+ case (node.parent.type === AST_NODE_TYPES.VariableDeclarator && node.parent.init === node && node.parent.id.type === AST_NODE_TYPES.Identifier):
211
216
  return node.parent.id;
212
217
  // MaybeComponent = () => {};
213
- case (node.parent.type === types.AST_NODE_TYPES.AssignmentExpression && node.parent.right === node && node.parent.operator === "=" && node.parent.left.type === types.AST_NODE_TYPES.Identifier):
218
+ case (node.parent.type === AST_NODE_TYPES.AssignmentExpression && node.parent.right === node && node.parent.operator === "=" && node.parent.left.type === AST_NODE_TYPES.Identifier):
214
219
  return node.parent.left;
215
220
  // {MaybeComponent: () => {}}
216
221
  // {MaybeComponent() {}}
217
- case (node.parent.type === types.AST_NODE_TYPES.Property && node.parent.value === node && !node.parent.computed && node.parent.key.type === types.AST_NODE_TYPES.Identifier):
222
+ case (node.parent.type === AST_NODE_TYPES.Property && node.parent.value === node && !node.parent.computed && node.parent.key.type === AST_NODE_TYPES.Identifier):
218
223
  return node.parent.key;
219
224
  // class {MaybeComponent = () => {}}
220
225
  // class {MaybeComponent() {}}
221
- case (isMethodOrProperty(node.parent) && node.parent.value === node && node.parent.key.type === types.AST_NODE_TYPES.Identifier):
226
+ case (isMethodOrProperty(node.parent) && node.parent.value === node && node.parent.key.type === AST_NODE_TYPES.Identifier):
222
227
  return node.parent.key;
223
228
  // Follow spec convention for `IsAnonymousFunctionDefinition()` usage.
224
229
  //
225
230
  // const {MaybeComponent = () => {}} = {};
226
231
  // ({MaybeComponent = () => {}} = {});
227
- case (node.parent.type === types.AST_NODE_TYPES.AssignmentPattern && node.parent.right === node && node.parent.left.type === types.AST_NODE_TYPES.Identifier):
232
+ case (node.parent.type === AST_NODE_TYPES.AssignmentPattern && node.parent.right === node && node.parent.left.type === AST_NODE_TYPES.Identifier):
228
233
  return node.parent.left;
229
234
  // const MaybeComponent = (() => {})!;
230
235
  // const MaybeComponent = (() => {}) as FunctionComponent;
@@ -232,38 +237,38 @@ function getFunctionId(node) {
232
237
  case isTypeAssertionExpression(node.parent):
233
238
  return getFunctionId(node.parent);
234
239
  }
235
- return eff._;
240
+ return _;
236
241
  }
237
242
  function getFunctionInitPath(node) {
238
- if (node.type === types.AST_NODE_TYPES.FunctionDeclaration) {
243
+ if (node.type === AST_NODE_TYPES.FunctionDeclaration) {
239
244
  return [node];
240
245
  }
241
246
  const { parent } = node;
242
247
  switch (true) {
243
- case parent.type === types.AST_NODE_TYPES.VariableDeclarator:
248
+ case parent.type === AST_NODE_TYPES.VariableDeclarator:
244
249
  return [parent.parent, parent, node];
245
- case (parent.type === types.AST_NODE_TYPES.CallExpression && parent.parent.type === types.AST_NODE_TYPES.VariableDeclarator):
250
+ case (parent.type === AST_NODE_TYPES.CallExpression && parent.parent.type === AST_NODE_TYPES.VariableDeclarator):
246
251
  return [parent.parent.parent, parent.parent, parent, node];
247
- case (parent.type === types.AST_NODE_TYPES.CallExpression && parent.parent.type === types.AST_NODE_TYPES.CallExpression && parent.parent.parent.type === types.AST_NODE_TYPES.VariableDeclarator):
252
+ case (parent.type === AST_NODE_TYPES.CallExpression && parent.parent.type === AST_NODE_TYPES.CallExpression && parent.parent.parent.type === AST_NODE_TYPES.VariableDeclarator):
248
253
  return [parent.parent.parent.parent, parent.parent.parent, parent.parent, parent, node];
249
- case (parent.type === types.AST_NODE_TYPES.Property && parent.parent.type === types.AST_NODE_TYPES.ObjectExpression && parent.parent.parent.type === types.AST_NODE_TYPES.VariableDeclarator):
254
+ case (parent.type === AST_NODE_TYPES.Property && parent.parent.type === AST_NODE_TYPES.ObjectExpression && parent.parent.parent.type === AST_NODE_TYPES.VariableDeclarator):
250
255
  return [parent.parent.parent.parent, parent.parent.parent, parent.parent, parent, node];
251
- case (parent.type === types.AST_NODE_TYPES.MethodDefinition && parent.parent.parent.type === types.AST_NODE_TYPES.ClassDeclaration):
256
+ case (parent.type === AST_NODE_TYPES.MethodDefinition && parent.parent.parent.type === AST_NODE_TYPES.ClassDeclaration):
252
257
  return [parent.parent.parent, parent.parent, parent, node];
253
- case (parent.type === types.AST_NODE_TYPES.PropertyDefinition && parent.parent.parent.type === types.AST_NODE_TYPES.ClassDeclaration):
258
+ case (parent.type === AST_NODE_TYPES.PropertyDefinition && parent.parent.parent.type === AST_NODE_TYPES.ClassDeclaration):
254
259
  return [parent.parent.parent, parent.parent, parent, node];
255
260
  }
256
- return eff._;
261
+ return _;
257
262
  }
258
263
  function hasCallInFunctionInitPath(callName, initPath) {
259
264
  return initPath.some((n) => {
260
- if (n.type !== types.AST_NODE_TYPES.CallExpression) {
265
+ if (n.type !== AST_NODE_TYPES.CallExpression) {
261
266
  return false;
262
267
  }
263
268
  switch (n.callee.type) {
264
- case types.AST_NODE_TYPES.Identifier:
269
+ case AST_NODE_TYPES.Identifier:
265
270
  return n.callee.name === callName;
266
- case types.AST_NODE_TYPES.MemberExpression:
271
+ case AST_NODE_TYPES.MemberExpression:
267
272
  return "name" in n.callee.property && n.callee.property.name === callName;
268
273
  default:
269
274
  return false;
@@ -271,22 +276,25 @@ function hasCallInFunctionInitPath(callName, initPath) {
271
276
  });
272
277
  }
273
278
  function isEmptyFunction(node) {
274
- return node.body.type === types.AST_NODE_TYPES.BlockStatement && node.body.body.length === 0;
279
+ return node.body.type === AST_NODE_TYPES.BlockStatement && node.body.body.length === 0;
280
+ }
281
+ function isImmediatelyInvokedFunction(node) {
282
+ return node.type !== AST_NODE_TYPES.FunctionDeclaration && node.parent.type === AST_NODE_TYPES.CallExpression && node.parent.callee === node;
275
283
  }
276
284
  function findParentNode(node, test) {
277
- if (node == null) return eff._;
285
+ if (node == null) return _;
278
286
  let parent = node.parent;
279
- while (parent != null && parent.type !== types.AST_NODE_TYPES.Program) {
287
+ while (parent != null && parent.type !== AST_NODE_TYPES.Program) {
280
288
  if (test(parent)) {
281
289
  return parent;
282
290
  }
283
291
  parent = parent.parent;
284
292
  }
285
- return eff._;
293
+ return _;
286
294
  }
287
295
  function getNestedIdentifiers(node) {
288
296
  const identifiers = [];
289
- if (node.type === types.AST_NODE_TYPES.Identifier) {
297
+ if (node.type === AST_NODE_TYPES.Identifier) {
290
298
  identifiers.push(node);
291
299
  }
292
300
  if ("arguments" in node) {
@@ -313,35 +321,35 @@ function getNestedIdentifiers(node) {
313
321
  const chunk = getNestedIdentifiers(node.right);
314
322
  identifiers.push(...chunk);
315
323
  }
316
- if (node.type === types.AST_NODE_TYPES.Property) {
324
+ if (node.type === AST_NODE_TYPES.Property) {
317
325
  const chunk = getNestedIdentifiers(node.value);
318
326
  identifiers.push(...chunk);
319
327
  }
320
- if (node.type === types.AST_NODE_TYPES.SpreadElement) {
328
+ if (node.type === AST_NODE_TYPES.SpreadElement) {
321
329
  const chunk = getNestedIdentifiers(node.argument);
322
330
  identifiers.push(...chunk);
323
331
  }
324
- if (node.type === types.AST_NODE_TYPES.MemberExpression) {
332
+ if (node.type === AST_NODE_TYPES.MemberExpression) {
325
333
  const chunk = getNestedIdentifiers(node.object);
326
334
  identifiers.push(...chunk);
327
335
  }
328
- if (node.type === types.AST_NODE_TYPES.UnaryExpression) {
336
+ if (node.type === AST_NODE_TYPES.UnaryExpression) {
329
337
  const chunk = getNestedIdentifiers(node.argument);
330
338
  identifiers.push(...chunk);
331
339
  }
332
- if (node.type === types.AST_NODE_TYPES.ChainExpression) {
340
+ if (node.type === AST_NODE_TYPES.ChainExpression) {
333
341
  const chunk = getNestedIdentifiers(node.expression);
334
342
  identifiers.push(...chunk);
335
343
  }
336
- if (node.type === types.AST_NODE_TYPES.TSNonNullExpression) {
344
+ if (node.type === AST_NODE_TYPES.TSNonNullExpression) {
337
345
  const chunk = getNestedIdentifiers(node.expression);
338
346
  identifiers.push(...chunk);
339
347
  }
340
- if (node.type === types.AST_NODE_TYPES.TSAsExpression) {
348
+ if (node.type === AST_NODE_TYPES.TSAsExpression) {
341
349
  const chunk = getNestedIdentifiers(node.expression);
342
350
  identifiers.push(...chunk);
343
351
  }
344
- if (node.type === types.AST_NODE_TYPES.TSSatisfiesExpression) {
352
+ if (node.type === AST_NODE_TYPES.TSSatisfiesExpression) {
345
353
  const chunk = getNestedIdentifiers(node.expression);
346
354
  identifiers.push(...chunk);
347
355
  }
@@ -350,9 +358,9 @@ function getNestedIdentifiers(node) {
350
358
  function getNestedReturnStatements(node) {
351
359
  const statements = [];
352
360
  const boundaryNode = isFunction(node) ? node : findParentNode(node, isFunction);
353
- typescriptEstree.simpleTraverse(node, {
361
+ simpleTraverse(node, {
354
362
  enter(node2) {
355
- if (node2.type !== types.AST_NODE_TYPES.ReturnStatement) {
363
+ if (node2.type !== AST_NODE_TYPES.ReturnStatement) {
356
364
  return;
357
365
  }
358
366
  const parentFunction = findParentNode(node2, isFunction);
@@ -412,51 +420,51 @@ function getNestedExpressionsOfType(type) {
412
420
  const chunk = node.expressions.map(boundGetNestedExpressionsOfType).flat(1);
413
421
  expressions.push(...chunk);
414
422
  }
415
- if (node.type === types.AST_NODE_TYPES.Property) {
423
+ if (node.type === AST_NODE_TYPES.Property) {
416
424
  const chunk = boundGetNestedExpressionsOfType(node.value);
417
425
  expressions.push(...chunk);
418
426
  }
419
- if (node.type === types.AST_NODE_TYPES.SpreadElement) {
427
+ if (node.type === AST_NODE_TYPES.SpreadElement) {
420
428
  const chunk = boundGetNestedExpressionsOfType(node.argument);
421
429
  expressions.push(...chunk);
422
430
  }
423
- if (node.type === types.AST_NODE_TYPES.MemberExpression) {
431
+ if (node.type === AST_NODE_TYPES.MemberExpression) {
424
432
  const chunk = boundGetNestedExpressionsOfType(node.object);
425
433
  expressions.push(...chunk);
426
434
  }
427
- if (node.type === types.AST_NODE_TYPES.UnaryExpression) {
435
+ if (node.type === AST_NODE_TYPES.UnaryExpression) {
428
436
  const chunk = boundGetNestedExpressionsOfType(node.argument);
429
437
  expressions.push(...chunk);
430
438
  }
431
- if (node.type === types.AST_NODE_TYPES.ChainExpression) {
439
+ if (node.type === AST_NODE_TYPES.ChainExpression) {
432
440
  const chunk = boundGetNestedExpressionsOfType(node.expression);
433
441
  expressions.push(...chunk);
434
442
  }
435
- if (node.type === types.AST_NODE_TYPES.TSNonNullExpression) {
443
+ if (node.type === AST_NODE_TYPES.TSNonNullExpression) {
436
444
  const chunk = boundGetNestedExpressionsOfType(node.expression);
437
445
  expressions.push(...chunk);
438
446
  }
439
- if (node.type === types.AST_NODE_TYPES.TSAsExpression) {
447
+ if (node.type === AST_NODE_TYPES.TSAsExpression) {
440
448
  const chunk = boundGetNestedExpressionsOfType(node.expression);
441
449
  expressions.push(...chunk);
442
450
  }
443
- if (node.type === types.AST_NODE_TYPES.TSSatisfiesExpression) {
451
+ if (node.type === AST_NODE_TYPES.TSSatisfiesExpression) {
444
452
  const chunk = boundGetNestedExpressionsOfType(node.expression);
445
453
  expressions.push(...chunk);
446
454
  }
447
455
  return expressions;
448
456
  };
449
457
  }
450
- var getNestedNewExpressions = getNestedExpressionsOfType(types.AST_NODE_TYPES.NewExpression);
451
- var getNestedCallExpressions = getNestedExpressionsOfType(types.AST_NODE_TYPES.CallExpression);
458
+ var getNestedNewExpressions = getNestedExpressionsOfType(AST_NODE_TYPES.NewExpression);
459
+ var getNestedCallExpressions = getNestedExpressionsOfType(AST_NODE_TYPES.CallExpression);
452
460
  function isMultiLine(node) {
453
461
  return node.loc.start.line !== node.loc.end.line;
454
462
  }
455
463
  function isLineBreak(node) {
456
- return isOneOf([types.AST_NODE_TYPES.Literal, types.AST_NODE_TYPES.JSXText])(node) && typeof node.value === "string" && node.value.trim() === "" && isMultiLine(node);
464
+ return isOneOf([AST_NODE_TYPES.Literal, AST_NODE_TYPES.JSXText])(node) && typeof node.value === "string" && node.value.trim() === "" && isMultiLine(node);
457
465
  }
458
466
  function isLiteral(node, type) {
459
- if (node.type !== types.AST_NODE_TYPES.Literal) return false;
467
+ if (node.type !== AST_NODE_TYPES.Literal) return false;
460
468
  if (type == null) return true;
461
469
  switch (type) {
462
470
  case "boolean":
@@ -471,17 +479,17 @@ function isLiteral(node, type) {
471
479
  return typeof node.value === "string";
472
480
  }
473
481
  }
474
- var isNodeEqual = eff.dual(2, (a, b) => {
482
+ var isNodeEqual = dual(2, (a, b) => {
475
483
  switch (true) {
476
484
  case a === b:
477
485
  return true;
478
486
  case a.type !== b.type:
479
487
  return false;
480
- case (a.type === types.AST_NODE_TYPES.Literal && b.type === types.AST_NODE_TYPES.Literal):
488
+ case (a.type === AST_NODE_TYPES.Literal && b.type === AST_NODE_TYPES.Literal):
481
489
  return a.value === b.value;
482
- case (a.type === types.AST_NODE_TYPES.TemplateElement && b.type === types.AST_NODE_TYPES.TemplateElement):
490
+ case (a.type === AST_NODE_TYPES.TemplateElement && b.type === AST_NODE_TYPES.TemplateElement):
483
491
  return a.value.raw === b.value.raw;
484
- case (a.type === types.AST_NODE_TYPES.TemplateLiteral && b.type === types.AST_NODE_TYPES.TemplateLiteral): {
492
+ case (a.type === AST_NODE_TYPES.TemplateLiteral && b.type === AST_NODE_TYPES.TemplateLiteral): {
485
493
  if (a.quasis.length !== b.quasis.length || a.expressions.length !== b.expressions.length) {
486
494
  return false;
487
495
  }
@@ -501,13 +509,13 @@ var isNodeEqual = eff.dual(2, (a, b) => {
501
509
  }
502
510
  return true;
503
511
  }
504
- case (a.type === types.AST_NODE_TYPES.Identifier && b.type === types.AST_NODE_TYPES.Identifier):
512
+ case (a.type === AST_NODE_TYPES.Identifier && b.type === AST_NODE_TYPES.Identifier):
505
513
  return a.name === b.name;
506
- case (a.type === types.AST_NODE_TYPES.PrivateIdentifier && b.type === types.AST_NODE_TYPES.PrivateIdentifier):
514
+ case (a.type === AST_NODE_TYPES.PrivateIdentifier && b.type === AST_NODE_TYPES.PrivateIdentifier):
507
515
  return a.name === b.name;
508
- case (a.type === types.AST_NODE_TYPES.MemberExpression && b.type === types.AST_NODE_TYPES.MemberExpression):
516
+ case (a.type === AST_NODE_TYPES.MemberExpression && b.type === AST_NODE_TYPES.MemberExpression):
509
517
  return isNodeEqual(a.property, b.property) && isNodeEqual(a.object, b.object);
510
- case (a.type === types.AST_NODE_TYPES.JSXAttribute && b.type === types.AST_NODE_TYPES.JSXAttribute): {
518
+ case (a.type === AST_NODE_TYPES.JSXAttribute && b.type === AST_NODE_TYPES.JSXAttribute): {
511
519
  if (a.name.name !== b.name.name) {
512
520
  return false;
513
521
  }
@@ -516,18 +524,18 @@ var isNodeEqual = eff.dual(2, (a, b) => {
516
524
  }
517
525
  return isNodeEqual(a.value, b.value);
518
526
  }
519
- case (a.type === types.AST_NODE_TYPES.ThisExpression && b.type === types.AST_NODE_TYPES.ThisExpression):
527
+ case (a.type === AST_NODE_TYPES.ThisExpression && b.type === AST_NODE_TYPES.ThisExpression):
520
528
  return true;
521
529
  default:
522
530
  return false;
523
531
  }
524
532
  });
525
533
  function isProcessEnvNodeEnv(node) {
526
- return node != null && node.type === types.AST_NODE_TYPES.MemberExpression && node.object.type === types.AST_NODE_TYPES.MemberExpression && node.object.object.type === types.AST_NODE_TYPES.Identifier && node.object.object.name === "process" && node.object.property.type === types.AST_NODE_TYPES.Identifier && node.object.property.name === "env" && node.property.type === types.AST_NODE_TYPES.Identifier && node.property.name === "NODE_ENV";
534
+ return node != null && node.type === AST_NODE_TYPES.MemberExpression && node.object.type === AST_NODE_TYPES.MemberExpression && node.object.object.type === AST_NODE_TYPES.Identifier && node.object.object.name === "process" && node.object.property.type === AST_NODE_TYPES.Identifier && node.object.property.name === "env" && node.property.type === AST_NODE_TYPES.Identifier && node.property.name === "NODE_ENV";
527
535
  }
528
536
  function isProcessEnvNodeEnvCompare(node, operator, value) {
529
537
  if (node == null) return false;
530
- if (node.type !== types.AST_NODE_TYPES.BinaryExpression) return false;
538
+ if (node.type !== AST_NODE_TYPES.BinaryExpression) return false;
531
539
  if (node.operator !== operator) return false;
532
540
  if (isProcessEnvNodeEnv(node.left) && isLiteral(node.right, "string")) {
533
541
  return node.right.value === value;
@@ -541,96 +549,54 @@ function getPropertyName(node) {
541
549
  if (isTypeExpression(node)) {
542
550
  return getPropertyName(getJSExpression(node));
543
551
  }
544
- if (node.type === types.AST_NODE_TYPES.Identifier || node.type === types.AST_NODE_TYPES.PrivateIdentifier) {
552
+ if (node.type === AST_NODE_TYPES.Identifier || node.type === AST_NODE_TYPES.PrivateIdentifier) {
545
553
  return node.name;
546
554
  }
547
- if (node.type === types.AST_NODE_TYPES.Literal) {
555
+ if (node.type === AST_NODE_TYPES.Literal) {
548
556
  return String(node.value);
549
557
  }
550
- if (node.type === types.AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) {
558
+ if (node.type === AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) {
551
559
  return node.quasis[0]?.value.raw;
552
560
  }
553
- return eff._;
561
+ return _;
562
+ }
563
+ function isThenCall(node) {
564
+ return node.callee.type === AST_NODE_TYPES.MemberExpression && node.callee.property.type === AST_NODE_TYPES.Identifier && node.callee.property.name === "then";
554
565
  }
555
566
  function getLiteralValueType(input) {
556
567
  if (input === null) return "null";
557
568
  return typeof input;
558
569
  }
559
570
  function toDelimiterCaseType(node, delimiter = " ") {
560
- if (node.type === types.AST_NODE_TYPES.Literal) {
571
+ if (node.type === AST_NODE_TYPES.Literal) {
561
572
  if ("regex" in node) {
562
573
  return "RegExp literal";
563
574
  }
564
575
  return `${getLiteralValueType(node.value)} literal`;
565
576
  }
566
577
  if (isJSX(node)) {
567
- return `JSX ${stringTs.toLowerCase(stringTs.delimiterCase(stringTs.replace(node.type, "JSX", ""), delimiter))}`;
578
+ return `JSX ${toLowerCase(delimiterCase(replace(node.type, "JSX", ""), delimiter))}`;
568
579
  }
569
- return stringTs.toLowerCase(stringTs.delimiterCase(node.type, delimiter));
580
+ return toLowerCase(delimiterCase(node.type, delimiter));
570
581
  }
571
582
  function toString(node, getText) {
572
583
  switch (node.type) {
573
- case types.AST_NODE_TYPES.Identifier:
574
- case types.AST_NODE_TYPES.JSXIdentifier:
575
- case types.AST_NODE_TYPES.PrivateIdentifier:
584
+ case AST_NODE_TYPES.Identifier:
585
+ case AST_NODE_TYPES.JSXIdentifier:
586
+ case AST_NODE_TYPES.PrivateIdentifier:
576
587
  return node.name;
577
- case types.AST_NODE_TYPES.MemberExpression:
578
- case types.AST_NODE_TYPES.JSXMemberExpression:
588
+ case AST_NODE_TYPES.MemberExpression:
589
+ case AST_NODE_TYPES.JSXMemberExpression:
579
590
  return `${toString(node.object, getText)}.${toString(node.property, getText)}`;
580
- case types.AST_NODE_TYPES.JSXNamespacedName:
591
+ case AST_NODE_TYPES.JSXNamespacedName:
581
592
  return `${node.namespace.name}:${node.name.name}`;
582
- case types.AST_NODE_TYPES.JSXText:
593
+ case AST_NODE_TYPES.JSXText:
583
594
  return node.value;
584
- case types.AST_NODE_TYPES.Literal:
595
+ case AST_NODE_TYPES.Literal:
585
596
  return node.raw;
586
597
  default:
587
598
  return getText(node);
588
599
  }
589
600
  }
590
601
 
591
- exports.findParentNode = findParentNode;
592
- exports.getArrayMethodCallbackIndexParamPosition = getArrayMethodCallbackIndexParamPosition;
593
- exports.getClassId = getClassId;
594
- exports.getFunctionId = getFunctionId;
595
- exports.getFunctionInitPath = getFunctionInitPath;
596
- exports.getJSExpression = getJSExpression;
597
- exports.getNestedCallExpressions = getNestedCallExpressions;
598
- exports.getNestedExpressionsOfType = getNestedExpressionsOfType;
599
- exports.getNestedIdentifiers = getNestedIdentifiers;
600
- exports.getNestedNewExpressions = getNestedNewExpressions;
601
- exports.getNestedReturnStatements = getNestedReturnStatements;
602
- exports.getPropertyName = getPropertyName;
603
- exports.hasCallInFunctionInitPath = hasCallInFunctionInitPath;
604
- exports.is = is;
605
- exports.isArrayFromCall = isArrayFromCall;
606
- exports.isArrayMapCall = isArrayMapCall;
607
- exports.isArrayTupleType = isArrayTupleType;
608
- exports.isClass = isClass;
609
- exports.isConditional = isConditional;
610
- exports.isControlFlow = isControlFlow;
611
- exports.isDestructuringPattern = isDestructuringPattern;
612
- exports.isEmptyFunction = isEmptyFunction;
613
- exports.isFunction = isFunction;
614
- exports.isFunctionType = isFunctionType;
615
- exports.isJSX = isJSX;
616
- exports.isJSXElement = isJSXElement;
617
- exports.isJSXFragment = isJSXFragment;
618
- exports.isJSXTagNameExpression = isJSXTagNameExpression;
619
- exports.isLeftHandSideExpression = isLeftHandSideExpression;
620
- exports.isLeftHandSideExpressionType = isLeftHandSideExpressionType;
621
- exports.isLineBreak = isLineBreak;
622
- exports.isLiteral = isLiteral;
623
- exports.isLoop = isLoop;
624
- exports.isMethodOrProperty = isMethodOrProperty;
625
- exports.isMultiLine = isMultiLine;
626
- exports.isNodeEqual = isNodeEqual;
627
- exports.isOneOf = isOneOf;
628
- exports.isProcessEnvNodeEnv = isProcessEnvNodeEnv;
629
- exports.isProcessEnvNodeEnvCompare = isProcessEnvNodeEnvCompare;
630
- exports.isProperty = isProperty;
631
- exports.isThisExpression = isThisExpression;
632
- exports.isTypeAssertionExpression = isTypeAssertionExpression;
633
- exports.isTypeDeclaration = isTypeDeclaration;
634
- exports.isTypeExpression = isTypeExpression;
635
- exports.toDelimiterCaseType = toDelimiterCaseType;
636
- exports.toString = toString;
602
+ export { findParentNode, getArrayMethodCallbackIndexParamPosition, getArrayPatternElementNameAt, getClassId, getFunctionId, getFunctionInitPath, getJSExpression, getNestedCallExpressions, getNestedExpressionsOfType, getNestedIdentifiers, getNestedNewExpressions, getNestedReturnStatements, getPropertyName, hasCallInFunctionInitPath, is, isArrayFromCall, isArrayMapCall, isArrayTupleType, isClass, isConditional, isControlFlow, isDestructuringPattern, isEmptyFunction, isFunction, isFunctionType, isImmediatelyInvokedFunction, isJSX, isJSXElement, isJSXFragment, isJSXTagNameExpression, isLeftHandSideExpression, isLeftHandSideExpressionType, isLineBreak, isLiteral, isLoop, isMethodOrProperty, isMultiLine, isNodeEqual, isOneOf, isProcessEnvNodeEnv, isProcessEnvNodeEnvCompare, isProperty, isThenCall, isThisExpression, isTypeAssertionExpression, isTypeDeclaration, isTypeExpression, toDelimiterCaseType, toString };