@eslint-react/ast 2.0.0-next.1 → 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,6 +1,6 @@
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;
@@ -20,12 +20,7 @@ type TSESTreeTypeDeclaration = TSESTree$1.TSInterfaceDeclaration | TSESTree$1.TS
20
20
  type TSESTreeTypeExpression = TSESTree$1.TSAsExpression | TSESTree$1.TSNonNullExpression | TSESTree$1.TSSatisfiesExpression | TSESTree$1.TSTypeAssertion | TSESTree$1.TSInstantiationExpression;
21
21
  type TSESTreeTypeAssertionExpression = TSESTree$1.TSAsExpression | TSESTree$1.TSNonNullExpression | TSESTree$1.TSSatisfiesExpression | TSESTree$1.TSTypeAssertion;
22
22
 
23
- /**
24
- * Gets class identifier from ClassDeclaration or ClassExpression
25
- * @param node The AST node to check
26
- * @returns class identifier or null
27
- */
28
- declare function getClassId(node: TSESTreeClass): TSESTree.Identifier | _;
23
+ declare function getClassId(node: TSESTreeClass): TSESTree.Identifier | unit;
29
24
 
30
25
  /**
31
26
  * Recursively get the inner expression until it's not a TypeExpression
@@ -42,8 +37,7 @@ declare function isThisExpression(node: TSESTree.Expression): boolean;
42
37
  * where JS gives anonymous function expressions names. We roughly detect the
43
38
  * same AST nodes with some exceptions to better fit our use case.
44
39
  */
45
-
46
- declare function getFunctionId(node: TSESTree.Expression | TSESTreeFunction): TSESTree.Identifier | _;
40
+ declare function getFunctionId(node: TSESTree.Expression | TSESTreeFunction): TSESTree.Identifier | unit;
47
41
 
48
42
  type FunctionInitPath =
49
43
  /**
@@ -143,10 +137,11 @@ readonly [TSESTree.FunctionDeclaration]
143
137
  TSESTree.PropertyDefinition,
144
138
  TSESTreeFunction
145
139
  ];
146
- declare function getFunctionInitPath(node: TSESTreeFunction): FunctionInitPath | _;
140
+ declare function getFunctionInitPath(node: TSESTreeFunction): unit | FunctionInitPath;
147
141
  declare function hasCallInFunctionInitPath(callName: string, initPath: FunctionInitPath): boolean;
148
142
 
149
143
  declare function isEmptyFunction(node: TSESTreeFunction): boolean;
144
+ declare function isImmediatelyInvokedFunction(node: TSESTreeFunction): boolean;
150
145
 
151
146
  /**
152
147
  * Find the parent node that satisfies the test function
@@ -154,14 +149,14 @@ declare function isEmptyFunction(node: TSESTreeFunction): boolean;
154
149
  * @param test The test function
155
150
  * @returns The parent node that satisfies the test function or `_` if not found
156
151
  */
157
- 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;
158
153
  /**
159
154
  * Find the parent node that satisfies the test function or `_` if not found
160
155
  * @param node The AST node
161
156
  * @param test The test function
162
157
  * @returns The parent node that satisfies the test function
163
158
  */
164
- 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;
165
160
 
166
161
  /**
167
162
  * Get all nested identifiers in a expression like node
@@ -197,32 +192,6 @@ declare const getNestedNewExpressions: (node: TSESTree.Node) => TSESTree.NewExpr
197
192
  */
198
193
  declare const getNestedCallExpressions: (node: TSESTree.Node) => TSESTree.CallExpression[];
199
194
 
