@eslint-react/ast 2.8.2-beta.0 → 2.8.2-beta.4

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
@@ -18,11 +18,41 @@ type TSESTreeTypeExpression = TSESTree$1.TSAsExpression | TSESTree$1.TSNonNullEx
18
18
  type TSESTreeTypeAssertionExpression = TSESTree$1.TSAsExpression | TSESTree$1.TSNonNullExpression | TSESTree$1.TSSatisfiesExpression | TSESTree$1.TSTypeAssertion;
19
19
  //#endregion
20
20
  //#region src/class-id.d.ts
21
+ /**
22
+ * Get the class identifier of a class node
23
+ * @param node The class node to get the identifier from
24
+ * @returns The class identifier or unit if not found
25
+ */
21
26
  declare function getClassId(node: TSESTreeClass): TSESTree.BindingName | unit;
22
27
  //#endregion
28
+ //#region src/directive-is.d.ts
29
+ /**
30
+ * Check if a node is a directive
31
+ * @param node The node to check
32
+ * @returns True if the node is a directive, false otherwise
33
+ */
34
+ declare function isDirective(node: TSESTree.Node): node is TSESTree.StringLiteral;
35
+ //#endregion
36
+ //#region src/directive-kind.d.ts
37
+ type DirectiveKind = "use client" | "use server" | "use memo" | "use no memo";
38
+ /**
39
+ * Check if a node is a directive kind
40
+ * @param kind The kind to check
41
+ * @returns True if the kind is a directive kind, false otherwise
42
+ */
43
+ declare function isDirectiveKind(kind: string): kind is DirectiveKind;
44
+ //#endregion
45
+ //#region src/directive-name.d.ts
46
+ /**
47
+ * Check if a string is a directive name
48
+ * @param name The string to check
49
+ * @returns True if the string is a directive name, false otherwise
50
+ */
51
+ declare function isDirectiveName(name: string): boolean;
52
+ //#endregion
23
53
  //#region src/equal.d.ts
24
54
  /**
25
- * Determine whether node equals to another node
55
+ * Check if two nodes are equal
26
56
  * @param a node to compare
27
57
  * @param b node to compare
28
58
  * @returns `true` if node equal
@@ -44,11 +74,11 @@ declare function getUnderlyingExpression(node: TSESTree.Node): Exclude<TSESTree.
44
74
  //#endregion
45
75
  //#region src/expression-is.d.ts
46
76
  /**
47
- * Check if the given expression is a 'this' expression.
48
- * Unwraps any type expressions before checking.
77
+ * Check if the given expression is a 'this' expression
78
+ * Unwraps any type expressions before checking
49
79
  *
50
80
  * @param node The expression node to check
51
- * @returns true if the expression is a ThisExpression, false otherwise
81
+ * @returns True if the expression is a 'this' expression, false otherwise
52
82
  */
53
83
  declare function isThisExpressionLoose(node: TSESTree.Expression): boolean;
54
84
  //#endregion
@@ -87,7 +117,31 @@ declare const getNestedNewExpressions: (node: TSESTree.Node) => TSESTree.NewExpr
87
117
  */
88
118
  declare const getNestedCallExpressions: (node: TSESTree.Node) => TSESTree.CallExpression[];
89
119
  //#endregion
90
- //#region src/function-directives.d.ts
120
+ //#region src/file-directive.d.ts
121
+ /**
122
+ * Get all directive string literals from a program node
123
+ * @param node The program AST node
124
+ * @returns The array of directive string literals (e.g., "use strict")
125
+ */
126
+ declare function getFileDirectives(node: TSESTree.Program): TSESTree.StringLiteral[];
127
+ //#endregion
128
+ //#region src/format.d.ts
129
+ /**
130
+ * Convert a node type to a delimiter format string
131
+ * @param node The AST node
132
+ * @param delimiter The delimiter to use
133
+ * @returns The delimiter format string
134
+ */
135
+ declare function toDelimiterFormat(node: TSESTree.Node, delimiter?: string): "RegExp literal" | Lowercase<string> | `JSX ${Lowercase<string>}`;
136
+ /**
137
+ * Incomplete but sufficient stringification of AST nodes for common use cases
138
+ * @param node The AST node
139
+ * @param getText A function to get the text representation of a node
140
+ * @returns A string representation of the node
141
+ */
142
+ declare function toStringFormat(node: TSESTree.Node, getText: (node: TSESTree.Node) => string): string;
143
+ //#endregion
144
+ //#region src/function-directive.d.ts
91
145
  /**
92
146
  * Get all directive string literals from a function node
93
147
  * @param node The function AST node
@@ -108,8 +162,8 @@ type FunctionID = ReturnType<typeof getFunctionId>;
108
162
  //#endregion
109
163
  //#region src/function-init-path.d.ts
110
164
  /**
111
- * Represents various AST paths for React component function declarations.
112
- * Each tuple type represents a specific component definition pattern.
165
+ * Represents various AST paths for React component function declarations
166
+ * Each tuple type represents a specific component definition pattern
113
167
  */
