@eslint-react/ast 2.0.0-next.186 → 2.0.0-next.188

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
@@ -41,15 +41,15 @@ declare const is: <NodeType extends TSESTree.AST_NODE_TYPES>(nodeType: NodeType)
41
41
  declare const isOneOf: <NodeTypes extends readonly TSESTree.AST_NODE_TYPES[]>(nodeTypes: NodeTypes) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
42
42
  type: NodeTypes[number];
43
43
  }>;
44
- declare const isFunction: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrowFunctionExpression | TSESTree.FunctionExpression | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName;
45
- declare const isFunctionType: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrowFunctionExpression | TSESTree.FunctionExpression | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.TSCallSignatureDeclaration | TSESTree.TSConstructSignatureDeclaration | TSESTree.TSDeclareFunctionNoDeclare | TSESTree.TSDeclareFunctionWithDeclare | TSESTree.TSEmptyBodyFunctionExpression | TSESTree.TSFunctionType | TSESTree.TSMethodSignatureComputedName | TSESTree.TSMethodSignatureNonComputedName;
46
- declare const isClass: (node: TSESTree.Node | null | undefined) => node is TSESTree.ClassExpression | TSESTree.ClassDeclarationWithName | TSESTree.ClassDeclarationWithOptionalName;
44
+ declare const isFunction: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression;
45
+ 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;
46
+ declare const isClass: (node: TSESTree.Node | null | undefined) => node is TSESTree.ClassDeclarationWithName | TSESTree.ClassDeclarationWithOptionalName | TSESTree.ClassExpression;
47
47
  declare const isMethodOrProperty: (node: TSESTree.Node | null | undefined) => node is TSESTree.MethodDefinitionComputedName | TSESTree.MethodDefinitionNonComputedName | TSESTree.PropertyDefinitionComputedName | TSESTree.PropertyDefinitionNonComputedName;
48
48
  declare const isProperty: (node: TSESTree.Node | null | undefined) => node is TSESTree.PropertyDefinitionComputedName | TSESTree.PropertyDefinitionNonComputedName | TSESTree.TSIndexSignature | TSESTree.TSParameterProperty | TSESTree.TSPropertySignatureComputedName | TSESTree.TSPropertySignatureNonComputedName;
49
49
  declare const isJSXElement: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXElement;
50
50
  declare const isJSXFragment: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXFragment;
51
51
  declare const isJSXTagNameExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXIdentifier | TSESTree.JSXMemberExpression | TSESTree.JSXNamespacedName;
52
- declare const isJSX: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXElement | TSESTree.JSXFragment | TSESTree.JSXAttribute | TSESTree.JSXClosingElement | TSESTree.JSXClosingFragment | TSESTree.JSXEmptyExpression | TSESTree.JSXExpressionContainer | TSESTree.JSXIdentifier | TSESTree.JSXMemberExpression | TSESTree.JSXNamespacedName | TSESTree.JSXOpeningElement | TSESTree.JSXOpeningFragment | TSESTree.JSXSpreadAttribute | TSESTree.JSXSpreadChild | TSESTree.JSXText;
52
+ 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;
53
53
  declare const isLoop: (node: TSESTree.Node | null | undefined) => node is TSESTree.DoWhileStatement | TSESTree.ForInStatement | TSESTree.ForOfStatement | TSESTree.ForStatement | TSESTree.WhileStatement;
54
54
  declare const isTypeExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSAsExpression | TSESTree.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
55
55
  declare const isTypeAssertionExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSAsExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
@@ -187,6 +187,44 @@ declare function isMultiLine(node: TSESTree.Node): boolean;
187
187
  */
188
188
  declare function isLineBreak(node: TSESTree.Node): boolean;
189
189
  //#endregion
