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

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.d.ts CHANGED
@@ -1,14 +1,12 @@
1
1
  import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/types';
2
2
  import { TSESTree as TSESTree$1 } from '@typescript-eslint/utils';
3
- import { _ } from '@eslint-react/eff';
3
+ import { unit } from '@eslint-react/eff';
4
4
 
5
5
  declare function isArrayFromCall(node: TSESTree.Node, loose?: boolean): node is TSESTree.CallExpression;
6
6
  declare function isArrayMapCall(node: TSESTree.Node, loose?: boolean): node is TSESTree.CallExpression;
7
7
 
8
8
  declare function getArrayMethodCallbackIndexParamPosition(methodName: string): number;
9
9
 
10
- declare function getArrayPatternElementNameAt(node: TSESTree.Identifier, at: number): string | true | undefined;
11
-
12
10
  type TSESTreeFunction = TSESTree$1.ArrowFunctionExpression | TSESTree$1.FunctionDeclaration | TSESTree$1.FunctionExpression;
13
11
  type TSESTreeFunctionType = TSESTree$1.TSCallSignatureDeclaration | TSESTree$1.TSConstructSignatureDeclaration | TSESTree$1.TSDeclareFunction | TSESTree$1.TSEmptyBodyFunctionExpression | TSESTree$1.TSFunctionType | TSESTree$1.TSMethodSignature | TSESTreeFunction;
14
12
  type TSESTreeClass = TSESTree$1.ClassDeclaration | TSESTree$1.ClassExpression;
@@ -22,12 +20,7 @@ type TSESTreeTypeDeclaration = TSESTree$1.TSInterfaceDeclaration | TSESTree$1.TS
22
20
  type TSESTreeTypeExpression = TSESTree$1.TSAsExpression | TSESTree$1.TSNonNullExpression | TSESTree$1.TSSatisfiesExpression | TSESTree$1.TSTypeAssertion | TSESTree$1.TSInstantiationExpression;
23
21
  type TSESTreeTypeAssertionExpression = TSESTree$1.TSAsExpression | TSESTree$1.TSNonNullExpression | TSESTree$1.TSSatisfiesExpression | TSESTree$1.TSTypeAssertion;
24
22
 
25
- /**
26
- * Gets class identifier from ClassDeclaration or ClassExpression
27
- * @param node The AST node to check
28
- * @returns class identifier or null
29
- */
30
- declare function getClassId(node: TSESTreeClass): TSESTree.Identifier | _;
23
+ declare function getClassId(node: TSESTreeClass): TSESTree.Identifier | unit;
31
24
 
32
25
  /**
33
26
  * Recursively get the inner expression until it's not a TypeExpression
@@ -44,8 +37,7 @@ declare function isThisExpression(node: TSESTree.Expression): boolean;
44
37
  * where JS gives anonymous function expressions names. We roughly detect the
45
38
  * same AST nodes with some exceptions to better fit our use case.
46
39
  */
47
-
48
- declare function getFunctionId(node: TSESTree.Expression | TSESTreeFunction): TSESTree.Identifier | _;
40
+ declare function getFunctionId(node: TSESTree.Expression | TSESTreeFunction): TSESTree.Identifier | unit;
49
41
 
50
42
  type FunctionInitPath =
51
43
  /**
@@ -145,7 +137,7 @@ readonly [TSESTree.FunctionDeclaration]
145
137
  TSESTree.PropertyDefinition,
146
138
  TSESTreeFunction
147
139
  ];
148
- declare function getFunctionInitPath(node: TSESTreeFunction): FunctionInitPath | _;
140
+ declare function getFunctionInitPath(node: TSESTreeFunction): unit | FunctionInitPath;
149
141
  declare function hasCallInFunctionInitPath(callName: string, initPath: FunctionInitPath): boolean;
150
142
 
151
143
  declare function isEmptyFunction(node: TSESTreeFunction): boolean;
@@ -157,14 +149,14 @@ declare function isImmediatelyInvokedFunction(node: TSESTreeFunction): boolean;
157
149
  * @param test The test function
158
150
  * @returns The parent node that satisfies the test function or `_` if not found
159
151
  */