114
168
  type FunctionInitPath = readonly [TSESTree.FunctionDeclaration] | readonly [TSESTree.VariableDeclaration, TSESTree.VariableDeclarator, TSESTreeFunction] | readonly [TSESTree.VariableDeclaration, TSESTree.VariableDeclarator, TSESTree.CallExpression, TSESTreeFunction] | readonly [TSESTree.VariableDeclaration, TSESTree.VariableDeclarator, TSESTree.CallExpression, TSESTree.CallExpression, TSESTreeFunction] | readonly [TSESTree.VariableDeclaration, TSESTree.VariableDeclarator, TSESTree.ObjectExpression, TSESTree.Property, TSESTreeFunction] | readonly [TSESTree.VariableDeclaration, TSESTree.VariableDeclarator, TSESTree.ObjectExpression, TSESTree.Property, TSESTree.CallExpression, TSESTreeFunction] | readonly [TSESTree.VariableDeclaration, TSESTree.VariableDeclarator, TSESTree.ObjectExpression, TSESTree.Property, TSESTree.CallExpression, TSESTree.CallExpression, TSESTreeFunction] | readonly [TSESTree.ClassDeclaration, TSESTree.ClassBody, TSESTree.MethodDefinition, TSESTreeFunction] | readonly [TSESTree.ClassDeclaration, TSESTree.ClassBody, TSESTree.PropertyDefinition, TSESTreeFunction];
115
169
  /**
@@ -131,12 +185,27 @@ declare function getFunctionInitPath(node: TSESTreeFunction): unit | FunctionIni
131
185
  declare function hasCallInFunctionInitPath(callName: string, initPath: FunctionInitPath): boolean;
132
186
  //#endregion
133
187
  //#region src/function-is.d.ts
188
+ /**
189
+ * Check if a function is empty
190
+ * @param node The function node to check
191
+ * @returns True if the function is empty, false otherwise
192
+ */
134
193
  declare function isFunctionEmpty(node: TSESTreeFunction): boolean;
194
+ /**
195
+ * Check if a function is immediately invoked
196
+ * @param node The function node to check
197
+ * @returns True if the function is immediately invoked, false otherwise
198
+ */
135
199
  declare function isFunctionImmediatelyInvoked(node: TSESTreeFunction): boolean;
136
200
  //#endregion
137
201
  //#region src/identifier-is.d.ts
138
- declare function isNaN(node: TSESTree.Node | null | unit): node is TSESTree.Identifier;
139
- declare function isUndefined(node: TSESTree.Node | null | unit): node is TSESTree.Identifier;
202
+ /**
203
+ * Check if the given node is an identifier
204
+ * @param node The node to check
205
+ * @param name The name to check
206
+ * @returns True if the node is an identifier, false otherwise
207
+ */
208
+ declare function isIdentifier(node: TSESTree.Node | null | unit, name?: string): node is TSESTree.Identifier;
140
209
  //#endregion
141
210
  //#region src/identifier-name.d.ts
142
211
  declare function isIdentifierName(name: string): boolean;
@@ -171,33 +240,19 @@ declare function isLiteral(node: TSESTree.Node, type: "number"): node is TSESTre
171
240
  declare function isLiteral(node: TSESTree.Node, type: "regexp"): node is TSESTree.RegExpLiteral;
172
241
  declare function isLiteral(node: TSESTree.Node, type: "string"): node is TSESTree.StringLiteral;
