@eslint-react/ast 1.52.3-next.9 → 2.0.0-beta.0

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