160
- declare function findParentNode<A extends TSESTree.Node>(node: TSESTree.Node | _, test: (n: TSESTree.Node) => n is A): A | _;
152
+ declare function findParentNode<A extends TSESTree.Node>(node: TSESTree.Node | unit, test: (n: TSESTree.Node) => n is A): A | unit;
161
153
  /**
162
154
  * Find the parent node that satisfies the test function or `_` if not found
163
155
  * @param node The AST node
164
156
  * @param test The test function
165
157
  * @returns The parent node that satisfies the test function
166
158
  */
167
- declare function findParentNode(node: TSESTree.Node | _, test: (node: TSESTree.Node) => boolean): TSESTree.Node | _;
159
+ declare function findParentNode(node: TSESTree.Node | unit, test: (node: TSESTree.Node) => boolean): TSESTree.Node | unit;
168
160
 
169
161
  /**
170
162
  * Get all nested identifiers in a expression like node
@@ -200,32 +192,6 @@ declare const getNestedNewExpressions: (node: TSESTree.Node) => TSESTree.NewExpr
200
192
  */
201
193
  declare const getNestedCallExpressions: (node: TSESTree.Node) => TSESTree.CallExpression[];
202
194
 
203
- declare const is: <NodeType extends TSESTree.AST_NODE_TYPES>(nodeType: NodeType) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
204
- type: NodeType;
205
- }>;
206
- declare const isOneOf: <NodeTypes extends readonly TSESTree.AST_NODE_TYPES[]>(nodeTypes: NodeTypes) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
207
- type: NodeTypes[number];
208
- }>;
209
- declare const isFunction: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression;
210
- declare const isFunctionType: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression | TSESTree.TSCallSignatureDeclaration | TSESTree.TSConstructSignatureDeclaration | TSESTree.TSDeclareFunctionNoDeclare | TSESTree.TSDeclareFunctionWithDeclare | TSESTree.TSEmptyBodyFunctionExpression | TSESTree.TSFunctionType | TSESTree.TSMethodSignatureComputedName | TSESTree.TSMethodSignatureNonComputedName;
211
- declare const isClass: (node: TSESTree.Node | null | undefined) => node is TSESTree.ClassDeclarationWithName | TSESTree.ClassDeclarationWithOptionalName | TSESTree.ClassExpression;
212
- declare const isMethodOrProperty: (node: TSESTree.Node | null | undefined) => node is TSESTree.MethodDefinitionComputedName | TSESTree.MethodDefinitionNonComputedName | TSESTree.PropertyDefinitionComputedName | TSESTree.PropertyDefinitionNonComputedName;
213
- declare const isLoop: (node: TSESTree.Node | null | undefined) => node is TSESTree.DoWhileStatement | TSESTree.ForInStatement | TSESTree.ForOfStatement | TSESTree.ForStatement | TSESTree.WhileStatement;
214
- declare const isControlFlow: (data: TSESTree.Node | null | undefined) => data is TSESTree.DoWhileStatement | TSESTree.ForInStatement | TSESTree.ForOfStatement | TSESTree.ForStatement | TSESTree.IfStatement | TSESTree.SwitchStatement | TSESTree.WhileStatement;
215
- declare const isConditional: (data: TSESTree.Node | null | undefined) => data is TSESTree.ConditionalExpression | TSESTree.DoWhileStatement | TSESTree.ForInStatement | TSESTree.ForOfStatement | TSESTree.ForStatement | TSESTree.IfStatement | TSESTree.LogicalExpression | TSESTree.SwitchStatement | TSESTree.WhileStatement;
216
- declare const isArrayTupleType: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSArrayType | TSESTree.TSTupleType;
217
- declare const isProperty: (node: TSESTree.Node | null | undefined) => node is TSESTree.PropertyDefinitionComputedName | TSESTree.PropertyDefinitionNonComputedName | TSESTree.TSIndexSignature | TSESTree.TSParameterProperty | TSESTree.TSPropertySignatureComputedName | TSESTree.TSPropertySignatureNonComputedName;
218
- declare const isJSXElement: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXElement;
219
- declare const isJSXFragment: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXFragment;
220
- declare const isJSXTagNameExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXIdentifier | TSESTree.JSXMemberExpression | TSESTree.JSXNamespacedName;
221
- declare const isJSX: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXAttribute | TSESTree.JSXClosingElement | TSESTree.JSXClosingFragment | TSESTree.JSXElement | TSESTree.JSXEmptyExpression | TSESTree.JSXExpressionContainer | TSESTree.JSXFragment | TSESTree.JSXIdentifier | TSESTree.JSXMemberExpression | TSESTree.JSXNamespacedName | TSESTree.JSXOpeningElement | TSESTree.JSXOpeningFragment | TSESTree.JSXSpreadAttribute | TSESTree.JSXSpreadChild | TSESTree.JSXText;
222
- declare const isDestructuringPattern: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrayPattern | TSESTree.AssignmentPattern | TSESTree.ObjectPattern | TSESTree.RestElement;
223
- declare const isTypeDeclaration: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSInterfaceDeclaration | TSESTree.TSTypeAliasDeclaration;
224
- declare const isLeftHandSideExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpression | TSESTree.CallExpression | TSESTree.ClassExpression | TSESTree.FunctionExpression | TSESTree.Identifier | TSESTree.JSXElement | TSESTree.JSXFragment | TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral | TSESTree.MemberExpressionComputedName | TSESTree.MemberExpressionNonComputedName | TSESTree.MetaProperty | TSESTree.ObjectExpression | TSESTree.ObjectPattern | TSESTree.SequenceExpression | TSESTree.Super | TSESTree.TaggedTemplateExpression | TSESTree.TemplateLiteral | TSESTree.ThisExpression;
225
- declare const isLeftHandSideExpressionType: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpression | TSESTree.CallExpression | TSESTree.ClassExpression | TSESTree.FunctionExpression | TSESTree.Identifier | TSESTree.JSXElement | TSESTree.JSXFragment | TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral | TSESTree.MemberExpressionComputedName | TSESTree.MemberExpressionNonComputedName | TSESTree.MetaProperty | TSESTree.ObjectExpression | TSESTree.ObjectPattern | TSESTree.SequenceExpression | TSESTree.Super | TSESTree.TaggedTemplateExpression | TSESTree.TemplateLiteral | TSESTree.ThisExpression | TSESTree.TSAsExpression | TSESTree.TSNonNullExpression | TSESTree.TSTypeAssertion;
226
- declare const isTypeExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSAsExpression | TSESTree.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
227
- declare const isTypeAssertionExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSAsExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
228
-
229
195
  /**
230
196
  * Check if a node is multiline
231
197
  * @param node The AST node to check
@@ -258,12 +224,40 @@ declare const isNodeEqual: {
258
224
  (a: TSESTree.Node, b: TSESTree.Node): boolean;
259
225
  };
260
226
 
227
+ /**
228
+ * @internal
229
+ */
230
+ declare function toDelimiterFormat(node: TSESTree.Node, delimiter?: string): "RegExp literal" | Lowercase<string> | `JSX ${Lowercase<string>}`;
231
+ /**
232
+ * @internal
233
+ */
234
+ declare function toStringFormat(node: TSESTree.Node, getText: (node: TSESTree.Node) => string): string;
235
+
236
+ declare const is: <NodeType extends TSESTree.AST_NODE_TYPES>(nodeType: NodeType) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
237
+ type: NodeType;
238
+ }>;
239
+ declare const isOneOf: <NodeTypes extends readonly TSESTree.AST_NODE_TYPES[]>(nodeTypes: NodeTypes) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
240
+ type: NodeTypes[number];
241
+ }>;
242
+ declare const isFunction: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression;
243
+ declare const isFunctionType: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression | TSESTree.TSCallSignatureDeclaration | TSESTree.TSConstructSignatureDeclaration | TSESTree.TSDeclareFunctionNoDeclare | TSESTree.TSDeclareFunctionWithDeclare | TSESTree.TSEmptyBodyFunctionExpression | TSESTree.TSFunctionType | TSESTree.TSMethodSignatureComputedName | TSESTree.TSMethodSignatureNonComputedName;
244
+ declare const isClass: (node: TSESTree.Node | null | undefined) => node is TSESTree.ClassDeclarationWithName | TSESTree.ClassDeclarationWithOptionalName | TSESTree.ClassExpression;
245
+ declare const isMethodOrProperty: (node: TSESTree.Node | null | undefined) => node is TSESTree.MethodDefinitionComputedName | TSESTree.MethodDefinitionNonComputedName | TSESTree.PropertyDefinitionComputedName | TSESTree.PropertyDefinitionNonComputedName;
246
+ declare const isProperty: (node: TSESTree.Node | null | undefined) => node is TSESTree.PropertyDefinitionComputedName | TSESTree.PropertyDefinitionNonComputedName | TSESTree.TSIndexSignature | TSESTree.TSParameterProperty | TSESTree.TSPropertySignatureComputedName | TSESTree.TSPropertySignatureNonComputedName;
247
+ declare const isJSXElement: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXElement;
248
+ declare const isJSXFragment: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXFragment;
249
+ declare const isJSXTagNameExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXIdentifier | TSESTree.JSXMemberExpression | TSESTree.JSXNamespacedName;
250
+ declare const isJSX: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXAttribute | TSESTree.JSXClosingElement | TSESTree.JSXClosingFragment | TSESTree.JSXElement | TSESTree.JSXEmptyExpression | TSESTree.JSXExpressionContainer | TSESTree.JSXFragment | TSESTree.JSXIdentifier | TSESTree.JSXMemberExpression | TSESTree.JSXNamespacedName | TSESTree.JSXOpeningElement | TSESTree.JSXOpeningFragment | TSESTree.JSXSpreadAttribute | TSESTree.JSXSpreadChild | TSESTree.JSXText;
251
+ declare const isLoop: (node: TSESTree.Node | null | undefined) => node is TSESTree.DoWhileStatement | TSESTree.ForInStatement | TSESTree.ForOfStatement | TSESTree.ForStatement | TSESTree.WhileStatement;
252
+ declare const isTypeExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSAsExpression | TSESTree.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
253
+ declare const isTypeAssertionExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSAsExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
254
+
261
255
  /**
262
256
  * Check if the given node is a member expression that accesses `process.env.NODE_ENV`
263
257
  * @param node The AST node
264
258
  * @returns True if the node is a member expression that accesses `process.env.NODE_ENV`, false otherwise
265
259
  */