173
242
  //#endregion
174
- //#region src/misc.d.ts
243
+ //#region src/location.d.ts
175
244
  /**
176
- * Check if a node is multiline
245
+ * Check if a node spans multiple lines
177
246
  * @param node The AST node to check
178
- * @returns `true` if the node is multiline
247
+ * @returns `true` if the node spans multiple lines, `false` otherwise
179
248
  */
180
249
  declare function isMultiLine(node: TSESTree.Node): boolean;
181
250
  /**
182
- * Check if a node is a line break
251
+ * Check if a node is a line break (whitespace spanning multiple lines)
183
252
  * @param node The AST node to check
184
- * @returns boolean
253
+ * @returns `true` if the node is a line break, `false` otherwise
185
254
  */
186
255
  declare function isLineBreak(node: TSESTree.Node): boolean;
187
- /**
188
- * Convert a node type to a delimiter format string
189
- * @param node The AST node
190
- * @param delimiter The delimiter to use
191
- * @returns The delimiter format string
192
- */
193
- declare function toDelimiterFormat(node: TSESTree.Node, delimiter?: string): "RegExp literal" | Lowercase<string> | `JSX ${Lowercase<string>}`;
194
- /**
195
- * Incomplete but sufficient stringification of AST nodes for common use cases
196
- * @param node The AST node
197
- * @param getText A function to get the text representation of a node
198
- * @returns A string representation of the node
199
- */
200
- declare function toStringFormat(node: TSESTree.Node, getText: (node: TSESTree.Node) => string): string;
201
256
  //#endregion
202
257
  //#region src/process-env-node-env.d.ts
203
258
  /**
@@ -215,14 +270,6 @@ declare function isProcessEnvNodeEnv(node: TSESTree.Node | null | unit): node is
215
270
  */
216
271
  declare function isProcessEnvNodeEnvCompare(node: TSESTree.Node | null | unit, operator: "===" | "!==", value: "development" | "production"): node is TSESTree.BinaryExpression;
217
272
  //#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
226
273
  //#region src/property-name.d.ts
227
274
  declare function getPropertyName(node: TSESTree.Node): string | unit;
228
275
  //#endregion
@@ -280,4 +327,4 @@ declare function isViMock(node: TSESTree.Node | null | unit): node is TSESTree.M
280
327
  */
281
328
  declare function isViMockCallback(node: TSESTree.Node | null | unit): boolean;
282
329
  //#endregion
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 };
330
+ 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, TSESTreeFunction, TSESTreeFunctionType, TSESTreeJSX, TSESTreeJSXAttributeLike, TSESTreeLoop, TSESTreeMethodOrProperty, TSESTreeProperty, TSESTreeTypeAssertionExpression, TSESTreeTypeDeclaration, TSESTreeTypeExpression, findParentNode, getClassId, getFileDirectives, getFunctionDirectives, getFunctionId, getFunctionInitPath, getNestedCallExpressions, getNestedExpressionsOfType, getNestedIdentifiers, getNestedNewExpressions, getNestedReturnStatements, getPropertyName, getUnderlyingExpression, hasCallInFunctionInitPath, is, isClass, isConditional, isControlFlow, isDirective, isDirectiveKind, 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, toDelimiterFormat, toStringFormat };
package/dist/index.js CHANGED
@@ -5,12 +5,64 @@ import { simpleTraverse } from "@typescript-eslint/typescript-estree";
5
5
  import { delimiterCase, replace, toLowerCase } from "string-ts";
6
6
 
7
7
  //#region src/class-id.ts
8
+ /**
9
+ * Get the class identifier of a class node
10
+ * @param node The class node to get the identifier from
11
+ * @returns The class identifier or unit if not found
12
+ */
8
13
  function getClassId(node) {
9
14
  if (node.id != null) return node.id;
10
15
  if (node.parent.type === AST_NODE_TYPES.VariableDeclarator) return node.parent.id;
11
16
  return unit;
12
17
  }
13
18
 