200
- declare const is: <NodeType extends TSESTree.AST_NODE_TYPES>(nodeType: NodeType) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
201
- type: NodeType;
202
- }>;
203
- declare const isOneOf: <NodeTypes extends readonly TSESTree.AST_NODE_TYPES[]>(nodeTypes: NodeTypes) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
204
- type: NodeTypes[number];
205
- }>;
206
- declare const isFunction: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression;
207
- 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;
208
- declare const isClass: (node: TSESTree.Node | null | undefined) => node is TSESTree.ClassDeclarationWithName | TSESTree.ClassDeclarationWithOptionalName | TSESTree.ClassExpression;
209
- declare const isMethodOrProperty: (node: TSESTree.Node | null | undefined) => node is TSESTree.MethodDefinitionComputedName | TSESTree.MethodDefinitionNonComputedName | TSESTree.PropertyDefinitionComputedName | TSESTree.PropertyDefinitionNonComputedName;
210
- declare const isLoop: (node: TSESTree.Node | null | undefined) => node is TSESTree.DoWhileStatement | TSESTree.ForInStatement | TSESTree.ForOfStatement | TSESTree.ForStatement | TSESTree.WhileStatement;
211
- declare const isControlFlow: (data: TSESTree.Node | null | undefined) => data is TSESTree.DoWhileStatement | TSESTree.ForInStatement | TSESTree.ForOfStatement | TSESTree.ForStatement | TSESTree.IfStatement | TSESTree.SwitchStatement | TSESTree.WhileStatement;
212
- 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;
213
- declare const isArrayTupleType: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSArrayType | TSESTree.TSTupleType;
214
- declare const isProperty: (node: TSESTree.Node | null | undefined) => node is TSESTree.PropertyDefinitionComputedName | TSESTree.PropertyDefinitionNonComputedName | TSESTree.TSIndexSignature | TSESTree.TSParameterProperty | TSESTree.TSPropertySignatureComputedName | TSESTree.TSPropertySignatureNonComputedName;
215
- declare const isJSXElement: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXElement;
216
- declare const isJSXFragment: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXFragment;
217
- declare const isJSXTagNameExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXIdentifier | TSESTree.JSXMemberExpression | TSESTree.JSXNamespacedName;
218
- 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;
219
- declare const isDestructuringPattern: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrayPattern | TSESTree.AssignmentPattern | TSESTree.ObjectPattern | TSESTree.RestElement;
220
- declare const isTypeDeclaration: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSInterfaceDeclaration | TSESTree.TSTypeAliasDeclaration;
221
- 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;
222
- 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;
223
- declare const isTypeExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSAsExpression | TSESTree.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
224
- declare const isTypeAssertionExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSAsExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
225
-
226
195
  /**
227
196
  * Check if a node is multiline
228
197
  * @param node The AST node to check
@@ -255,12 +224,40 @@ declare const isNodeEqual: {
255
224
  (a: TSESTree.Node, b: TSESTree.Node): boolean;
256
225
  };
257
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
+
258
255
  /**
259
256
  * Check if the given node is a member expression that accesses `process.env.NODE_ENV`
260
257
  * @param node The AST node
261
258
  * @returns True if the node is a member expression that accesses `process.env.NODE_ENV`, false otherwise
262
259
  */
263
- declare function isProcessEnvNodeEnv(node: TSESTree.Node | null | _): node is TSESTree.MemberExpression;
260
+ declare function isProcessEnvNodeEnv(node: TSESTree.Node | null | unit): node is TSESTree.MemberExpression;
264
261
  /**
265
262
  * Check if the given node is a binary expression that compares `process.env.NODE_ENV` with a string literal
266
263
  * @param node The AST node
@@ -268,17 +265,10 @@ declare function isProcessEnvNodeEnv(node: TSESTree.Node | null | _): node is TS
268
265
  * @param value The string literal value to compare against
269
266
  * @returns True if the node is a binary expression that compares `process.env.NODE_ENV` with the specified value, false otherwise
270
267
  */
271
- 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;
272
269
 
273
- declare function getPropertyName(node: TSESTree.Node): string | _;
270
+ declare function getPropertyName(node: TSESTree.Node): string | unit;
274
271
 
275
- declare function toDelimiterCaseType(node: TSESTree.Node, delimiter?: string): "RegExp literal" | Lowercase<string> | `JSX ${Lowercase<string>}`;
276
- /**
277
- * Returns human readable node name for given AST node
278
- * @param node AST node
279
- * @param getText A function that returns the text of the node in the source code
280
- * @returns Human readable node name
281
- */
282
- declare function toString(node: TSESTree.Node, getText: (node: TSESTree.Node) => string): string;
272
+ declare function isThenCall(node: TSESTree.CallExpression): boolean;
283
273
 
