@eslint-react/ast 2.8.1-beta.0 → 2.8.1-beta.1

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
@@ -87,6 +87,14 @@ declare const getNestedNewExpressions: (node: TSESTree.Node) => TSESTree.NewExpr
87
87
  */
88
88
  declare const getNestedCallExpressions: (node: TSESTree.Node) => TSESTree.CallExpression[];
89
89
  //#endregion
90
+ //#region src/function-directives.d.ts
91
+ /**
92
+ * Get all directive string literals from a function node
93
+ * @param node The function AST node
94
+ * @returns The array of directive string literals (e.g., "use memo", "use no memo")
95
+ */
96
+ declare function getFunctionDirectives(node: TSESTreeFunction): TSESTree.StringLiteral[];
97
+ //#endregion
90
98
  //#region src/function-id.d.ts
91
99
  /**
92
100
  * Gets the static name of a function AST node. For function declarations it is
@@ -264,4 +272,4 @@ declare function isViMock(node: TSESTree.Node | null | unit): node is TSESTree.M
264
272
  */
265
273
  declare function isViMockCallback(node: TSESTree.Node | null | unit): boolean;
266
274
  //#endregion
267
- export { DisplayNameAssignmentExpression, FunctionID, 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, getClassId, getFunctionId, getFunctionInitPath, getNestedCallExpressions, getNestedExpressionsOfType, getNestedIdentifiers, getNestedNewExpressions, getNestedReturnStatements, getPropertyName, getUnderlyingExpression, hasCallInFunctionInitPath, is, isClass, isConditional, isControlFlow, isFunction, isFunctionEmpty, isFunctionImmediatelyInvoked, isFunctionType, isIdentifierName, isJSX, isJSXElement, isJSXFragment, isJSXTagNameExpression, isLineBreak, isLiteral, isLoop, isMethodOrProperty, isMultiLine, isNaN, isNodeEqual, isOneOf, isProcessEnvNodeEnv, isProcessEnvNodeEnvCompare, isProperty, isThisExpressionLoose, isTypeAssertionExpression, isTypeExpression, isUndefined, isViMock, isViMockCallback, toDelimiterFormat, toStringFormat };
275
+ export { DisplayNameAssignmentExpression, FunctionID, 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, getClassId, getFunctionDirectives, getFunctionId, getFunctionInitPath, getNestedCallExpressions, getNestedExpressionsOfType, getNestedIdentifiers, getNestedNewExpressions, getNestedReturnStatements, getPropertyName, getUnderlyingExpression, hasCallInFunctionInitPath, is, isClass, isConditional, isControlFlow, isFunction, isFunctionEmpty, isFunctionImmediatelyInvoked, isFunctionType, isIdentifierName, isJSX, isJSXElement, isJSXFragment, isJSXTagNameExpression, isLineBreak, isLiteral, isLoop, isMethodOrProperty, isMultiLine, isNaN, isNodeEqual, isOneOf, isProcessEnvNodeEnv, isProcessEnvNodeEnvCompare, isProperty, isThisExpressionLoose, isTypeAssertionExpression, isTypeExpression, isUndefined, isViMock, isViMockCallback, toDelimiterFormat, toStringFormat };
package/dist/index.js CHANGED
@@ -348,6 +348,39 @@ const getNestedNewExpressions = getNestedExpressionsOfType(AST_NODE_TYPES.NewExp
348
348
  */
349
349
  const getNestedCallExpressions = getNestedExpressionsOfType(AST_NODE_TYPES.CallExpression);
350
350
 
351
+ //#endregion
352
+ //#region src/literal.ts
353
+ function isLiteral(node, type) {
354
+ if (node.type !== AST_NODE_TYPES.Literal) return false;
355
+ if (type == null) return true;
356
+ switch (type) {
357
+ case "boolean": return typeof node.value === "boolean";
358
+ case "null": return node.value === null;
359
+ case "number": return typeof node.value === "number";
360
+ case "regexp": return "regex" in node;
361
+ case "string": return typeof node.value === "string";
362
+ }
363
+ }
364
+
365
+ //#endregion
366
+ //#region src/function-directives.ts
367
+ /**
368
+ * Get all directive string literals from a function node
369
+ * @param node The function AST node
370
+ * @returns The array of directive string literals (e.g., "use memo", "use no memo")
371
+ */
372
+ function getFunctionDirectives(node) {
373
+ const directives = [];
374
+ if (node.body.type !== AST_NODE_TYPES.BlockStatement) return directives;
375
+ for (const stmt of node.body.body) {
376
+ if (stmt.type !== AST_NODE_TYPES.ExpressionStatement) continue;
377
+ const expr = getUnderlyingExpression(stmt.expression);
378
+ if (!isLiteral(expr, "string")) continue;
379
+ directives.push(expr);
380
+ }
381
+ return directives;
382
+ }
383
+
351
384
  //#endregion
352
385
  //#region src/function-id.ts
353
386
  /**
@@ -465,20 +498,6 @@ function isIdentifierName(name) {
465
498
  return /^[A-Z$_][\w$]*$/i.test(name);
466
499
  }
467
500
 
468
- //#endregion
469
- //#region src/literal.ts
470
- function isLiteral(node, type) {
471
- if (node.type !== AST_NODE_TYPES.Literal) return false;
472
- if (type == null) return true;
473
- switch (type) {
474
- case "boolean": return typeof node.value === "boolean";
475
- case "null": return node.value === null;
476
- case "number": return typeof node.value === "number";
477
- case "regexp": return "regex" in node;
478
- case "string": return typeof node.value === "string";
479
- }
480
- }
481
-
482
501
  //#endregion
483
502
  //#region src/misc.ts
484
503
  /**
@@ -613,4 +632,4 @@ function isViMockCallback(node) {
613
632
  }
614
633
 
615
634
  //#endregion
616
- export { SEL_DISPLAY_NAME_ASSIGNMENT_EXPRESSION, SEL_IMPLICIT_RETURN_ARROW_FUNCTION_EXPRESSION, SEL_OBJECT_DESTRUCTURING_VARIABLE_DECLARATOR, findParentNode, getClassId, getFunctionId, getFunctionInitPath, getNestedCallExpressions, getNestedExpressionsOfType, getNestedIdentifiers, getNestedNewExpressions, getNestedReturnStatements, getPropertyName, getUnderlyingExpression, hasCallInFunctionInitPath, is, isClass, isConditional, isControlFlow, isFunction, isFunctionEmpty, isFunctionImmediatelyInvoked, isFunctionType, isIdentifierName, isJSX, isJSXElement, isJSXFragment, isJSXTagNameExpression, isLineBreak, isLiteral, isLoop, isMethodOrProperty, isMultiLine, isNaN, isNodeEqual, isOneOf, isProcessEnvNodeEnv, isProcessEnvNodeEnvCompare, isProperty, isThisExpressionLoose, isTypeAssertionExpression, isTypeExpression, isUndefined, isViMock, isViMockCallback, toDelimiterFormat, toStringFormat };
635
+ export { SEL_DISPLAY_NAME_ASSIGNMENT_EXPRESSION, SEL_IMPLICIT_RETURN_ARROW_FUNCTION_EXPRESSION, SEL_OBJECT_DESTRUCTURING_VARIABLE_DECLARATOR, findParentNode, getClassId, getFunctionDirectives, getFunctionId, getFunctionInitPath, getNestedCallExpressions, getNestedExpressionsOfType, getNestedIdentifiers, getNestedNewExpressions, getNestedReturnStatements, getPropertyName, getUnderlyingExpression, hasCallInFunctionInitPath, is, isClass, isConditional, isControlFlow, isFunction, isFunctionEmpty, isFunctionImmediatelyInvoked, isFunctionType, isIdentifierName, isJSX, isJSXElement, isJSXFragment, isJSXTagNameExpression, isLineBreak, isLiteral, isLoop, isMethodOrProperty, isMultiLine, isNaN, isNodeEqual, isOneOf, isProcessEnvNodeEnv, isProcessEnvNodeEnvCompare, isProperty, isThisExpressionLoose, isTypeAssertionExpression, isTypeExpression, isUndefined, isViMock, isViMockCallback, toDelimiterFormat, toStringFormat };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/ast",
3
- "version": "2.8.1-beta.0",
3
+ "version": "2.8.1-beta.1",
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": "^8.54.0",
35
35
  "@typescript-eslint/utils": "^8.54.0",
36
36
  "string-ts": "^2.3.1",
37
- "@eslint-react/eff": "2.8.1-beta.0"
37
+ "@eslint-react/eff": "2.8.1-beta.1"
38
38
  },
39
39
  "devDependencies": {
40
40
  "tsdown": "^0.20.1",