@eslint-react/ast 3.0.0-next.63 → 3.0.0-next.65

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,4 +1,3 @@
1
- import { unit } from "@eslint-react/eff";
2
1
  import { AST_NODE_TYPES, TSESTree } from "@typescript-eslint/types";
3
2
  import { TSESTree as TSESTree$1 } from "@typescript-eslint/utils";
4
3
 
@@ -73,9 +72,9 @@ type TSESTreeDirectiveLike = TSESTree$1.ExpressionStatement & {
73
72
  /**
74
73
  * Get the class identifier of a class node
75
74
  * @param node The class node to get the identifier from
76
- * @returns The class identifier or unit if not found
75
+ * @returns The class identifier or null if not found
77
76
  */
78
- declare function getClassId(node: TSESTreeClass): TSESTree.BindingName | unit;
77
+ declare function getClassId(node: TSESTreeClass): TSESTree.BindingName | null;
79
78
  //#endregion
80
79
  //#region src/directive-is.d.ts
81
80
  /**
@@ -191,7 +190,7 @@ declare function isDirectiveInFunction(node: TSESTreeFunction, name: string): bo
191
190
  * where JS gives anonymous function expressions names. We roughly detect the
192
191
  * same AST nodes with some exceptions to better fit our use case.
193
192
  */
194
- declare function getFunctionId(node: TSESTree.Expression | TSESTreeFunction): TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpression | TSESTree.AssignmentExpression | TSESTree.AwaitExpression | TSESTree.PrivateInExpression | TSESTree.SymmetricBinaryExpression | TSESTree.CallExpression | TSESTree.ChainExpression | TSESTree.ClassExpression | TSESTree.ConditionalExpression | TSESTree.FunctionExpression | TSESTree.Identifier | TSESTree.ImportExpression | TSESTree.JSXElement | TSESTree.JSXFragment | TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral | TSESTree.LogicalExpression | TSESTree.MemberExpressionComputedName | TSESTree.MemberExpressionNonComputedName | TSESTree.MetaProperty | TSESTree.NewExpression | TSESTree.ObjectExpression | TSESTree.ObjectPattern | TSESTree.PrivateIdentifier | TSESTree.SequenceExpression | TSESTree.Super | TSESTree.TaggedTemplateExpression | TSESTree.TemplateLiteral | TSESTree.ThisExpression | TSESTree.TSAsExpression | TSESTree.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion | TSESTree.UnaryExpressionBitwiseNot | TSESTree.UnaryExpressionDelete | TSESTree.UnaryExpressionMinus | TSESTree.UnaryExpressionNot | TSESTree.UnaryExpressionPlus | TSESTree.UnaryExpressionTypeof | TSESTree.UnaryExpressionVoid | TSESTree.UpdateExpression | TSESTree.YieldExpression | undefined;
193
+ declare function getFunctionId(node: TSESTree.Expression | TSESTreeFunction): TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpression | TSESTree.AssignmentExpression | TSESTree.AwaitExpression | TSESTree.PrivateInExpression | TSESTree.SymmetricBinaryExpression | TSESTree.CallExpression | TSESTree.ChainExpression | TSESTree.ClassExpression | TSESTree.ConditionalExpression | TSESTree.FunctionExpression | TSESTree.Identifier | TSESTree.ImportExpression | TSESTree.JSXElement | TSESTree.JSXFragment | TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral | TSESTree.LogicalExpression | TSESTree.MemberExpressionComputedName | TSESTree.MemberExpressionNonComputedName | TSESTree.MetaProperty | TSESTree.NewExpression | TSESTree.ObjectExpression | TSESTree.ObjectPattern | TSESTree.PrivateIdentifier | TSESTree.SequenceExpression | TSESTree.Super | TSESTree.TaggedTemplateExpression | TSESTree.TemplateLiteral | TSESTree.ThisExpression | TSESTree.TSAsExpression | TSESTree.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion | TSESTree.UnaryExpressionBitwiseNot | TSESTree.UnaryExpressionDelete | TSESTree.UnaryExpressionMinus | TSESTree.UnaryExpressionNot | TSESTree.UnaryExpressionPlus | TSESTree.UnaryExpressionTypeof | TSESTree.UnaryExpressionVoid | TSESTree.UpdateExpression | TSESTree.YieldExpression | null;
195
194
  /**
196
195
  * Type representing the return type of getFunctionId
197
196
  */
@@ -208,9 +207,9 @@ type FunctionInitPath = readonly [TSESTree.FunctionDeclaration] | readonly [TSES
208
207
  * Determine what kind of component declaration pattern the function belongs to.
209
208
  *
210
209
  * @param node The function node to analyze
211
- * @returns The function initialization path or unit if not identifiable
210
+ * @returns The function initialization path or null if not identifiable
212
211
  */
213
- declare function getFunctionInitPath(node: TSESTreeFunction): unit | FunctionInitPath;
212
+ declare function getFunctionInitPath(node: TSESTreeFunction): null | FunctionInitPath;
214
213
  /**
215
214
  * Check if a specific function call exists in the function initialization path.
216
215
  * Useful for detecting HOCs like React.memo, React.forwardRef, etc.
@@ -242,7 +241,7 @@ declare function isFunctionImmediatelyInvoked(node: TSESTreeFunction): boolean;
242
241
  * @param name The name to check
243
242
  * @returns True if the node is an identifier, false otherwise
244
243
  */
245
- declare function isIdentifier(node: TSESTree.Node | null | unit, name?: string): node is TSESTree.Identifier;
244
+ declare function isIdentifier(node: TSESTree.Node | null, name?: string): node is TSESTree.Identifier;
246
245
  //#endregion
247
246
  //#region src/identifier-name.d.ts
248
247
  /**
@@ -444,16 +443,16 @@ declare const SEL_DISPLAY_NAME_ASSIGNMENT_EXPRESSION: string;
444
443
  * Find the parent node that satisfies the test function
445
444
  * @param node The AST node
446
445
  * @param test The test function
447
- * @returns The parent node that satisfies the test function or `_` if not found
446
+ * @returns The parent node that satisfies the test function or `null` if not found
448
447
  */
449
- declare function findParentNode<A extends TSESTree.Node>(node: TSESTree.Node | unit, test: (n: TSESTree.Node) => n is A): A | unit;
448
+ declare function findParentNode<A extends TSESTree.Node>(node: TSESTree.Node | null, test: (n: TSESTree.Node) => n is A): A | null;
450
449
  /**
451
- * Find the parent node that satisfies the test function or `_` if not found
450
+ * Find the parent node that satisfies the test function or `null` if not found
452
451
  * @param node The AST node
453
452
  * @param test The test function
454
453
  * @returns The parent node that satisfies the test function
455
454
  */
456
- declare function findParentNode(node: TSESTree.Node | unit, test: (node: TSESTree.Node) => boolean): TSESTree.Node | unit;
455
+ declare function findParentNode(node: TSESTree.Node | null, test: (node: TSESTree.Node) => boolean): TSESTree.Node | null;
457
456
  //#endregion
458
457
  //#region src/node-unwrap.d.ts
459
458
  /**
@@ -470,7 +469,7 @@ declare function getUnderlyingExpression(node: TSESTree.Node): Exclude<TSESTree.
470
469
  * @param node The AST node
471
470
  * @returns True if the node is a member expression that accesses `process.env.NODE_ENV`, false otherwise
472
471
  */
473
- declare function isProcessEnvNodeEnv(node: TSESTree.Node | null | unit): node is TSESTree.MemberExpression;
472
+ declare function isProcessEnvNodeEnv(node: TSESTree.Node | null): node is TSESTree.MemberExpression;
474
473
  /**
475
474
  * Check if the given node is a binary expression that compares `process.env.NODE_ENV` with a string literal.
476
475
  * @param node The AST node
@@ -478,7 +477,7 @@ declare function isProcessEnvNodeEnv(node: TSESTree.Node | null | unit): node is
478
477
  * @param value The string literal value to compare against
479
478
  * @returns True if the node is a binary expression that compares `process.env.NODE_ENV` with the specified value, false otherwise
480
479
  */
481
- declare function isProcessEnvNodeEnvCompare(node: TSESTree.Node | null | unit, operator: "===" | "!==", value: "development" | "production"): node is TSESTree.BinaryExpression;
480
+ declare function isProcessEnvNodeEnvCompare(node: TSESTree.Node | null, operator: "===" | "!==", value: "development" | "production"): node is TSESTree.BinaryExpression;
482
481
  //#endregion
483
482
  //#region src/pattern-vitest-mock.d.ts
484
483
  /**
@@ -487,31 +486,31 @@ declare function isProcessEnvNodeEnvCompare(node: TSESTree.Node | null | unit, o
487
486
  * @returns `true` if the node is a `vi.mock`, otherwise `false`.
488
487
  * @internal
489
488
  */
490
- declare function isViMock(node: TSESTree.Node | null | unit): node is TSESTree.MemberExpression;
489
+ declare function isViMock(node: TSESTree.Node | null): node is TSESTree.MemberExpression;
491
490
  /**
492
491
  * Check if the given node is a `vi.mock` callback.
493
492
  * @param node The node to check
494
493
  * @returns `true` if the node is a `vi.mock` callback, otherwise `false`.
495
494
  * @internal
496
495
  */
497
- declare function isViMockCallback(node: TSESTree.Node | null | unit): boolean;
496
+ declare function isViMockCallback(node: TSESTree.Node | null): boolean;
498
497
  //#endregion
499
498
  //#region src/property-name.d.ts
500
499
  /**
501
500
  * Get the name of a property from a node
502
501
  * Handles identifiers, private identifiers, literals, and template literals
503
502
  * @param node The node to get the property name from
504
- * @returns The property name or unit if not determinable
503
+ * @returns The property name or null if not determinable
505
504
  */
506
- declare function getPropertyName(node: TSESTree.Node): string | unit;
505
+ declare function getPropertyName(node: TSESTree.Node): string | null;
507
506
  //#endregion
508
507
  //#region src/property-traverse.d.ts
509
508
  /**
510
509
  * Recursively traverses an object expression's properties to find a property with the specified name
511
510
  * @param properties The properties of the object expression to traverse
512
511
  * @param name The name of the property to find
513
- * @returns The matching property node, or undefined if not found
512
+ * @returns The matching property node, or null if not found
514
513
  */
515
- declare function findProperty(properties: TSESTree.ObjectLiteralElement[], name: string): TSESTree.Property | unit;
514
+ declare function findProperty(properties: TSESTree.ObjectLiteralElement[], name: string): TSESTree.Property | null;
516
515
  //#endregion
517
516
  export { DirectiveKind, DisplayNameAssignmentExpression, FunctionID, FunctionInitPath, ImplicitReturnArrowFunctionExpression, ObjectDestructuringVariableDeclarator, SEL_DISPLAY_NAME_ASSIGNMENT_EXPRESSION, SEL_IMPLICIT_RETURN_ARROW_FUNCTION_EXPRESSION, SEL_OBJECT_DESTRUCTURING_VARIABLE_DECLARATOR, TSESTreeArrayTupleType, TSESTreeClass, TSESTreeDestructuringPattern, TSESTreeDirective, TSESTreeDirectiveLike, TSESTreeFunction, TSESTreeFunctionType, TSESTreeJSX, TSESTreeJSXAttributeLike, TSESTreeLoop, TSESTreeMethodOrProperty, TSESTreeProperty, TSESTreeTypeAssertionExpression, TSESTreeTypeDeclaration, TSESTreeTypeExpression, findParentNode, findProperty, getClassId, getFileDirectives, getFullyQualifiedName, getFunctionDirectives, getFunctionId, getFunctionInitPath, getHumanReadableKind, getNestedCallExpressions, getNestedExpressionsOfType, getNestedIdentifiers, getNestedNewExpressions, getNestedReturnStatements, getPropertyName, getRootIdentifier, getUnderlyingExpression, hasCallInFunctionInitPath, is, isClass, isConditional, isControlFlow, isDirective, isDirectiveInFile, isDirectiveInFunction, isDirectiveKind, isDirectiveLike, isDirectiveName, isFunction, isFunctionEmpty, isFunctionImmediatelyInvoked, isFunctionType, isIdentifier, isIdentifierName, isJSX, isJSXElement, isJSXFragment, isJSXTagNameExpression, isLineBreak, isLiteral, isLoop, isMethodOrProperty, isMultiLine, isNodeEqual, isOneOf, isProcessEnvNodeEnv, isProcessEnvNodeEnvCompare, isProperty, isThisExpressionLoose, isTypeAssertionExpression, isTypeExpression, isViMock, isViMockCallback };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { dual, or, unit } from "@eslint-react/eff";
2
1
  import { AST_NODE_TYPES, TSESTree } from "@typescript-eslint/types";
2
+ import { dual, or } from "@eslint-react/eff";
3
3
  import { ASTUtils } from "@typescript-eslint/utils";
4
4
  import { simpleTraverse } from "@typescript-eslint/typescript-estree";
5
5
  import { delimiterCase, replace, toLowerCase } from "string-ts";
@@ -8,12 +8,12 @@ import { delimiterCase, replace, toLowerCase } from "string-ts";
8
8
  /**
9
9
  * Get the class identifier of a class node
10
10
  * @param node The class node to get the identifier from
11
- * @returns The class identifier or unit if not found
11
+ * @returns The class identifier or null if not found
12
12
  */
13
13
  function getClassId(node) {
14
14
  if (node.id != null) return node.id;
15
15
  if (node.parent.type === AST_NODE_TYPES.VariableDeclarator) return node.parent.id;
16
- return unit;
16
+ return null;
17
17
  }
18
18
 
19
19
  //#endregion
@@ -255,13 +255,13 @@ function isThisExpressionLoose(node) {
255
255
  //#endregion
256
256
  //#region src/node-traverse.ts
257
257
  function findParentNode(node, test) {
258
- if (node == null) return unit;
258
+ if (node == null) return null;
259
259
  let parent = node.parent;
260
260
  while (parent != null && parent.type !== AST_NODE_TYPES.Program) {
261
261
  if (test(parent)) return parent;
262
262
  parent = parent.parent;
263
263
  }
264
- return unit;
264
+ return null;
265
265
  }
266
266
 
267
267
  //#endregion
@@ -518,7 +518,7 @@ function getFunctionId(node) {
518
518
  case node.parent.type === AST_NODE_TYPES.ConditionalExpression: return getFunctionId(node.parent);
519
519
  case isTypeAssertionExpression(node.parent): return getFunctionId(node.parent);
520
520
  }
521
- return unit;
521
+ return null;
522
522
  }
523
523
 
524
524
  //#endregion
@@ -528,7 +528,7 @@ function getFunctionId(node) {
528
528
  * Determine what kind of component declaration pattern the function belongs to.
529
529
  *
530
530
  * @param node The function node to analyze
531
- * @returns The function initialization path or unit if not identifiable
531
+ * @returns The function initialization path or null if not identifiable
532
532
  */
533
533
  function getFunctionInitPath(node) {
534
534
  if (node.type === AST_NODE_TYPES.FunctionDeclaration) return [node];
@@ -572,7 +572,7 @@ function getFunctionInitPath(node) {
572
572
  node
573
573
  ];
574
574
  }
575
- return unit;
575
+ return null;
576
576
  }
577
577
  /**
578
578
  * Check if a specific function call exists in the function initialization path.
@@ -806,14 +806,14 @@ function isViMockCallback(node) {
806
806
  * Get the name of a property from a node
807
807
  * Handles identifiers, private identifiers, literals, and template literals
808
808
  * @param node The node to get the property name from
809
- * @returns The property name or unit if not determinable
809
+ * @returns The property name or null if not determinable
810
810
  */
811
811
  function getPropertyName(node) {
812
812
  if (isTypeExpression(node)) return getPropertyName(getUnderlyingExpression(node));
813
813
  if (node.type === AST_NODE_TYPES.Identifier || node.type === AST_NODE_TYPES.PrivateIdentifier) return node.name;
814
814
  if (node.type === AST_NODE_TYPES.Literal) return String(node.value);
815
- if (node.type === AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) return node.quasis[0]?.value.raw;
816
- return unit;
815
+ if (node.type === AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) return node.quasis[0]?.value.raw ?? null;
816
+ return null;
817
817
  }
818
818
 
819
819
  //#endregion
@@ -822,7 +822,7 @@ function getPropertyName(node) {
822
822
  * Recursively traverses an object expression's properties to find a property with the specified name
823
823
  * @param properties The properties of the object expression to traverse
824
824
  * @param name The name of the property to find
825
- * @returns The matching property node, or undefined if not found
825
+ * @returns The matching property node, or null if not found
826
826
  */
827
827
  function findProperty(properties, name) {
828
828
  for (const prop of properties) {
@@ -832,7 +832,7 @@ function findProperty(properties, name) {
832
832
  if (found != null) return found;
833
833
  }
834
834
  }
835
- return unit;
835
+ return null;
836
836
  }
837
837
 
838
838
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/ast",
3
- "version": "3.0.0-next.63",
3
+ "version": "3.0.0-next.65",
4
4
  "description": "ESLint React's TSESTree AST utility module.",
5
5
  "homepage": "https://github.com/Rel1cx/eslint-react",
6
6
  "bugs": {
@@ -34,7 +34,7 @@
34
34
  "@typescript-eslint/typescript-estree": "canary",
35
35
  "@typescript-eslint/utils": "canary",
36
36
  "string-ts": "^2.3.1",
37
- "@eslint-react/eff": "3.0.0-next.63"
37
+ "@eslint-react/eff": "3.0.0-next.65"
38
38
  },
39
39
  "devDependencies": {
40
40
  "tsdown": "^0.21.0-beta.2",