284
- 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, isArrayTupleType, isClass, isConditional, isControlFlow, isDestructuringPattern, isEmptyFunction, isFunction, isFunctionType, isJSX, isJSXElement, isJSXFragment, isJSXTagNameExpression, isLeftHandSideExpression, isLeftHandSideExpressionType, isLineBreak, isLiteral, isLoop, isMethodOrProperty, isMultiLine, isNodeEqual, isOneOf, isProcessEnvNodeEnv, isProcessEnvNodeEnvCompare, isProperty, 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';
@@ -43,7 +43,7 @@ function getClassId(node) {
43
43
  if (node.parent.type === AST_NODE_TYPES.VariableDeclarator && node.parent.id.type === AST_NODE_TYPES.Identifier) {
44
44
  return node.parent.id;
45
45
  }
46
- return _;
46
+ return unit;
47
47
  }
48
48
  var is = ASTUtils.isNodeOfType;
49
49
  var isOneOf = ASTUtils.isNodeOfTypes;
@@ -68,28 +68,6 @@ var isMethodOrProperty = isOneOf([
68
68
  AST_NODE_TYPES.PropertyDefinition,
69
69
  AST_NODE_TYPES.MethodDefinition
70
70
  ]);
71
- var isLoop = isOneOf([
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
77
- ]);
78
- var isControlFlow = or(
79
- isLoop,
80
- isOneOf([
81
- AST_NODE_TYPES.IfStatement,
82
- AST_NODE_TYPES.SwitchStatement
83
- ])
84
- );
85
- var isConditional = or(
86
- isControlFlow,
87
- isOneOf([
88
- AST_NODE_TYPES.LogicalExpression,
89
- AST_NODE_TYPES.ConditionalExpression
90
- ])
91
- );
92
- var isArrayTupleType = isOneOf([AST_NODE_TYPES.TSArrayType, AST_NODE_TYPES.TSTupleType]);
93
71
  var isProperty = isOneOf([
94
72
  AST_NODE_TYPES.PropertyDefinition,
95
73
  AST_NODE_TYPES.TSIndexSignature,
@@ -120,60 +98,12 @@ var isJSX = isOneOf([
120
98
  AST_NODE_TYPES.JSXSpreadChild,
121
99
  AST_NODE_TYPES.JSXText
122
100
  ]);
123
- var isDestructuringPattern = isOneOf([
124
- AST_NODE_TYPES.ArrayPattern,
125
- AST_NODE_TYPES.AssignmentPattern,
126
- AST_NODE_TYPES.ObjectPattern,
127
- AST_NODE_TYPES.RestElement
128
- ]);
129
- var isTypeDeclaration = isOneOf([
130
- AST_NODE_TYPES.TSInterfaceDeclaration,
131
- AST_NODE_TYPES.TSTypeAliasDeclaration
132
- ]);
133
- var isLeftHandSideExpression = isOneOf([
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
153
- ]);
154
- var isLeftHandSideExpressionType = isOneOf([
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
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
177
107
  ]);
178
108
  var isTypeExpression = isOneOf([
179
109
  AST_NODE_TYPES.TSAsExpression,
@@ -230,7 +160,7 @@ function getFunctionId(node) {
230
160
  case isTypeAssertionExpression(node.parent):
231
161
  return getFunctionId(node.parent);
232
162
  }
233
- return _;
163
+ return unit;
234
164
  }
235
165
  function getFunctionInitPath(node) {
236
166
  if (node.type === AST_NODE_TYPES.FunctionDeclaration) {
@@ -251,7 +181,7 @@ function getFunctionInitPath(node) {
251
181
  case (parent.type === AST_NODE_TYPES.PropertyDefinition && parent.parent.parent.type === AST_NODE_TYPES.ClassDeclaration):
252
182
  return [parent.parent.parent, parent.parent, parent, node];
253
183
  }
254
- return _;
184
+ return unit;
255
185
  }
256
186
  function hasCallInFunctionInitPath(callName, initPath) {
257
187
  return initPath.some((n) => {
@@ -271,8 +201,11 @@ function hasCallInFunctionInitPath(callName, initPath) {
271
201
  function isEmptyFunction(node) {
272
202
  return node.body.type === AST_NODE_TYPES.BlockStatement && node.body.body.length === 0;
273
203
  }
204
+ function isImmediatelyInvokedFunction(node) {
205
+ return node.type !== AST_NODE_TYPES.FunctionDeclaration && node.parent.type === AST_NODE_TYPES.CallExpression && node.parent.callee === node;
206
+ }
274
207
  function findParentNode(node, test) {
275
- if (node == null) return _;
208
+ if (node == null) return unit;
276
209
  let parent = node.parent;
277
210
  while (parent != null && parent.type !== AST_NODE_TYPES.Program) {
278
211
  if (test(parent)) {
@@ -280,7 +213,7 @@ function findParentNode(node, test) {
280
213
  }
281
214
  parent = parent.parent;
282
215
  }
283
- return _;
216
+ return unit;
284
217
  }
285
218
  function getNestedIdentifiers(node) {
286
219
  const identifiers = [];
@@ -520,41 +453,11 @@ var isNodeEqual = dual(2, (a, b) => {
520
453
  return false;
521
454
  }
522
455
  });
523
- function isProcessEnvNodeEnv(node) {
524
- 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";
525
- }
526
- function isProcessEnvNodeEnvCompare(node, operator, value) {
527
- if (node == null) return false;
528
- if (node.type !== AST_NODE_TYPES.BinaryExpression) return false;
529
- if (node.operator !== operator) return false;
530
- if (isProcessEnvNodeEnv(node.left) && isLiteral(node.right, "string")) {
531
- return node.right.value === value;
532
- }
533
- if (isLiteral(node.left, "string") && isProcessEnvNodeEnv(node.right)) {
534
- return node.left.value === value;
535
- }
536
- return false;
537
- }
538
- function getPropertyName(node) {
539
- if (isTypeExpression(node)) {
540
- return getPropertyName(getJSExpression(node));
541
- }
542
- if (node.type === AST_NODE_TYPES.Identifier || node.type === AST_NODE_TYPES.PrivateIdentifier) {
543
- return node.name;
544
- }
545
- if (node.type === AST_NODE_TYPES.Literal) {
546
- return String(node.value);
547
- }
548
- if (node.type === AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) {
549
- return node.quasis[0]?.value.raw;
550
- }
551
- return _;
552
- }
553
456
  function getLiteralValueType(input) {
554
457
  if (input === null) return "null";
555
458
  return typeof input;
556
459
  }
557
- function toDelimiterCaseType(node, delimiter = " ") {
460
+ function toDelimiterFormat(node, delimiter = " ") {
558
461
  if (node.type === AST_NODE_TYPES.Literal) {
559
462
  if ("regex" in node) {
560
463
  return "RegExp literal";
@@ -566,7 +469,7 @@ function toDelimiterCaseType(node, delimiter = " ") {
566
469
  }
567
470
  return toLowerCase(delimiterCase(node.type, delimiter));
568
471
  }
569
- function toString(node, getText) {
472
+ function toStringFormat(node, getText) {
570
473
  switch (node.type) {
571
474
  case AST_NODE_TYPES.Identifier:
572
475
  case AST_NODE_TYPES.JSXIdentifier:
@@ -574,7 +477,7 @@ function toString(node, getText) {
574
477
  return node.name;
575
478
  case AST_NODE_TYPES.MemberExpression:
576
479
  case AST_NODE_TYPES.JSXMemberExpression:
577
- return `${toString(node.object, getText)}.${toString(node.property, getText)}`;
480
+ return `${toStringFormat(node.object, getText)}.${toStringFormat(node.property, getText)}`;
578
481
  case AST_NODE_TYPES.JSXNamespacedName:
579
482
  return `${node.namespace.name}:${node.name.name}`;
580
483
  case AST_NODE_TYPES.JSXText:
@@ -585,5 +488,38 @@ function toString(node, getText) {
585
488
  return getText(node);
586
489
  }
587
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
+ }
588
524
 
589
- 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, isJSX, isJSXElement, isJSXFragment, isJSXTagNameExpression, isLeftHandSideExpression, isLeftHandSideExpressionType, isLineBreak, isLiteral, isLoop, isMethodOrProperty, isMultiLine, isNodeEqual, isOneOf, isProcessEnvNodeEnv, isProcessEnvNodeEnvCompare, isProperty, 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.1",
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.30.1",
31
- "@typescript-eslint/typescript-estree": "^8.30.1",
32
- "@typescript-eslint/utils": "^8.30.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.1"
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": {