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

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
@@ -207,6 +215,14 @@ declare function isProcessEnvNodeEnv(node: TSESTree.Node | null | unit): node is
207
215
  */
208
216
  declare function isProcessEnvNodeEnvCompare(node: TSESTree.Node | null | unit, operator: "===" | "!==", value: "development" | "production"): node is TSESTree.BinaryExpression;
209
217
  //#endregion
218
+ //#region src/program-directives.d.ts
219
+ /**
220
+ * Get all directive string literals from a program node
221
+ * @param node The program AST node
222
+ * @returns The array of directive string literals (e.g., "use strict")
223
+ */
224
+ declare function getProgramDirectives(node: TSESTree.Program): TSESTree.StringLiteral[];
225
+ //#endregion
210
226
  //#region src/property-name.d.ts
211
227
  declare function getPropertyName(node: TSESTree.Node): string | unit;
212
228
  //#endregion
@@ -264,4 +280,4 @@ declare function isViMock(node: TSESTree.Node | null | unit): node is TSESTree.M
264
280
  */
265
281
  declare function isViMockCallback(node: TSESTree.Node | null | unit): boolean;
266
282
  //#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 };
283
+ 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, getProgramDirectives, 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
  /**
@@ -566,6 +585,24 @@ function isProcessEnvNodeEnvCompare(node, operator, value) {
566
585
  return false;
567
586
  }
568
587
 
588
+ //#endregion
589
+ //#region src/program-directives.ts
590
+ /**
591
+ * Get all directive string literals from a program node
592
+ * @param node The program AST node
593
+ * @returns The array of directive string literals (e.g., "use strict")
594
+ */
595
+ function getProgramDirectives(node) {
596
+ const directives = [];
597
+ for (const stmt of node.body) {
598
+ if (stmt.type !== AST_NODE_TYPES.ExpressionStatement) continue;
599
+ const expr = getUnderlyingExpression(stmt.expression);
600
+ if (!isLiteral(expr, "string")) continue;
601
+ directives.push(expr);
602
+ }
603
+ return directives;
604
+ }
605
+
569
606
  //#endregion
570
607
  //#region src/property-name.ts
571
608
  function getPropertyName(node) {
@@ -613,4 +650,4 @@ function isViMockCallback(node) {
613
650
  }
614
651
 
615
652
  //#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 };
653
+ 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, getProgramDirectives, 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.3",
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.3"
38
38
  },
39
39
  "devDependencies": {
40
40
  "tsdown": "^0.20.1",