190
+ //#region src/node-selectors.d.ts
191
+ type ImplicitReturnArrowFunctionExpression = TSESTree$1.ArrowFunctionExpression & {
192
+ body: TSESTree$1.Expression;
193
+ };
194
+ type ObjectDestructuringVariableDeclarator = TSESTree$1.VariableDeclarator & {
195
+ id: TSESTree$1.ObjectPattern;
196
+ init: TSESTree$1.Identifier;
197
+ };
198
+ type DisplayNameAssignmentExpression = TSESTree$1.AssignmentExpression & {
199
+ type: "AssignmentExpression";
200
+ left: TSESTree$1.MemberExpression & {
201
+ property: TSESTree$1.Identifier & {
202
+ name: "displayName";
203
+ };
204
+ };
205
+ operator: "=";
206
+ right: TSESTree$1.Literal;
207
+ };
208
+ declare const SEL_IMPLICIT_RETURN_ARROW_FUNCTION_EXPRESSION = "ArrowFunctionExpression[body.type!='BlockStatement']";
209
+ declare const SEL_OBJECT_DESTRUCTURING_VARIABLE_DECLARATOR: string;
210
+ declare const SEL_DISPLAY_NAME_ASSIGNMENT_EXPRESSION: string;
211
+ //#endregion
212
+ //#region src/process-env-node-env.d.ts
213
+ /**
214
+ * Check if the given node is a member expression that accesses `process.env.NODE_ENV`
215
+ * @param node The AST node
216
+ * @returns True if the node is a member expression that accesses `process.env.NODE_ENV`, false otherwise
217
+ */
218
+ declare function isProcessEnvNodeEnv(node: TSESTree.Node | null | unit): node is TSESTree.MemberExpression;
219
+ /**
220
+ * Check if the given node is a binary expression that compares `process.env.NODE_ENV` with a string literal.
221
+ * @param node The AST node
222
+ * @param operator The operator used in the comparison
223
+ * @param value The string literal value to compare against
224
+ * @returns True if the node is a binary expression that compares `process.env.NODE_ENV` with the specified value, false otherwise
225
+ */
226
+ declare function isProcessEnvNodeEnvCompare(node: TSESTree.Node | null | unit, operator: "===" | "!==", value: "development" | "production"): node is TSESTree.BinaryExpression;
227
+ //#endregion
190
228
  //#region src/promise-then.d.ts
191
229
  declare function isThenCall(node: TSESTree.CallExpression): boolean;
192
230
  //#endregion
