@eslint-react/ast 4.0.2-beta.4 → 4.0.2-beta.6
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 +19 -6
- package/dist/index.js +18 -8
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -32,6 +32,9 @@ type TSESTreeArrayTupleType = TSESTree$1.TSArrayType | TSESTree$1.TSTupleType;
|
|
|
32
32
|
type TSESTreeProperty = TSESTree$1.PropertyDefinition | TSESTree$1.TSIndexSignature | TSESTree$1.TSParameterProperty | TSESTree$1.TSPropertySignature;
|
|
33
33
|
/**
|
|
34
34
|
* Represents all JSX-related nodes in TSESTree
|
|
35
|
+
* Note: This type is for type-level operations. The isJSX() runtime guard in node-is.ts
|
|
36
|
+
* has a slightly different set of nodes as it includes JSXExpressionContainer which is
|
|
37
|
+
* commonly needed for runtime checks but not included in this type union.
|
|
35
38
|
*/
|
|
36
39
|
type TSESTreeJSX = TSESTree$1.JSXAttribute | TSESTree$1.JSXChild | TSESTree$1.JSXClosingElement | TSESTree$1.JSXClosingFragment | TSESTree$1.JSXEmptyExpression | TSESTree$1.JSXIdentifierToken | TSESTree$1.JSXOpeningElement | TSESTree$1.JSXOpeningFragment | TSESTree$1.JSXSpreadAttribute | TSESTree$1.JSXTagNameExpression | TSESTree$1.JSXTextToken;
|
|
37
40
|
type TSESTreeJSXElementLike = TSESTree$1.JSXElement | TSESTree$1.JSXFragment;
|
|
@@ -105,9 +108,12 @@ declare function isDirectiveKind(kind: string): kind is DirectiveKind;
|
|
|
105
108
|
//#endregion
|
|
106
109
|
//#region src/directive-name.d.ts
|
|
107
110
|
/**
|
|
108
|
-
* Check if a string is a directive name
|
|
111
|
+
* Check if a string is a directive name (heuristic check)
|
|
112
|
+
* Note: This is a broad check that matches any string starting with "use ".
|
|
113
|
+
* For strict validation against known directives, use isDirectiveKind.
|
|
109
114
|
* @param name The string to check
|
|
110
|
-
* @returns True if the string
|
|
115
|
+
* @returns True if the string looks like a directive name, false otherwise
|
|
116
|
+
* @see isDirectiveKind
|
|
111
117
|
*/
|
|
112
118
|
declare function isDirectiveName(name: string): boolean;
|
|
113
119
|
//#endregion
|
|
@@ -164,8 +170,8 @@ declare const getNestedCallExpressions: (node: TSESTree.Node) => TSESTree.CallEx
|
|
|
164
170
|
*/
|
|
165
171
|
declare function getFileDirectives(node: TSESTree.Program): TSESTreeDirective[];
|
|
166
172
|
/**
|
|
167
|
-
* Check if a directive with the given name exists in the file
|
|
168
|
-
* @param node The program
|
|
173
|
+
* Check if a directive with the given name exists in the file directives
|
|
174
|
+
* @param node The program AST node
|
|
169
175
|
* @param name The directive name to check (ex: "use strict", "use memo", "use no memo")
|
|
170
176
|
* @returns True if the directive exists, false otherwise
|
|
171
177
|
*/
|
|
@@ -205,7 +211,7 @@ type FunctionID = ReturnType<typeof getFunctionId>;
|
|
|
205
211
|
* Represents various AST paths for React component function declarations
|
|
206
212
|
* Each tuple type represents a specific component definition pattern
|
|
207
213
|
*/
|
|
208
|
-
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];
|
|
214
|
+
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.ClassExpression, TSESTree.ClassBody, TSESTree.MethodDefinition, TSESTreeFunction] | readonly [TSESTree.ClassDeclaration | TSESTree.ClassExpression, TSESTree.ClassBody, TSESTree.PropertyDefinition, TSESTreeFunction];
|
|
209
215
|
/**
|
|
210
216
|
* Identifies the initialization path of a function node in the ast.
|
|
211
217
|
* Determine what kind of component declaration pattern the function belongs to.
|
|
@@ -250,8 +256,10 @@ declare function isIdentifier(node: TSESTree.Node | null, name?: string): node i
|
|
|
250
256
|
//#region src/identifier-name.d.ts
|
|
251
257
|
/**
|
|
252
258
|
* Check if a string is a valid JavaScript identifier name
|
|
259
|
+
* Note: This only checks for ASCII identifiers. Unicode identifiers (e.g., `const 变量 = 1`)
|
|
260
|
+
* are not supported by this simple regex check.
|
|
253
261
|
* @param name The string to check
|
|
254
|
-
* @returns True if the string is a valid identifier name
|
|
262
|
+
* @returns True if the string is a valid ASCII identifier name
|
|
255
263
|
*/
|
|
256
264
|
declare function isIdentifierName(name: string): boolean;
|
|
257
265
|
//#endregion
|
|
@@ -361,8 +369,11 @@ declare const isJSXElementLike: (data: TSESTree.Node | null | undefined) => data
|
|
|
361
369
|
declare const isJSXTagNameExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXIdentifier | TSESTree.JSXMemberExpression | TSESTree.JSXNamespacedName;
|
|
362
370
|
/**
|
|
363
371
|
* Check if a node is a JSX-related node
|
|
372
|
+
* Note: This runtime guard includes JSXExpressionContainer which is commonly needed
|
|
373
|
+
* for AST traversals but not included in the TSESTreeJSX type union.
|
|
364
374
|
* @param node The node to check
|
|
365
375
|
* @returns True if the node is a JSX node
|
|
376
|
+
* @see TSESTreeJSX
|
|
366
377
|
*/
|
|
367
378
|
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;
|
|
368
379
|
/**
|
|
@@ -515,6 +526,8 @@ declare function getPropertyName(node: TSESTree.Node): string | null;
|
|
|
515
526
|
//#region src/property-traverse.d.ts
|
|
516
527
|
/**
|
|
517
528
|
* Recursively traverses an object expression's properties to find a property with the specified name
|
|
529
|
+
* Note: This only handles inline object literals in spread elements. Properties from variables
|
|
530
|
+
* (e.g., `{...props}` where props is a variable) are not resolved.
|
|
518
531
|
* @param properties The properties of the object expression to traverse
|
|
519
532
|
* @param name The name of the property to find
|
|
520
533
|
* @returns The matching property node, or null if not found
|
package/dist/index.js
CHANGED
|
@@ -18,9 +18,12 @@ function getClassId(node) {
|
|
|
18
18
|
//#endregion
|
|
19
19
|
//#region src/directive-name.ts
|
|
20
20
|
/**
|
|
21
|
-
* Check if a string is a directive name
|
|
21
|
+
* Check if a string is a directive name (heuristic check)
|
|
22
|
+
* Note: This is a broad check that matches any string starting with "use ".
|
|
23
|
+
* For strict validation against known directives, use isDirectiveKind.
|
|
22
24
|
* @param name The string to check
|
|
23
|
-
* @returns True if the string
|
|
25
|
+
* @returns True if the string looks like a directive name, false otherwise
|
|
26
|
+
* @see isDirectiveKind
|
|
24
27
|
*/
|
|
25
28
|
function isDirectiveName(name) {
|
|
26
29
|
return name.startsWith("use ") && name.length > 4;
|
|
@@ -282,8 +285,11 @@ const isJSXTagNameExpression = isOneOf([
|
|
|
282
285
|
]);
|
|
283
286
|
/**
|
|
284
287
|
* Check if a node is a JSX-related node
|
|
288
|
+
* Note: This runtime guard includes JSXExpressionContainer which is commonly needed
|
|
289
|
+
* for AST traversals but not included in the TSESTreeJSX type union.
|
|
285
290
|
* @param node The node to check
|
|
286
291
|
* @returns True if the node is a JSX node
|
|
292
|
+
* @see TSESTreeJSX
|
|
287
293
|
*/
|
|
288
294
|
const isJSX = isOneOf([
|
|
289
295
|
AST_NODE_TYPES.JSXAttribute,
|
|
@@ -596,8 +602,8 @@ function getFileDirectives(node) {
|
|
|
596
602
|
return directives;
|
|
597
603
|
}
|
|
598
604
|
/**
|
|
599
|
-
* Check if a directive with the given name exists in the file
|
|
600
|
-
* @param node The program
|
|
605
|
+
* Check if a directive with the given name exists in the file directives
|
|
606
|
+
* @param node The program AST node
|
|
601
607
|
* @param name The directive name to check (ex: "use strict", "use memo", "use no memo")
|
|
602
608
|
* @returns True if the directive exists, false otherwise
|
|
603
609
|
*/
|
|
@@ -693,13 +699,13 @@ function getFunctionInitPath(node) {
|
|
|
693
699
|
parent,
|
|
694
700
|
node
|
|
695
701
|
];
|
|
696
|
-
case parent.type === AST_NODE_TYPES.MethodDefinition
|
|
702
|
+
case parent.type === AST_NODE_TYPES.MethodDefinition: return [
|
|
697
703
|
parent.parent.parent,
|
|
698
704
|
parent.parent,
|
|
699
705
|
parent,
|
|
700
706
|
node
|
|
701
707
|
];
|
|
702
|
-
case parent.type === AST_NODE_TYPES.PropertyDefinition
|
|
708
|
+
case parent.type === AST_NODE_TYPES.PropertyDefinition: return [
|
|
703
709
|
parent.parent.parent,
|
|
704
710
|
parent.parent,
|
|
705
711
|
parent,
|
|
@@ -761,8 +767,10 @@ function isIdentifier(node, name) {
|
|
|
761
767
|
//#region src/identifier-name.ts
|
|
762
768
|
/**
|
|
763
769
|
* Check if a string is a valid JavaScript identifier name
|
|
770
|
+
* Note: This only checks for ASCII identifiers. Unicode identifiers (e.g., `const 变量 = 1`)
|
|
771
|
+
* are not supported by this simple regex check.
|
|
764
772
|
* @param name The string to check
|
|
765
|
-
* @returns True if the string is a valid identifier name
|
|
773
|
+
* @returns True if the string is a valid ASCII identifier name
|
|
766
774
|
*/
|
|
767
775
|
function isIdentifierName(name) {
|
|
768
776
|
return /^[A-Z$_][\w$]*$/i.test(name);
|
|
@@ -818,7 +826,7 @@ const isNodeEqual = dual(2, (a, b) => {
|
|
|
818
826
|
case a.type === AST_NODE_TYPES.PrivateIdentifier && b.type === AST_NODE_TYPES.PrivateIdentifier: return a.name === b.name;
|
|
819
827
|
case a.type === AST_NODE_TYPES.MemberExpression && b.type === AST_NODE_TYPES.MemberExpression: return isNodeEqual(a.property, b.property) && isNodeEqual(a.object, b.object);
|
|
820
828
|
case a.type === AST_NODE_TYPES.JSXAttribute && b.type === AST_NODE_TYPES.JSXAttribute:
|
|
821
|
-
if (a.name
|
|
829
|
+
if (!isNodeEqual(a.name, b.name)) return false;
|
|
822
830
|
if (a.value == null || b.value == null) return a.value === b.value;
|
|
823
831
|
return isNodeEqual(a.value, b.value);
|
|
824
832
|
case a.type === AST_NODE_TYPES.ThisExpression && b.type === AST_NODE_TYPES.ThisExpression: return true;
|
|
@@ -954,6 +962,8 @@ function getPropertyName(node) {
|
|
|
954
962
|
//#region src/property-traverse.ts
|
|
955
963
|
/**
|
|
956
964
|
* Recursively traverses an object expression's properties to find a property with the specified name
|
|
965
|
+
* Note: This only handles inline object literals in spread elements. Properties from variables
|
|
966
|
+
* (e.g., `{...props}` where props is a variable) are not resolved.
|
|
957
967
|
* @param properties The properties of the object expression to traverse
|
|
958
968
|
* @param name The name of the property to find
|
|
959
969
|
* @returns The matching property node, or null if not found
|