266
- declare function isProcessEnvNodeEnv(node: TSESTree.Node | null | _): node is TSESTree.MemberExpression;
260
+ declare function isProcessEnvNodeEnv(node: TSESTree.Node | null | unit): node is TSESTree.MemberExpression;
267
261
  /**
268
262
  * Check if the given node is a binary expression that compares `process.env.NODE_ENV` with a string literal
269
263
  * @param node The AST node
@@ -271,19 +265,10 @@ declare function isProcessEnvNodeEnv(node: TSESTree.Node | null | _): node is TS
271
265
  * @param value The string literal value to compare against
272
266
  * @returns True if the node is a binary expression that compares `process.env.NODE_ENV` with the specified value, false otherwise
273
267
  */
274
- declare function isProcessEnvNodeEnvCompare(node: TSESTree.Node | null | _, operator: "===" | "!==", value: "development" | "production"): node is TSESTree.BinaryExpression;
268
+ declare function isProcessEnvNodeEnvCompare(node: TSESTree.Node | null | unit, operator: "===" | "!==", value: "development" | "production"): node is TSESTree.BinaryExpression;
275
269
 
276
- declare function getPropertyName(node: TSESTree.Node): string | _;
270
+ declare function getPropertyName(node: TSESTree.Node): string | unit;
277
271
 