@@ -209,4 +247,20 @@ declare function findParentNode<A extends TSESTree.Node>(node: TSESTree.Node | u
209
247
  */
210
248
  declare function findParentNode(node: TSESTree.Node | unit, test: (node: TSESTree.Node) => boolean): TSESTree.Node | unit;
211
249
  //#endregion
212
- export { FunctionInitPath, TSESTreeArrayTupleType, TSESTreeClass, TSESTreeDestructuringPattern, TSESTreeFunction, TSESTreeFunctionType, TSESTreeJSX, TSESTreeJSXAttributeLike, TSESTreeLoop, TSESTreeMethodOrProperty, TSESTreeProperty, TSESTreeTypeAssertionExpression, TSESTreeTypeDeclaration, TSESTreeTypeExpression, findParentNode, getArrayMethodCallbackIndexParamPosition, getClassId, getFunctionId, getFunctionInitPath, getNestedCallExpressions, getNestedExpressionsOfType, getNestedIdentifiers, getNestedNewExpressions, getNestedReturnStatements, getPropertyName, getUnderlyingExpression, hasCallInFunctionInitPath, is, isArrayFromCall, isArrayMapCall, isClass, isFunction, isFunctionEmpty, isFunctionImmediatelyInvoked, isFunctionType, isJSX, isJSXElement, isJSXFragment, isJSXTagNameExpression, isLineBreak, isLiteral, isLoop, isMethodOrProperty, isMultiLine, isNodeEqual, isOneOf, isProperty, isThenCall, isThisExpression, isTypeAssertionExpression, isTypeExpression, toDelimiterFormat, toStringFormat };
250
+ //#region src/vitest-mock.d.ts
251
+ /**
252
+ * Checks if the given node is a `vi.mock`.
253
+ * @param node The node to check
254
+ * @returns `true` if the node is a `vi.mock`, otherwise `false`.
255
+ * @internal
256
+ */
257
+ declare function isViMock(node: TSESTree.Node | null | unit): node is TSESTree.MemberExpression;
258
+ /**
259
+ * Checks if the given node is a `vi.mock` callback.
260
+ * @param node The node to check
261
+ * @returns `true` if the node is a `vi.mock` callback, otherwise `false`.
262
+ * @internal
263
+ */
264
+ declare function isViMockCallback(node: TSESTree.Node | null | unit): boolean;
265
+ //#endregion
266
+ export { DisplayNameAssignmentExpression, FunctionInitPath, ImplicitReturnArrowFunctionExpression, ObjectDestructuringVariableDeclarator, SEL_DISPLAY_NAME_ASSIGNMENT_EXPRESSION, SEL_IMPLICIT_RETURN_ARROW_FUNCTION_EXPRESSION, SEL_OBJECT_DESTRUCTURING_VARIABLE_DECLARATOR, TSESTreeArrayTupleType, TSESTreeClass, TSESTreeDestructuringPattern, TSESTreeFunction, TSESTreeFunctionType, TSESTreeJSX, TSESTreeJSXAttributeLike, TSESTreeLoop, TSESTreeMethodOrProperty, TSESTreeProperty, TSESTreeTypeAssertionExpression, TSESTreeTypeDeclaration, TSESTreeTypeExpression, findParentNode, getArrayMethodCallbackIndexParamPosition, getClassId, getFunctionId, getFunctionInitPath, getNestedCallExpressions, getNestedExpressionsOfType, getNestedIdentifiers, getNestedNewExpressions, getNestedReturnStatements, getPropertyName, getUnderlyingExpression, hasCallInFunctionInitPath, is, isArrayFromCall, isArrayMapCall, isClass, isFunction, isFunctionEmpty, isFunctionImmediatelyInvoked, isFunctionType, isJSX, isJSXElement, isJSXFragment, isJSXTagNameExpression, isLineBreak, isLiteral, isLoop, isMethodOrProperty, isMultiLine, isNodeEqual, isOneOf, isProcessEnvNodeEnv, isProcessEnvNodeEnvCompare, isProperty, isThenCall, isThisExpression, isTypeAssertionExpression, isTypeExpression, isViMock, isViMockCallback, toDelimiterFormat, toStringFormat };
package/dist/index.js CHANGED
@@ -553,6 +553,47 @@ function isLineBreak(node) {
553
553
  return isOneOf([AST_NODE_TYPES.Literal, AST_NODE_TYPES.JSXText])(node) && typeof node.value === "string" && node.value.trim() === "" && isMultiLine(node);
554
554
  }
555
555
 
556
+ //#endregion
557
+ //#region src/node-selectors.ts
558
+ const SEL_IMPLICIT_RETURN_ARROW_FUNCTION_EXPRESSION = "ArrowFunctionExpression[body.type!='BlockStatement']";
559
+ const SEL_OBJECT_DESTRUCTURING_VARIABLE_DECLARATOR = [
560
+ "VariableDeclarator",
561
+ "[id.type='ObjectPattern']",
562
+ "[init.type='Identifier']"
563
+ ].join("");
564
+ const SEL_DISPLAY_NAME_ASSIGNMENT_EXPRESSION = [
565
+ "AssignmentExpression",
566
+ "[operator='=']",
567
+ "[left.type='MemberExpression']",
568
+ "[left.property.name='displayName']"
569
+ ].join("");
570
+
571
+ //#endregion
572
+ //#region src/process-env-node-env.ts
573
+ /**
574
+ * Check if the given node is a member expression that accesses `process.env.NODE_ENV`
575
+ * @param node The AST node
576
+ * @returns True if the node is a member expression that accesses `process.env.NODE_ENV`, false otherwise
577
+ */
578
+ function isProcessEnvNodeEnv(node) {
579
+ 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";
580
+ }
581
+ /**
582
+ * Check if the given node is a binary expression that compares `process.env.NODE_ENV` with a string literal.
583
+ * @param node The AST node
584
+ * @param operator The operator used in the comparison
585
+ * @param value The string literal value to compare against
586
+ * @returns True if the node is a binary expression that compares `process.env.NODE_ENV` with the specified value, false otherwise
587
+ */
588
+ function isProcessEnvNodeEnvCompare(node, operator, value) {
589
+ if (node == null) return false;
590
+ if (node.type !== AST_NODE_TYPES.BinaryExpression) return false;
591
+ if (node.operator !== operator) return false;
592
+ if (isProcessEnvNodeEnv(node.left) && isLiteral(node.right, "string")) return node.right.value === value;
593
+ if (isLiteral(node.left, "string") && isProcessEnvNodeEnv(node.right)) return node.left.value === value;
594
+ return false;
595
+ }
596
+
556
597
  //#endregion
557
598
  //#region src/promise-then.ts
558
599
  function isThenCall(node) {
@@ -570,4 +611,25 @@ function getPropertyName(node) {
570
611
  }
571
612
 
572
613
  //#endregion
573
- export { findParentNode, getArrayMethodCallbackIndexParamPosition, getClassId, getFunctionId, getFunctionInitPath, getNestedCallExpressions, getNestedExpressionsOfType, getNestedIdentifiers, getNestedNewExpressions, getNestedReturnStatements, getPropertyName, getUnderlyingExpression, hasCallInFunctionInitPath, is, isArrayFromCall, isArrayMapCall, isClass, isFunction, isFunctionEmpty, isFunctionImmediatelyInvoked, isFunctionType, isJSX, isJSXElement, isJSXFragment, isJSXTagNameExpression, isLineBreak, isLiteral, isLoop, isMethodOrProperty, isMultiLine, isNodeEqual, isOneOf, isProperty, isThenCall, isThisExpression, isTypeAssertionExpression, isTypeExpression, toDelimiterFormat, toStringFormat };
614
+ //#region src/vitest-mock.ts
615
+ /**
616
+ * Checks if the given node is a `vi.mock`.
617
+ * @param node The node to check
618
+ * @returns `true` if the node is a `vi.mock`, otherwise `false`.
619
+ * @internal
620
+ */
621
+ function isViMock(node) {
622
+ return node != null && node.type === AST_NODE_TYPES.MemberExpression && node.object.type === AST_NODE_TYPES.Identifier && node.object.name === "vi" && node.property.type === AST_NODE_TYPES.Identifier && node.property.name === "mock";
623
+ }
624
+ /**
625
+ * Checks if the given node is a `vi.mock` callback.
626
+ * @param node The node to check
627
+ * @returns `true` if the node is a `vi.mock` callback, otherwise `false`.
628
+ * @internal
629
+ */
630
+ function isViMockCallback(node) {
631
+ return node != null && isFunction(node) && node.parent.type === AST_NODE_TYPES.CallExpression && isViMock(node.parent.callee) && node.parent.arguments[1] === node;
632
+ }
633
+
634
+ //#endregion
635
+ export { SEL_DISPLAY_NAME_ASSIGNMENT_EXPRESSION, SEL_IMPLICIT_RETURN_ARROW_FUNCTION_EXPRESSION, SEL_OBJECT_DESTRUCTURING_VARIABLE_DECLARATOR, findParentNode, getArrayMethodCallbackIndexParamPosition, getClassId, getFunctionId, getFunctionInitPath, getNestedCallExpressions, getNestedExpressionsOfType, getNestedIdentifiers, getNestedNewExpressions, getNestedReturnStatements, getPropertyName, getUnderlyingExpression, hasCallInFunctionInitPath, is, isArrayFromCall, isArrayMapCall, isClass, isFunction, isFunctionEmpty, isFunctionImmediatelyInvoked, isFunctionType, isJSX, isJSXElement, isJSXFragment, isJSXTagNameExpression, isLineBreak, isLiteral, isLoop, isMethodOrProperty, isMultiLine, isNodeEqual, isOneOf, isProcessEnvNodeEnv, isProcessEnvNodeEnvCompare, isProperty, isThenCall, isThisExpression, isTypeAssertionExpression, isTypeExpression, isViMock, isViMockCallback, toDelimiterFormat, toStringFormat };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/ast",
3
- "version": "2.0.0-next.186",
3
+ "version": "2.0.0-next.188",
4
4
  "description": "ESLint React's TSESTree AST utility module.",
5
5
  "homepage": "https://github.com/Rel1cx/eslint-react",
6
6
  "bugs": {
@@ -32,7 +32,7 @@
32
32
  "@typescript-eslint/utils": "^8.44.0",
33
33
  "string-ts": "^2.2.1",
34
34
  "ts-pattern": "^5.8.0",
35
- "@eslint-react/eff": "2.0.0-next.186"
35
+ "@eslint-react/eff": "2.0.0-next.188"
36
36
  },
37
37
  "devDependencies": {
38
38
  "tsdown": "^0.15.2",