@eslint-react/jsx 1.40.4-next.4 → 1.40.4-next.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.mts +34 -42
- package/dist/index.d.ts +34 -42
- package/dist/index.js +35 -40
- package/dist/index.mjs +32 -35
- package/package.json +4 -4
package/dist/index.d.mts
CHANGED
|
@@ -1,16 +1,8 @@
|
|
|
1
1
|
import { _ } from '@eslint-react/eff';
|
|
2
|
-
import { TSESTree } from '@typescript-eslint/types';
|
|
3
2
|
import { Scope } from '@typescript-eslint/scope-manager';
|
|
4
|
-
import { TSESTree
|
|
3
|
+
import { TSESTree } from '@typescript-eslint/utils';
|
|
5
4
|
import * as VAR from '@eslint-react/var';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Find the parent JSX attribute node of a node
|
|
9
|
-
* @param node The node to find the parent attribute of
|
|
10
|
-
* @param test The test to apply to the parent attribute
|
|
11
|
-
* @returns The parent attribute node or undefined
|
|
12
|
-
*/
|
|
13
|
-
declare function findParentAttribute(node: TSESTree.Node, test?: (node: TSESTree.JSXAttribute) => boolean): TSESTree.JSXAttribute | _;
|
|
5
|
+
import { TSESTree as TSESTree$1 } from '@typescript-eslint/types';
|
|
14
6
|
|
|
15
7
|
/**
|
|
16
8
|
* Get the JSX attribute node with the given name
|
|
@@ -19,14 +11,14 @@ declare function findParentAttribute(node: TSESTree.Node, test?: (node: TSESTree
|
|
|
19
11
|
* @param initialScope The initial scope to use for variable resolution
|
|
20
12
|
* @returns The JSX attribute node or undefined
|
|
21
13
|
*/
|
|
22
|
-
declare function getAttribute(name: string, attributes: (TSESTree
|
|
14
|
+
declare function getAttribute(name: string, attributes: (TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute)[], initialScope?: Scope): TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute | _;
|
|
23
15
|
|
|
24
16
|
/**
|
|
25
17
|
* Get the stringified name of a JSX attribute
|
|
26
18
|
* @param node The JSX attribute node
|
|
27
19
|
* @returns The name of the attribute
|
|
28
20
|
*/
|
|
29
|
-
declare function getAttributeName(node: TSESTree
|
|
21
|
+
declare function getAttributeName(node: TSESTree.JSXAttribute): string;
|
|
30
22
|
|
|
31
23
|
/**
|
|
32
24
|
* Get a StaticValue of the attribute value
|
|
@@ -35,20 +27,33 @@ declare function getAttributeName(node: TSESTree$1.JSXAttribute): string;
|
|
|
35
27
|
* @param initialScope The initial scope to use
|
|
36
28
|
* @returns The StaticValue of the attribute value
|
|
37
29
|
*/
|
|
38
|
-
declare function getAttributeValue(node: TSESTree
|
|
30
|
+
declare function getAttributeValue(node: TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute, name: string, initialScope: Scope): Exclude<VAR.LazyValue, {
|
|
39
31
|
kind: "lazy";
|
|
40
32
|
}>;
|
|
41
33
|
|
|
42
34
|
/**
|
|
43
|
-
*
|
|
35
|
+
* Find the parent JSX attribute node of a node
|
|
36
|
+
* @param node The node to find the parent attribute of
|
|
37
|
+
* @param test The test to apply to the parent attribute
|
|
38
|
+
* @returns The parent attribute node or undefined
|
|
39
|
+
*/
|
|
40
|
+
declare function findParentAttribute(node: TSESTree$1.Node, test?: (node: TSESTree$1.JSXAttribute) => boolean): TSESTree$1.JSXAttribute | _;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Get the stringified type of a JSX element
|
|
44
44
|
* @param node The JSX element node
|
|
45
|
-
* @returns The
|
|
45
|
+
* @returns The type of the element
|
|
46
46
|
*/
|
|
47
|
-
declare function getElementType(node: TSESTree.JSXElement | TSESTree.JSXFragment): string;
|
|
47
|
+
declare function getElementType(node: TSESTree$1.JSXElement | TSESTree$1.JSXFragment): string;
|
|
48
|
+
|
|
49
|
+
declare function isHostElement(node: TSESTree$1.Node): boolean;
|
|
50
|
+
declare function isKeyedElement(node: TSESTree$1.Node, initialScope?: Scope): boolean;
|
|
51
|
+
declare function isFragmentElement(node: TSESTree$1.Node | null | _, allowJSXFragment?: false): node is TSESTree$1.JSXElement;
|
|
52
|
+
declare function isFragmentElement(node: TSESTree$1.Node | null | _, allowJSXFragment?: true): node is TSESTree$1.JSXElement | TSESTree$1.JSXFragment;
|
|
48
53
|
|
|
49
|
-
declare function hasAttribute(name: string, attributes: TSESTree.JSXOpeningElement["attributes"], initialScope?: Scope): boolean;
|
|
50
|
-
declare function hasAnyAttribute(names: string[], attributes: TSESTree.JSXOpeningElement["attributes"], initialScope?: Scope): boolean;
|
|
51
|
-
declare function hasEveryAttribute(names: string[], attributes: TSESTree.JSXOpeningElement["attributes"], initialScope?: Scope): boolean;
|
|
54
|
+
declare function hasAttribute(name: string, attributes: TSESTree$1.JSXOpeningElement["attributes"], initialScope?: Scope): boolean;
|
|
55
|
+
declare function hasAnyAttribute(names: string[], attributes: TSESTree$1.JSXOpeningElement["attributes"], initialScope?: Scope): boolean;
|
|
56
|
+
declare function hasEveryAttribute(names: string[], attributes: TSESTree$1.JSXOpeningElement["attributes"], initialScope?: Scope): boolean;
|
|
52
57
|
|
|
53
58
|
type JSXDetectionHint = bigint;
|
|
54
59
|
declare const JSXDetectionHint: {
|
|
@@ -67,6 +72,12 @@ declare const JSXDetectionHint: {
|
|
|
67
72
|
};
|
|
68
73
|
declare const DEFAULT_JSX_DETECTION_HINT: bigint;
|
|
69
74
|
|
|
75
|
+
/**
|
|
76
|
+
* Check if a node is a `JSXText` or a `Literal` node
|
|
77
|
+
* @param node The AST node to check
|
|
78
|
+
* @returns `true` if the node is a `JSXText` or a `Literal` node
|
|
79
|
+
*/
|
|
80
|
+
declare function isJsxText(node: TSESTree.Node | null | _): node is TSESTree.JSXText | TSESTree.Literal;
|
|
70
81
|
/**
|
|
71
82
|
* Heuristic decision to determine if a node is a JSX-like node.
|
|
72
83
|
* @param code The sourceCode object
|
|
@@ -76,33 +87,14 @@ declare const DEFAULT_JSX_DETECTION_HINT: bigint;
|
|
|
76
87
|
* @returns boolean
|
|
77
88
|
*/
|
|
78
89
|
declare function isJsxLike(code: {
|
|
79
|
-
getScope: (node: TSESTree
|
|
80
|
-
}, node: TSESTree
|
|
81
|
-
|
|
82
|
-
declare function isJsxFragmentElement(node: TSESTree.Node): boolean;
|
|
83
|
-
declare function isJsxKeyedElement(node: TSESTree.Node, initialScope?: Scope): boolean;
|
|
84
|
-
declare function isJsxBuiltInElement(node: TSESTree.Node): boolean;
|
|
85
|
-
declare function isJsxUserDefinedElement(node: TSESTree.Node): boolean;
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Check if a node is a `JSXFragment` or a `Fragment` element
|
|
89
|
-
* @param node The AST node to check
|
|
90
|
-
* @returns `true` if the node is a `JSXFragment` or a `Fragment` element
|
|
91
|
-
*/
|
|
92
|
-
declare function isJsxFragment(node: TSESTree.Node | null | _): boolean;
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Check if a node is a `JSXText` or a `Literal` node
|
|
96
|
-
* @param node The AST node to check
|
|
97
|
-
* @returns `true` if the node is a `JSXText` or a `Literal` node
|
|
98
|
-
*/
|
|
99
|
-
declare function isJsxText(node: TSESTree.Node | null | _): node is TSESTree.JSXText | TSESTree.Literal;
|
|
90
|
+
getScope: (node: TSESTree.Node) => Scope;
|
|
91
|
+
}, node: TSESTree.Node | _ | null, hint?: JSXDetectionHint): boolean;
|
|
100
92
|
|
|
101
93
|
/**
|
|
102
94
|
* Get the stringified representation of a JSX node
|
|
103
95
|
* @param node The JSX node
|
|
104
96
|
* @returns The stringified representation
|
|
105
97
|
*/
|
|
106
|
-
declare function toString(node: TSESTree
|
|
98
|
+
declare function toString(node: TSESTree.JSXIdentifier | TSESTree.JSXMemberExpression | TSESTree.JSXNamespacedName | TSESTree.JSXOpeningElement | TSESTree.JSXClosingElement | TSESTree.JSXOpeningFragment | TSESTree.JSXClosingFragment | TSESTree.JSXText): string;
|
|
107
99
|
|
|
108
|
-
export { DEFAULT_JSX_DETECTION_HINT, JSXDetectionHint, findParentAttribute, getAttribute, getAttributeName, getAttributeValue, getElementType, hasAnyAttribute, hasAttribute, hasEveryAttribute,
|
|
100
|
+
export { DEFAULT_JSX_DETECTION_HINT, JSXDetectionHint, findParentAttribute, getAttribute, getAttributeName, getAttributeValue, getElementType, hasAnyAttribute, hasAttribute, hasEveryAttribute, isFragmentElement, isHostElement, isJsxLike, isJsxText, isKeyedElement, toString };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,8 @@
|
|
|
1
1
|
import { _ } from '@eslint-react/eff';
|
|
2
|
-
import { TSESTree } from '@typescript-eslint/types';
|
|
3
2
|
import { Scope } from '@typescript-eslint/scope-manager';
|
|
4
|
-
import { TSESTree
|
|
3
|
+
import { TSESTree } from '@typescript-eslint/utils';
|
|
5
4
|
import * as VAR from '@eslint-react/var';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Find the parent JSX attribute node of a node
|
|
9
|
-
* @param node The node to find the parent attribute of
|
|
10
|
-
* @param test The test to apply to the parent attribute
|
|
11
|
-
* @returns The parent attribute node or undefined
|
|
12
|
-
*/
|
|
13
|
-
declare function findParentAttribute(node: TSESTree.Node, test?: (node: TSESTree.JSXAttribute) => boolean): TSESTree.JSXAttribute | _;
|
|
5
|
+
import { TSESTree as TSESTree$1 } from '@typescript-eslint/types';
|
|
14
6
|
|
|
15
7
|
/**
|
|
16
8
|
* Get the JSX attribute node with the given name
|
|
@@ -19,14 +11,14 @@ declare function findParentAttribute(node: TSESTree.Node, test?: (node: TSESTree
|
|
|
19
11
|
* @param initialScope The initial scope to use for variable resolution
|
|
20
12
|
* @returns The JSX attribute node or undefined
|
|
21
13
|
*/
|
|
22
|
-
declare function getAttribute(name: string, attributes: (TSESTree
|
|
14
|
+
declare function getAttribute(name: string, attributes: (TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute)[], initialScope?: Scope): TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute | _;
|
|
23
15
|
|
|
24
16
|
/**
|
|
25
17
|
* Get the stringified name of a JSX attribute
|
|
26
18
|
* @param node The JSX attribute node
|
|
27
19
|
* @returns The name of the attribute
|
|
28
20
|
*/
|
|
29
|
-
declare function getAttributeName(node: TSESTree
|
|
21
|
+
declare function getAttributeName(node: TSESTree.JSXAttribute): string;
|
|
30
22
|
|
|
31
23
|
/**
|
|
32
24
|
* Get a StaticValue of the attribute value
|
|
@@ -35,20 +27,33 @@ declare function getAttributeName(node: TSESTree$1.JSXAttribute): string;
|
|
|
35
27
|
* @param initialScope The initial scope to use
|
|
36
28
|
* @returns The StaticValue of the attribute value
|
|
37
29
|
*/
|
|
38
|
-
declare function getAttributeValue(node: TSESTree
|
|
30
|
+
declare function getAttributeValue(node: TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute, name: string, initialScope: Scope): Exclude<VAR.LazyValue, {
|
|
39
31
|
kind: "lazy";
|
|
40
32
|
}>;
|
|
41
33
|
|
|
42
34
|
/**
|
|
43
|
-
*
|
|
35
|
+
* Find the parent JSX attribute node of a node
|
|
36
|
+
* @param node The node to find the parent attribute of
|
|
37
|
+
* @param test The test to apply to the parent attribute
|
|
38
|
+
* @returns The parent attribute node or undefined
|
|
39
|
+
*/
|
|
40
|
+
declare function findParentAttribute(node: TSESTree$1.Node, test?: (node: TSESTree$1.JSXAttribute) => boolean): TSESTree$1.JSXAttribute | _;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Get the stringified type of a JSX element
|
|
44
44
|
* @param node The JSX element node
|
|
45
|
-
* @returns The
|
|
45
|
+
* @returns The type of the element
|
|
46
46
|
*/
|
|
47
|
-
declare function getElementType(node: TSESTree.JSXElement | TSESTree.JSXFragment): string;
|
|
47
|
+
declare function getElementType(node: TSESTree$1.JSXElement | TSESTree$1.JSXFragment): string;
|
|
48
|
+
|
|
49
|
+
declare function isHostElement(node: TSESTree$1.Node): boolean;
|
|
50
|
+
declare function isKeyedElement(node: TSESTree$1.Node, initialScope?: Scope): boolean;
|
|
51
|
+
declare function isFragmentElement(node: TSESTree$1.Node | null | _, allowJSXFragment?: false): node is TSESTree$1.JSXElement;
|
|
52
|
+
declare function isFragmentElement(node: TSESTree$1.Node | null | _, allowJSXFragment?: true): node is TSESTree$1.JSXElement | TSESTree$1.JSXFragment;
|
|
48
53
|
|
|
49
|
-
declare function hasAttribute(name: string, attributes: TSESTree.JSXOpeningElement["attributes"], initialScope?: Scope): boolean;
|
|
50
|
-
declare function hasAnyAttribute(names: string[], attributes: TSESTree.JSXOpeningElement["attributes"], initialScope?: Scope): boolean;
|
|
51
|
-
declare function hasEveryAttribute(names: string[], attributes: TSESTree.JSXOpeningElement["attributes"], initialScope?: Scope): boolean;
|
|
54
|
+
declare function hasAttribute(name: string, attributes: TSESTree$1.JSXOpeningElement["attributes"], initialScope?: Scope): boolean;
|
|
55
|
+
declare function hasAnyAttribute(names: string[], attributes: TSESTree$1.JSXOpeningElement["attributes"], initialScope?: Scope): boolean;
|
|
56
|
+
declare function hasEveryAttribute(names: string[], attributes: TSESTree$1.JSXOpeningElement["attributes"], initialScope?: Scope): boolean;
|
|
52
57
|
|
|
53
58
|
type JSXDetectionHint = bigint;
|
|
54
59
|
declare const JSXDetectionHint: {
|
|
@@ -67,6 +72,12 @@ declare const JSXDetectionHint: {
|
|
|
67
72
|
};
|
|
68
73
|
declare const DEFAULT_JSX_DETECTION_HINT: bigint;
|
|
69
74
|
|
|
75
|
+
/**
|
|
76
|
+
* Check if a node is a `JSXText` or a `Literal` node
|
|
77
|
+
* @param node The AST node to check
|
|
78
|
+
* @returns `true` if the node is a `JSXText` or a `Literal` node
|
|
79
|
+
*/
|
|
80
|
+
declare function isJsxText(node: TSESTree.Node | null | _): node is TSESTree.JSXText | TSESTree.Literal;
|
|
70
81
|
/**
|
|
71
82
|
* Heuristic decision to determine if a node is a JSX-like node.
|
|
72
83
|
* @param code The sourceCode object
|
|
@@ -76,33 +87,14 @@ declare const DEFAULT_JSX_DETECTION_HINT: bigint;
|
|
|
76
87
|
* @returns boolean
|
|
77
88
|
*/
|
|
78
89
|
declare function isJsxLike(code: {
|
|
79
|
-
getScope: (node: TSESTree
|
|
80
|
-
}, node: TSESTree
|
|
81
|
-
|
|
82
|
-
declare function isJsxFragmentElement(node: TSESTree.Node): boolean;
|
|
83
|
-
declare function isJsxKeyedElement(node: TSESTree.Node, initialScope?: Scope): boolean;
|
|
84
|
-
declare function isJsxBuiltInElement(node: TSESTree.Node): boolean;
|
|
85
|
-
declare function isJsxUserDefinedElement(node: TSESTree.Node): boolean;
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Check if a node is a `JSXFragment` or a `Fragment` element
|
|
89
|
-
* @param node The AST node to check
|
|
90
|
-
* @returns `true` if the node is a `JSXFragment` or a `Fragment` element
|
|
91
|
-
*/
|
|
92
|
-
declare function isJsxFragment(node: TSESTree.Node | null | _): boolean;
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Check if a node is a `JSXText` or a `Literal` node
|
|
96
|
-
* @param node The AST node to check
|
|
97
|
-
* @returns `true` if the node is a `JSXText` or a `Literal` node
|
|
98
|
-
*/
|
|
99
|
-
declare function isJsxText(node: TSESTree.Node | null | _): node is TSESTree.JSXText | TSESTree.Literal;
|
|
90
|
+
getScope: (node: TSESTree.Node) => Scope;
|
|
91
|
+
}, node: TSESTree.Node | _ | null, hint?: JSXDetectionHint): boolean;
|
|
100
92
|
|
|
101
93
|
/**
|
|
102
94
|
* Get the stringified representation of a JSX node
|
|
103
95
|
* @param node The JSX node
|
|
104
96
|
* @returns The stringified representation
|
|
105
97
|
*/
|
|
106
|
-
declare function toString(node: TSESTree
|
|
98
|
+
declare function toString(node: TSESTree.JSXIdentifier | TSESTree.JSXMemberExpression | TSESTree.JSXNamespacedName | TSESTree.JSXOpeningElement | TSESTree.JSXClosingElement | TSESTree.JSXOpeningFragment | TSESTree.JSXClosingFragment | TSESTree.JSXText): string;
|
|
107
99
|
|
|
108
|
-
export { DEFAULT_JSX_DETECTION_HINT, JSXDetectionHint, findParentAttribute, getAttribute, getAttributeName, getAttributeValue, getElementType, hasAnyAttribute, hasAttribute, hasEveryAttribute,
|
|
100
|
+
export { DEFAULT_JSX_DETECTION_HINT, JSXDetectionHint, findParentAttribute, getAttribute, getAttributeName, getAttributeValue, getElementType, hasAnyAttribute, hasAttribute, hasEveryAttribute, isFragmentElement, isHostElement, isJsxLike, isJsxText, isKeyedElement, toString };
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var AST = require('@eslint-react/ast');
|
|
4
|
-
var eff = require('@eslint-react/eff');
|
|
5
|
-
var types = require('@typescript-eslint/types');
|
|
6
3
|
var VAR = require('@eslint-react/var');
|
|
4
|
+
var types = require('@typescript-eslint/types');
|
|
7
5
|
var tsPattern = require('ts-pattern');
|
|
6
|
+
var AST = require('@eslint-react/ast');
|
|
7
|
+
var eff = require('@eslint-react/eff');
|
|
8
8
|
|
|
9
9
|
function _interopNamespace(e) {
|
|
10
10
|
if (e && e.__esModule) return e;
|
|
@@ -24,16 +24,10 @@ function _interopNamespace(e) {
|
|
|
24
24
|
return Object.freeze(n);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
var AST__namespace = /*#__PURE__*/_interopNamespace(AST);
|
|
28
27
|
var VAR__namespace = /*#__PURE__*/_interopNamespace(VAR);
|
|
28
|
+
var AST__namespace = /*#__PURE__*/_interopNamespace(AST);
|
|
29
29
|
|
|
30
|
-
// src/
|
|
31
|
-
function findParentAttribute(node, test = eff.constTrue) {
|
|
32
|
-
const guard = (node2) => {
|
|
33
|
-
return node2.type === types.AST_NODE_TYPES.JSXAttribute && test(node2);
|
|
34
|
-
};
|
|
35
|
-
return AST__namespace.findParentNode(node, guard);
|
|
36
|
-
}
|
|
30
|
+
// src/attribute/attribute.ts
|
|
37
31
|
function toString(node) {
|
|
38
32
|
switch (node.type) {
|
|
39
33
|
case types.AST_NODE_TYPES.JSXIdentifier:
|
|
@@ -55,12 +49,12 @@ function toString(node) {
|
|
|
55
49
|
}
|
|
56
50
|
}
|
|
57
51
|
|
|
58
|
-
// src/
|
|
52
|
+
// src/attribute/attribute-name.ts
|
|
59
53
|
function getAttributeName(node) {
|
|
60
54
|
return toString(node.name);
|
|
61
55
|
}
|
|
62
56
|
|
|
63
|
-
// src/
|
|
57
|
+
// src/attribute/attribute.ts
|
|
64
58
|
function getAttribute(name, attributes, initialScope) {
|
|
65
59
|
return attributes.findLast((attr) => {
|
|
66
60
|
if (attr.type === types.AST_NODE_TYPES.JSXAttribute) {
|
|
@@ -121,6 +115,12 @@ function getAttributeValue(node, name, initialScope) {
|
|
|
121
115
|
return { kind: "none", node, initialScope };
|
|
122
116
|
}
|
|
123
117
|
}
|
|
118
|
+
function findParentAttribute(node, test = eff.constTrue) {
|
|
119
|
+
const guard = (node2) => {
|
|
120
|
+
return node2.type === types.AST_NODE_TYPES.JSXAttribute && test(node2);
|
|
121
|
+
};
|
|
122
|
+
return AST__namespace.findParentNode(node, guard);
|
|
123
|
+
}
|
|
124
124
|
function getElementType(node) {
|
|
125
125
|
if (node.type === types.AST_NODE_TYPES.JSXFragment) {
|
|
126
126
|
return "";
|
|
@@ -139,6 +139,20 @@ function hasEveryAttribute(names, attributes, initialScope) {
|
|
|
139
139
|
return names.every((n) => hasAttribute(n, attributes, initialScope));
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
+
// src/element/is.ts
|
|
143
|
+
function isHostElement(node) {
|
|
144
|
+
return node.type === types.AST_NODE_TYPES.JSXElement && node.openingElement.name.type === types.AST_NODE_TYPES.JSXIdentifier && /^[a-z]/u.test(node.openingElement.name.name);
|
|
145
|
+
}
|
|
146
|
+
function isKeyedElement(node, initialScope) {
|
|
147
|
+
return node.type === types.AST_NODE_TYPES.JSXElement && hasAttribute("key", node.openingElement.attributes, initialScope);
|
|
148
|
+
}
|
|
149
|
+
function isFragmentElement(node, allowJSXFragment = false) {
|
|
150
|
+
if (node == null) return false;
|
|
151
|
+
if (node.type !== types.AST_NODE_TYPES.JSXElement && node.type !== types.AST_NODE_TYPES.JSXFragment) return false;
|
|
152
|
+
if (node.type === types.AST_NODE_TYPES.JSXFragment) return allowJSXFragment;
|
|
153
|
+
return getElementType(node).split(".").at(-1) === "Fragment";
|
|
154
|
+
}
|
|
155
|
+
|
|
142
156
|
// src/jsx-detection-hint.ts
|
|
143
157
|
var JSXDetectionHint = {
|
|
144
158
|
None: 0n,
|
|
@@ -156,7 +170,11 @@ var JSXDetectionHint = {
|
|
|
156
170
|
};
|
|
157
171
|
var DEFAULT_JSX_DETECTION_HINT = 0n | JSXDetectionHint.SkipUndefined | JSXDetectionHint.SkipBooleanLiteral;
|
|
158
172
|
|
|
159
|
-
// src/
|
|
173
|
+
// src/jsx-detection.ts
|
|
174
|
+
function isJsxText(node) {
|
|
175
|
+
if (node == null) return false;
|
|
176
|
+
return node.type === types.AST_NODE_TYPES.JSXText || node.type === types.AST_NODE_TYPES.Literal;
|
|
177
|
+
}
|
|
160
178
|
function isJsxLike(code, node, hint = DEFAULT_JSX_DETECTION_HINT) {
|
|
161
179
|
switch (node?.type) {
|
|
162
180
|
case types.AST_NODE_TYPES.JSXText:
|
|
@@ -258,27 +276,6 @@ function isJsxLike(code, node, hint = DEFAULT_JSX_DETECTION_HINT) {
|
|
|
258
276
|
}
|
|
259
277
|
return false;
|
|
260
278
|
}
|
|
261
|
-
function isJsxFragmentElement(node) {
|
|
262
|
-
if (node.type !== types.AST_NODE_TYPES.JSXElement) return false;
|
|
263
|
-
return getElementType(node).split(".").at(-1) === "Fragment";
|
|
264
|
-
}
|
|
265
|
-
function isJsxKeyedElement(node, initialScope) {
|
|
266
|
-
return node.type === types.AST_NODE_TYPES.JSXElement && hasAttribute("key", node.openingElement.attributes, initialScope);
|
|
267
|
-
}
|
|
268
|
-
function isJsxBuiltInElement(node) {
|
|
269
|
-
return node.type === types.AST_NODE_TYPES.JSXElement && node.openingElement.name.type === types.AST_NODE_TYPES.JSXIdentifier && /^[a-z]/u.test(node.openingElement.name.name);
|
|
270
|
-
}
|
|
271
|
-
function isJsxUserDefinedElement(node) {
|
|
272
|
-
return node.type === types.AST_NODE_TYPES.JSXElement && node.openingElement.name.type === types.AST_NODE_TYPES.JSXIdentifier && /^[A-Z]/u.test(node.openingElement.name.name);
|
|
273
|
-
}
|
|
274
|
-
function isJsxFragment(node) {
|
|
275
|
-
if (node == null) return false;
|
|
276
|
-
return node.type === types.AST_NODE_TYPES.JSXFragment || isJsxFragmentElement(node);
|
|
277
|
-
}
|
|
278
|
-
function isJsxText(node) {
|
|
279
|
-
if (node == null) return false;
|
|
280
|
-
return node.type === types.AST_NODE_TYPES.JSXText || node.type === types.AST_NODE_TYPES.Literal;
|
|
281
|
-
}
|
|
282
279
|
|
|
283
280
|
exports.DEFAULT_JSX_DETECTION_HINT = DEFAULT_JSX_DETECTION_HINT;
|
|
284
281
|
exports.JSXDetectionHint = JSXDetectionHint;
|
|
@@ -290,11 +287,9 @@ exports.getElementType = getElementType;
|
|
|
290
287
|
exports.hasAnyAttribute = hasAnyAttribute;
|
|
291
288
|
exports.hasAttribute = hasAttribute;
|
|
292
289
|
exports.hasEveryAttribute = hasEveryAttribute;
|
|
293
|
-
exports.
|
|
294
|
-
exports.
|
|
295
|
-
exports.isJsxFragmentElement = isJsxFragmentElement;
|
|
296
|
-
exports.isJsxKeyedElement = isJsxKeyedElement;
|
|
290
|
+
exports.isFragmentElement = isFragmentElement;
|
|
291
|
+
exports.isHostElement = isHostElement;
|
|
297
292
|
exports.isJsxLike = isJsxLike;
|
|
298
293
|
exports.isJsxText = isJsxText;
|
|
299
|
-
exports.
|
|
294
|
+
exports.isKeyedElement = isKeyedElement;
|
|
300
295
|
exports.toString = toString;
|
package/dist/index.mjs
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
import * as AST from '@eslint-react/ast';
|
|
2
|
-
import { constTrue } from '@eslint-react/eff';
|
|
3
|
-
import { AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
4
1
|
import * as VAR from '@eslint-react/var';
|
|
2
|
+
import { AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
5
3
|
import { match, P } from 'ts-pattern';
|
|
4
|
+
import * as AST from '@eslint-react/ast';
|
|
5
|
+
import { constTrue } from '@eslint-react/eff';
|
|
6
6
|
|
|
7
|
-
// src/
|
|
8
|
-
function findParentAttribute(node, test = constTrue) {
|
|
9
|
-
const guard = (node2) => {
|
|
10
|
-
return node2.type === AST_NODE_TYPES.JSXAttribute && test(node2);
|
|
11
|
-
};
|
|
12
|
-
return AST.findParentNode(node, guard);
|
|
13
|
-
}
|
|
7
|
+
// src/attribute/attribute.ts
|
|
14
8
|
function toString(node) {
|
|
15
9
|
switch (node.type) {
|
|
16
10
|
case AST_NODE_TYPES.JSXIdentifier:
|
|
@@ -32,12 +26,12 @@ function toString(node) {
|
|
|
32
26
|
}
|
|
33
27
|
}
|
|
34
28
|
|
|
35
|
-
// src/
|
|
29
|
+
// src/attribute/attribute-name.ts
|
|
36
30
|
function getAttributeName(node) {
|
|
37
31
|
return toString(node.name);
|
|
38
32
|
}
|
|
39
33
|
|
|
40
|
-
// src/
|
|
34
|
+
// src/attribute/attribute.ts
|
|
41
35
|
function getAttribute(name, attributes, initialScope) {
|
|
42
36
|
return attributes.findLast((attr) => {
|
|
43
37
|
if (attr.type === AST_NODE_TYPES.JSXAttribute) {
|
|
@@ -98,6 +92,12 @@ function getAttributeValue(node, name, initialScope) {
|
|
|
98
92
|
return { kind: "none", node, initialScope };
|
|
99
93
|
}
|
|
100
94
|
}
|
|
95
|
+
function findParentAttribute(node, test = constTrue) {
|
|
96
|
+
const guard = (node2) => {
|
|
97
|
+
return node2.type === AST_NODE_TYPES.JSXAttribute && test(node2);
|
|
98
|
+
};
|
|
99
|
+
return AST.findParentNode(node, guard);
|
|
100
|
+
}
|
|
101
101
|
function getElementType(node) {
|
|
102
102
|
if (node.type === AST_NODE_TYPES.JSXFragment) {
|
|
103
103
|
return "";
|
|
@@ -116,6 +116,20 @@ function hasEveryAttribute(names, attributes, initialScope) {
|
|
|
116
116
|
return names.every((n) => hasAttribute(n, attributes, initialScope));
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
+
// src/element/is.ts
|
|
120
|
+
function isHostElement(node) {
|
|
121
|
+
return node.type === AST_NODE_TYPES.JSXElement && node.openingElement.name.type === AST_NODE_TYPES.JSXIdentifier && /^[a-z]/u.test(node.openingElement.name.name);
|
|
122
|
+
}
|
|
123
|
+
function isKeyedElement(node, initialScope) {
|
|
124
|
+
return node.type === AST_NODE_TYPES.JSXElement && hasAttribute("key", node.openingElement.attributes, initialScope);
|
|
125
|
+
}
|
|
126
|
+
function isFragmentElement(node, allowJSXFragment = false) {
|
|
127
|
+
if (node == null) return false;
|
|
128
|
+
if (node.type !== AST_NODE_TYPES.JSXElement && node.type !== AST_NODE_TYPES.JSXFragment) return false;
|
|
129
|
+
if (node.type === AST_NODE_TYPES.JSXFragment) return allowJSXFragment;
|
|
130
|
+
return getElementType(node).split(".").at(-1) === "Fragment";
|
|
131
|
+
}
|
|
132
|
+
|
|
119
133
|
// src/jsx-detection-hint.ts
|
|
120
134
|
var JSXDetectionHint = {
|
|
121
135
|
None: 0n,
|
|
@@ -133,7 +147,11 @@ var JSXDetectionHint = {
|
|
|
133
147
|
};
|
|
134
148
|
var DEFAULT_JSX_DETECTION_HINT = 0n | JSXDetectionHint.SkipUndefined | JSXDetectionHint.SkipBooleanLiteral;
|
|
135
149
|
|
|
136
|
-
// src/
|
|
150
|
+
// src/jsx-detection.ts
|
|
151
|
+
function isJsxText(node) {
|
|
152
|
+
if (node == null) return false;
|
|
153
|
+
return node.type === AST_NODE_TYPES.JSXText || node.type === AST_NODE_TYPES.Literal;
|
|
154
|
+
}
|
|
137
155
|
function isJsxLike(code, node, hint = DEFAULT_JSX_DETECTION_HINT) {
|
|
138
156
|
switch (node?.type) {
|
|
139
157
|
case AST_NODE_TYPES.JSXText:
|
|
@@ -235,26 +253,5 @@ function isJsxLike(code, node, hint = DEFAULT_JSX_DETECTION_HINT) {
|
|
|
235
253
|
}
|
|
236
254
|
return false;
|
|
237
255
|
}
|
|
238
|
-
function isJsxFragmentElement(node) {
|
|
239
|
-
if (node.type !== AST_NODE_TYPES.JSXElement) return false;
|
|
240
|
-
return getElementType(node).split(".").at(-1) === "Fragment";
|
|
241
|
-
}
|
|
242
|
-
function isJsxKeyedElement(node, initialScope) {
|
|
243
|
-
return node.type === AST_NODE_TYPES.JSXElement && hasAttribute("key", node.openingElement.attributes, initialScope);
|
|
244
|
-
}
|
|
245
|
-
function isJsxBuiltInElement(node) {
|
|
246
|
-
return node.type === AST_NODE_TYPES.JSXElement && node.openingElement.name.type === AST_NODE_TYPES.JSXIdentifier && /^[a-z]/u.test(node.openingElement.name.name);
|
|
247
|
-
}
|
|
248
|
-
function isJsxUserDefinedElement(node) {
|
|
249
|
-
return node.type === AST_NODE_TYPES.JSXElement && node.openingElement.name.type === AST_NODE_TYPES.JSXIdentifier && /^[A-Z]/u.test(node.openingElement.name.name);
|
|
250
|
-
}
|
|
251
|
-
function isJsxFragment(node) {
|
|
252
|
-
if (node == null) return false;
|
|
253
|
-
return node.type === AST_NODE_TYPES.JSXFragment || isJsxFragmentElement(node);
|
|
254
|
-
}
|
|
255
|
-
function isJsxText(node) {
|
|
256
|
-
if (node == null) return false;
|
|
257
|
-
return node.type === AST_NODE_TYPES.JSXText || node.type === AST_NODE_TYPES.Literal;
|
|
258
|
-
}
|
|
259
256
|
|
|
260
|
-
export { DEFAULT_JSX_DETECTION_HINT, JSXDetectionHint, findParentAttribute, getAttribute, getAttributeName, getAttributeValue, getElementType, hasAnyAttribute, hasAttribute, hasEveryAttribute,
|
|
257
|
+
export { DEFAULT_JSX_DETECTION_HINT, JSXDetectionHint, findParentAttribute, getAttribute, getAttributeName, getAttributeValue, getElementType, hasAnyAttribute, hasAttribute, hasEveryAttribute, isFragmentElement, isHostElement, isJsxLike, isJsxText, isKeyedElement, toString };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/jsx",
|
|
3
|
-
"version": "1.40.4-next.
|
|
3
|
+
"version": "1.40.4-next.6",
|
|
4
4
|
"description": "ESLint React's TSESTree AST utility module for static analysis of JSX.",
|
|
5
5
|
"homepage": "https://github.com/Rel1cx/eslint-react",
|
|
6
6
|
"bugs": {
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
"@typescript-eslint/types": "^8.29.0",
|
|
40
40
|
"@typescript-eslint/utils": "^8.29.0",
|
|
41
41
|
"ts-pattern": "^5.7.0",
|
|
42
|
-
"@eslint-react/
|
|
43
|
-
"@eslint-react/
|
|
44
|
-
"@eslint-react/
|
|
42
|
+
"@eslint-react/var": "1.40.4-next.6",
|
|
43
|
+
"@eslint-react/ast": "1.40.4-next.6",
|
|
44
|
+
"@eslint-react/eff": "1.40.4-next.6"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"tsup": "^8.4.0",
|