278
272
  declare function isThenCall(node: TSESTree.CallExpression): boolean;
279
273
 
280
- declare function toDelimiterCaseType(node: TSESTree.Node, delimiter?: string): "RegExp literal" | Lowercase<string> | `JSX ${Lowercase<string>}`;
281
- /**
282
- * Returns human readable node name for given AST node
283
- * @param node AST node
284
- * @param getText A function that returns the text of the node in the source code
285
- * @returns Human readable node name
286
- */
287
- declare function toString(node: TSESTree.Node, getText: (node: TSESTree.Node) => string): string;
288
-
289
- export { type FunctionInitPath, type TSESTreeArrayTupleType, type TSESTreeClass, type TSESTreeDestructuringPattern, type TSESTreeFunction, type TSESTreeFunctionType, type TSESTreeJSX, type TSESTreeLoop, type TSESTreeMethodOrProperty, type TSESTreeProperty, type TSESTreeTypeAssertionExpression, type TSESTreeTypeDeclaration, type TSESTreeTypeExpression, 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 };
274
+ export { type FunctionInitPath, type TSESTreeArrayTupleType, type TSESTreeClass, type TSESTreeDestructuringPattern, type TSESTreeFunction, type TSESTreeFunctionType, type TSESTreeJSX, type TSESTreeLoop, type TSESTreeMethodOrProperty, type TSESTreeProperty, type TSESTreeTypeAssertionExpression, type TSESTreeTypeDeclaration, type TSESTreeTypeExpression, findParentNode, getArrayMethodCallbackIndexParamPosition, getClassId, getFunctionId, getFunctionInitPath, getJSExpression, getNestedCallExpressions, getNestedExpressionsOfType, getNestedIdentifiers, getNestedNewExpressions, getNestedReturnStatements, getPropertyName, hasCallInFunctionInitPath, is, isArrayFromCall, isArrayMapCall, isClass, isEmptyFunction, isFunction, isFunctionType, isImmediatelyInvokedFunction, isJSX, isJSXElement, isJSXFragment, isJSXTagNameExpression, isLineBreak, isLiteral, isLoop, isMethodOrProperty, isMultiLine, isNodeEqual, isOneOf, isProcessEnvNodeEnv, isProcessEnvNodeEnvCompare, isProperty, isThenCall, isThisExpression, isTypeAssertionExpression, isTypeExpression, toDelimiterFormat, toStringFormat };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { AST_NODE_TYPES } from '@typescript-eslint/types';
2
- import { or, dual, _ } from '@eslint-react/eff';
2
+ import { dual, unit } from '@eslint-react/eff';
3
3
  import { ASTUtils } from '@typescript-eslint/utils';