19
+ //#endregion
20
+ //#region src/directive-name.ts
21
+ /**
22
+ * Check if a string is a directive name
23
+ * @param name The string to check
24
+ * @returns True if the string is a directive name, false otherwise
25
+ */
26
+ function isDirectiveName(name) {
27
+ return name.startsWith("use ") && name.length > 4;
28
+ }
29
+
30
+ //#endregion
31
+ //#region src/literal.ts
32
+ function isLiteral(node, type) {
33
+ if (node.type !== AST_NODE_TYPES.Literal) return false;
34
+ if (type == null) return true;
35
+ switch (type) {
36
+ case "boolean": return typeof node.value === "boolean";
37
+ case "null": return node.value === null;
38
+ case "number": return typeof node.value === "number";
39
+ case "regexp": return "regex" in node;
40
+ case "string": return typeof node.value === "string";
41
+ }
42
+ }
43
+
44
+ //#endregion
45
+ //#region src/directive-is.ts
46
+ /**
47
+ * Check if a node is a directive
48
+ * @param node The node to check
49
+ * @returns True if the node is a directive, false otherwise
50
+ */
51
+ function isDirective(node) {
52
+ return isLiteral(node, "string") && isDirectiveName(node.value);
53
+ }
54
+
55
+ //#endregion
56
+ //#region src/directive-kind.ts
57
+ /**
58
+ * Check if a node is a directive kind
59
+ * @param kind The kind to check
60
+ * @returns True if the kind is a directive kind, false otherwise
61
+ */
62
+ function isDirectiveKind(kind) {
63
+ return kind === "use client" || kind === "use server" || kind === "use memo" || kind === "use no memo";
64
+ }
65
+
14
66
  //#endregion
15
67
  //#region src/is.ts
16
68
  const is = ASTUtils.isNodeOfType;