4
4
  import { simpleTraverse } from '@typescript-eslint/typescript-estree';
5
5
  import { toLowerCase, delimiterCase, replace } from 'string-ts';
@@ -38,19 +38,12 @@ var indexParamPosition = /* @__PURE__ */ new Map([
38
38
  function getArrayMethodCallbackIndexParamPosition(methodName) {
39
39
  return indexParamPosition.get(methodName) ?? -1;
40
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
- }
48
41
  function getClassId(node) {
49
42
  if (node.id != null) return node.id;
50
43
  if (node.parent.type === AST_NODE_TYPES.VariableDeclarator && node.parent.id.type === AST_NODE_TYPES.Identifier) {
51
44
  return node.parent.id;
52
45
  }
53
- return _;
46
+ return unit;
54
47
  }
55
48
  var is = ASTUtils.isNodeOfType;
56
49
  var isOneOf = ASTUtils.isNodeOfTypes;
@@ -75,28 +68,6 @@ var isMethodOrProperty = isOneOf([
75
68
  AST_NODE_TYPES.PropertyDefinition,
76
69
  AST_NODE_TYPES.MethodDefinition
77
70
  ]);
78
- var isLoop = isOneOf([
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
84
- ]);
85
- var isControlFlow = or(
86
- isLoop,
87
- isOneOf([
88
- AST_NODE_TYPES.IfStatement,
89
- AST_NODE_TYPES.SwitchStatement
90
- ])
91
- );
92
- var isConditional = or(
93
- isControlFlow,
94
- isOneOf([
95
- AST_NODE_TYPES.LogicalExpression,
96
- AST_NODE_TYPES.ConditionalExpression
97
- ])
98
- );
99
- var isArrayTupleType = isOneOf([AST_NODE_TYPES.TSArrayType, AST_NODE_TYPES.TSTupleType]);
100
71
  var isProperty = isOneOf([
101
72
  AST_NODE_TYPES.PropertyDefinition,
102
73
  AST_NODE_TYPES.TSIndexSignature,
@@ -127,60 +98,12 @@ var isJSX = isOneOf([
127
98
  AST_NODE_TYPES.JSXSpreadChild,
128
99
  AST_NODE_TYPES.JSXText
129
100
  ]);
130
- var isDestructuringPattern = isOneOf([
131
- AST_NODE_TYPES.ArrayPattern,
132
- AST_NODE_TYPES.AssignmentPattern,
133
- AST_NODE_TYPES.ObjectPattern,
134
- AST_NODE_TYPES.RestElement
135
- ]);
136
- var isTypeDeclaration = isOneOf([
137
- AST_NODE_TYPES.TSInterfaceDeclaration,
138
- AST_NODE_TYPES.TSTypeAliasDeclaration
139
- ]);
140
- var isLeftHandSideExpression = isOneOf([
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
160
- ]);
161
- var isLeftHandSideExpressionType = isOneOf([
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
101
+ var isLoop = isOneOf([
102
+ AST_NODE_TYPES.DoWhileStatement,
103
+ AST_NODE_TYPES.ForInStatement,
104
+ AST_NODE_TYPES.ForOfStatement,
105
+ AST_NODE_TYPES.ForStatement,
106
+ AST_NODE_TYPES.WhileStatement
184
107
  ]);
185
108
  var isTypeExpression = isOneOf([
186
109
  AST_NODE_TYPES.TSAsExpression,
@@ -237,7 +160,7 @@ function getFunctionId(node) {
237
160
  case isTypeAssertionExpression(node.parent):
238
161
  return getFunctionId(node.parent);
239
162
  }
240
- return _;
163
+ return unit;
241
164
  }
242
165
  function getFunctionInitPath(node) {
243
166
  if (node.type === AST_NODE_TYPES.FunctionDeclaration) {
@@ -258,7 +181,7 @@ function getFunctionInitPath(node) {
258
181
  case (parent.type === AST_NODE_TYPES.PropertyDefinition && parent.parent.parent.type === AST_NODE_TYPES.ClassDeclaration):
259
182
  return [parent.parent.parent, parent.parent, parent, node];
260
183
  }
261
- return _;
184
+ return unit;
262
185
  }
263
186
  function hasCallInFunctionInitPath(callName, initPath) {
264
187
  return initPath.some((n) => {
@@ -282,7 +205,7 @@ function isImmediatelyInvokedFunction(node) {
282
205
  return node.type !== AST_NODE_TYPES.FunctionDeclaration && node.parent.type === AST_NODE_TYPES.CallExpression && node.parent.callee === node;
283
206
  }
284
207
  function findParentNode(node, test) {
285
- if (node == null) return _;
208
+ if (node == null) return unit;
286
209
  let parent = node.parent;
287
210
  while (parent != null && parent.type !== AST_NODE_TYPES.Program) {
288
211
  if (test(parent)) {
@@ -290,7 +213,7 @@ function findParentNode(node, test) {
290
213
  }
291
214
  parent = parent.parent;
292
215
  }
293
- return _;
216
+ return unit;
294
217
  }
295
218
  function getNestedIdentifiers(node) {
296
219
  const identifiers = [];
@@ -530,44 +453,11 @@ var isNodeEqual = dual(2, (a, b) => {
530
453
  return false;
531
454
  }
532
455
  });
533
- function isProcessEnvNodeEnv(node) {
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";
535
- }
536
- function isProcessEnvNodeEnvCompare(node, operator, value) {
537
- if (node == null) return false;
538
- if (node.type !== AST_NODE_TYPES.BinaryExpression) return false;
539
- if (node.operator !== operator) return false;
540
- if (isProcessEnvNodeEnv(node.left) && isLiteral(node.right, "string")) {
541
- return node.right.value === value;
542
- }
543
- if (isLiteral(node.left, "string") && isProcessEnvNodeEnv(node.right)) {
544
- return node.left.value === value;
545
- }
546
- return false;
547
- }
548
- function getPropertyName(node) {
549
- if (isTypeExpression(node)) {
550
- return getPropertyName(getJSExpression(node));
551
- }
552
- if (node.type === AST_NODE_TYPES.Identifier || node.type === AST_NODE_TYPES.PrivateIdentifier) {
553
- return node.name;
554
- }
555
- if (node.type === AST_NODE_TYPES.Literal) {
556
- return String(node.value);
557
- }
558
- if (node.type === AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) {
559
- return node.quasis[0]?.value.raw;
560
- }
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";
565
- }
566
456
  function getLiteralValueType(input) {
567
457
  if (input === null) return "null";
568
458
  return typeof input;
569
459
  }
570
- function toDelimiterCaseType(node, delimiter = " ") {
460
+ function toDelimiterFormat(node, delimiter = " ") {
571
461
  if (node.type === AST_NODE_TYPES.Literal) {
572
462
  if ("regex" in node) {
573
463
  return "RegExp literal";
@@ -579,7 +469,7 @@ function toDelimiterCaseType(node, delimiter = " ") {
579
469
  }
580
470
  return toLowerCase(delimiterCase(node.type, delimiter));
581
471
  }
582
- function toString(node, getText) {
472
+ function toStringFormat(node, getText) {
583
473
  switch (node.type) {
584
474
  case AST_NODE_TYPES.Identifier:
585
475
  case AST_NODE_TYPES.JSXIdentifier:
@@ -587,7 +477,7 @@ function toString(node, getText) {
587
477
  return node.name;
588
478
  case AST_NODE_TYPES.MemberExpression:
589
479
  case AST_NODE_TYPES.JSXMemberExpression:
590
- return `${toString(node.object, getText)}.${toString(node.property, getText)}`;
480
+ return `${toStringFormat(node.object, getText)}.${toStringFormat(node.property, getText)}`;
591
481
  case AST_NODE_TYPES.JSXNamespacedName:
592
482
  return `${node.namespace.name}:${node.name.name}`;
593
483
  case AST_NODE_TYPES.JSXText:
@@ -598,5 +488,38 @@ function toString(node, getText) {
598
488
  return getText(node);
599
489
  }
600
490
  }
491
+ function isProcessEnvNodeEnv(node) {
492
+ 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";
493
+ }
494
+ function isProcessEnvNodeEnvCompare(node, operator, value) {
495
+ if (node == null) return false;
496
+ if (node.type !== AST_NODE_TYPES.BinaryExpression) return false;
497
+ if (node.operator !== operator) return false;
498
+ if (isProcessEnvNodeEnv(node.left) && isLiteral(node.right, "string")) {
499
+ return node.right.value === value;
500
+ }
501
+ if (isLiteral(node.left, "string") && isProcessEnvNodeEnv(node.right)) {
502
+ return node.left.value === value;
503
+ }
504
+ return false;
505
+ }
506
+ function getPropertyName(node) {
507
+ if (isTypeExpression(node)) {
508
+ return getPropertyName(getJSExpression(node));
509
+ }
510
+ if (node.type === AST_NODE_TYPES.Identifier || node.type === AST_NODE_TYPES.PrivateIdentifier) {
511
+ return node.name;
512
+ }
513
+ if (node.type === AST_NODE_TYPES.Literal) {
514
+ return String(node.value);
515
+ }
516
+ if (node.type === AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) {
517
+ return node.quasis[0]?.value.raw;
518
+ }
519
+ return unit;
520
+ }
521
+ function isThenCall(node) {
522
+ return node.callee.type === AST_NODE_TYPES.MemberExpression && node.callee.property.type === AST_NODE_TYPES.Identifier && node.callee.property.name === "then";
523
+ }
601
524
 
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 };
525
+ export { findParentNode, getArrayMethodCallbackIndexParamPosition, getClassId, getFunctionId, getFunctionInitPath, getJSExpression, getNestedCallExpressions, getNestedExpressionsOfType, getNestedIdentifiers, getNestedNewExpressions, getNestedReturnStatements, getPropertyName, hasCallInFunctionInitPath, is, isArrayFromCall, isArrayMapCall, isClass, isEmptyFunction, isFunction, isFunctionType, isImmediatelyInvokedFunction, isJSX, isJSXElement, isJSXFragment, isJSXTagNameExpression, isLineBreak, isLiteral, isLoop, isMethodOrProperty, isMultiLine, isNodeEqual, isOneOf, isProcessEnvNodeEnv, isProcessEnvNodeEnvCompare, isProperty, isThenCall, isThisExpression, isTypeAssertionExpression, isTypeExpression, toDelimiterFormat, toStringFormat };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/ast",
3
- "version": "2.0.0-next.10",
3
+ "version": "2.0.0-next.109",
4
4
  "description": "ESLint React's TSESTree AST utility module.",
5
5
  "homepage": "https://github.com/Rel1cx/eslint-react",
6
6
  "bugs": {
@@ -27,19 +27,18 @@
27
27
  "./package.json"
28
28
  ],
29
29
  "dependencies": {
30
- "@typescript-eslint/types": "^8.31.1",
31
- "@typescript-eslint/typescript-estree": "^8.31.1",
32
- "@typescript-eslint/utils": "^8.31.1",
30
+ "@typescript-eslint/types": "^8.38.0",
31
+ "@typescript-eslint/typescript-estree": "^8.38.0",
32
+ "@typescript-eslint/utils": "^8.38.0",
33
33
  "string-ts": "^2.2.1",
34
- "ts-pattern": "^5.7.0",
35
- "@eslint-react/eff": "2.0.0-next.10"
34
+ "ts-pattern": "^5.8.0",
35
+ "@eslint-react/eff": "2.0.0-next.109"
36
36
  },
37
37
  "devDependencies": {
38
- "tsup": "^8.4.0",
38
+ "tsup": "^8.5.0",
39
39
  "@local/configs": "0.0.0"
40
40
  },
41
41
  "engines": {
42
- "bun": ">=1.0.15",
43
42
  "node": ">=20.19.0"
44
43
  },
45
44
  "scripts": {