@@ -102,7 +154,7 @@ function getUnderlyingExpression(node) {
102
154
  //#endregion
103
155
  //#region src/equal.ts
104
156
  /**
105
- * Determine whether node equals to another node
157
+ * Check if two nodes are equal
106
158
  * @param a node to compare
107
159
  * @param b node to compare
108
160
  * @returns `true` if node equal
@@ -143,11 +195,11 @@ const isNodeEqual = dual(2, (a, b) => {
143
195
  //#endregion
144
196
  //#region src/expression-is.ts
145
197
  /**
146
- * Check if the given expression is a 'this' expression.
147
- * Unwraps any type expressions before checking.
198
+ * Check if the given expression is a 'this' expression
199
+ * Unwraps any type expressions before checking
148
200
  *
149
201
  * @param node The expression node to check
150
- * @returns true if the expression is a ThisExpression, false otherwise
202
+ * @returns True if the expression is a 'this' expression, false otherwise
151
203
  */
152
204
  function isThisExpressionLoose(node) {
153
205
  return getUnderlyingExpression(node).type === AST_NODE_TYPES.ThisExpression;
@@ -349,21 +401,62 @@ const getNestedNewExpressions = getNestedExpressionsOfType(AST_NODE_TYPES.NewExp
349
401
  const getNestedCallExpressions = getNestedExpressionsOfType(AST_NODE_TYPES.CallExpression);
350
402
 
351
403
  //#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";
404
+ //#region src/file-directive.ts
405
+ /**
406
+ * Get all directive string literals from a program node
407
+ * @param node The program AST node
408
+ * @returns The array of directive string literals (e.g., "use strict")
409
+ */
410
+ function getFileDirectives(node) {
411
+ const directives = [];
412
+ for (const stmt of node.body) {
413
+ if (stmt.type !== AST_NODE_TYPES.ExpressionStatement) continue;
414
+ const expr = getUnderlyingExpression(stmt.expression);
415
+ if (!isDirective(expr)) continue;
416
+ directives.push(expr);
362
417
  }
418
+ return directives;
363
419
  }
364
420
 
365
421
  //#endregion
366
- //#region src/function-directives.ts
422
+ //#region src/format.ts
423
+ /**
424
+ * Convert a node type to a delimiter format string
425
+ * @param node The AST node
426
+ * @param delimiter The delimiter to use
427
+ * @returns The delimiter format string
428
+ */
429
+ function toDelimiterFormat(node, delimiter = " ") {
430
+ if (node.type === AST_NODE_TYPES.Literal) {
431
+ if ("regex" in node) return "RegExp literal";
432
+ if (node.value === null) return "null literal";
433
+ return `${typeof node.value} literal`;
434
+ }
435
+ if (isJSX(node)) return `JSX ${toLowerCase(delimiterCase(replace(node.type, "JSX", ""), delimiter))}`;
436
+ return toLowerCase(delimiterCase(node.type, delimiter));
437
+ }
438
+ /**
439
+ * Incomplete but sufficient stringification of AST nodes for common use cases
440
+ * @param node The AST node
441
+ * @param getText A function to get the text representation of a node
442
+ * @returns A string representation of the node
443
+ */
444
+ function toStringFormat(node, getText) {
445
+ switch (node.type) {
446
+ case AST_NODE_TYPES.Identifier:
447
+ case AST_NODE_TYPES.JSXIdentifier:
448
+ case AST_NODE_TYPES.PrivateIdentifier: return node.name;
449
+ case AST_NODE_TYPES.MemberExpression:
450
+ case AST_NODE_TYPES.JSXMemberExpression: return `${toStringFormat(node.object, getText)}.${toStringFormat(node.property, getText)}`;
451
+ case AST_NODE_TYPES.JSXNamespacedName: return `${node.namespace.name}:${node.name.name}`;
452
+ case AST_NODE_TYPES.JSXText: return node.value;
453
+ case AST_NODE_TYPES.Literal: return node.raw;
454
+ default: return getText(node);
455
+ }
456
+ }
457
+
458
+ //#endregion
459
+ //#region src/function-directive.ts
367
460
  /**
368
461
  * Get all directive string literals from a function node
369
462
  * @param node The function AST node
@@ -375,7 +468,7 @@ function getFunctionDirectives(node) {
375
468
  for (const stmt of node.body.body) {
376
469
  if (stmt.type !== AST_NODE_TYPES.ExpressionStatement) continue;
377
470
  const expr = getUnderlyingExpression(stmt.expression);
378
- if (!isLiteral(expr, "string")) continue;
471
+ if (!isDirective(expr)) continue;
379
472
  directives.push(expr);
380
473
  }
381
474
  return directives;
@@ -476,20 +569,33 @@ function hasCallInFunctionInitPath(callName, initPath) {
476
569
 
477
570
  //#endregion
478
571
  //#region src/function-is.ts
572
+ /**
573
+ * Check if a function is empty
574
+ * @param node The function node to check
575
+ * @returns True if the function is empty, false otherwise
576
+ */
479
577
  function isFunctionEmpty(node) {
480
578
  return node.body.type === AST_NODE_TYPES.BlockStatement && node.body.body.length === 0;
481
579
  }
580
+ /**
581
+ * Check if a function is immediately invoked
582
+ * @param node The function node to check
583
+ * @returns True if the function is immediately invoked, false otherwise
584
+ */
482
585
  function isFunctionImmediatelyInvoked(node) {
483
586
  return node.type !== AST_NODE_TYPES.FunctionDeclaration && node.parent.type === AST_NODE_TYPES.CallExpression && node.parent.callee === node;
484
587
  }
485
588
 
486
589
  //#endregion
487
590
  //#region src/identifier-is.ts
488
- function isNaN(node) {
489
- return node != null && node.type === AST_NODE_TYPES.Identifier && node.name === "NaN";
490
- }
491
- function isUndefined(node) {
492
- return node != null && node.type === AST_NODE_TYPES.Identifier && node.name === "undefined";
591
+ /**
592
+ * Check if the given node is an identifier
593
+ * @param node The node to check
594
+ * @param name The name to check
595
+ * @returns True if the node is an identifier, false otherwise
596
+ */
597
+ function isIdentifier(node, name) {
598
+ return node != null && node.type === AST_NODE_TYPES.Identifier && (name == null || node.name === name);
493
599
  }
494
600
 
495
601
  //#endregion
@@ -499,65 +605,23 @@ function isIdentifierName(name) {
499
605
  }
500
606
 
501
607
  //#endregion
502
- //#region src/misc.ts
608
+ //#region src/location.ts
503
609
  /**
504
- * Check if a node is multiline
610
+ * Check if a node spans multiple lines
505
611
  * @param node The AST node to check
506
- * @returns `true` if the node is multiline
612
+ * @returns `true` if the node spans multiple lines, `false` otherwise
507
613
  */
508
614
  function isMultiLine(node) {
509
615
  return node.loc.start.line !== node.loc.end.line;
510
616
  }
511
617
  /**
512
- * Check if a node is a line break
618
+ * Check if a node is a line break (whitespace spanning multiple lines)
513
619
  * @param node The AST node to check
514
- * @returns boolean
620
+ * @returns `true` if the node is a line break, `false` otherwise
515
621
  */
516
622
  function isLineBreak(node) {
517
623
  return isOneOf([AST_NODE_TYPES.Literal, AST_NODE_TYPES.JSXText])(node) && typeof node.value === "string" && node.value.trim() === "" && isMultiLine(node);
518
624
  }
519
- /**
520
- * Get the type of a literal value
521
- * @param input The literal value
522
- * @returns The type of the literal value
523
- */
524
- function getLiteralValueType(input) {
525
- if (input === null) return "null";
526
- return typeof input;
527
- }
528
- /**
529
- * Convert a node type to a delimiter format string
530
- * @param node The AST node
531
- * @param delimiter The delimiter to use
532
- * @returns The delimiter format string
533
- */
534
- function toDelimiterFormat(node, delimiter = " ") {
535
- if (node.type === AST_NODE_TYPES.Literal) {
536
- if ("regex" in node) return "RegExp literal";
537
- return `${getLiteralValueType(node.value)} literal`;
538
- }
539
- if (isJSX(node)) return `JSX ${toLowerCase(delimiterCase(replace(node.type, "JSX", ""), delimiter))}`;
540
- return toLowerCase(delimiterCase(node.type, delimiter));
541
- }
542
- /**
543
- * Incomplete but sufficient stringification of AST nodes for common use cases
544
- * @param node The AST node
545
- * @param getText A function to get the text representation of a node
546
- * @returns A string representation of the node
547
- */
548
- function toStringFormat(node, getText) {
549
- switch (node.type) {
550
- case AST_NODE_TYPES.Identifier:
551
- case AST_NODE_TYPES.JSXIdentifier:
552
- case AST_NODE_TYPES.PrivateIdentifier: return node.name;
553
- case AST_NODE_TYPES.MemberExpression:
554
- case AST_NODE_TYPES.JSXMemberExpression: return `${toStringFormat(node.object, getText)}.${toStringFormat(node.property, getText)}`;
555
- case AST_NODE_TYPES.JSXNamespacedName: return `${node.namespace.name}:${node.name.name}`;
556
- case AST_NODE_TYPES.JSXText: return node.value;
557
- case AST_NODE_TYPES.Literal: return node.raw;
558
- default: return getText(node);
559
- }
560
- }
561
625
 
562
626
  //#endregion
563
627
  //#region src/process-env-node-env.ts
@@ -585,24 +649,6 @@ function isProcessEnvNodeEnvCompare(node, operator, value) {
585
649
  return false;
586
650
  }
587
651
 
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
-
606
652
  //#endregion
607
653
  //#region src/property-name.ts
608
654
  function getPropertyName(node) {
@@ -650,4 +696,4 @@ function isViMockCallback(node) {
650
696
  }
651
697
 
652
698
  //#endregion
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 };
699
+ export { SEL_DISPLAY_NAME_ASSIGNMENT_EXPRESSION, SEL_IMPLICIT_RETURN_ARROW_FUNCTION_EXPRESSION, SEL_OBJECT_DESTRUCTURING_VARIABLE_DECLARATOR, findParentNode, getClassId, getFileDirectives, getFunctionDirectives, getFunctionId, getFunctionInitPath, getNestedCallExpressions, getNestedExpressionsOfType, getNestedIdentifiers, getNestedNewExpressions, getNestedReturnStatements, getPropertyName, getUnderlyingExpression, hasCallInFunctionInitPath, is, isClass, isConditional, isControlFlow, isDirective, isDirectiveKind, 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, toDelimiterFormat, toStringFormat };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/ast",
3
- "version": "2.8.2-beta.0",
3
+ "version": "2.8.2-beta.4",
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.2-beta.0"
37
+ "@eslint-react/eff": "2.8.2-beta.4"
38
38
  },
39
39
  "devDependencies": {
40
40
  "tsdown": "^0.20.1",