@eslint-react/jsx 1.40.4-next.5 → 1.40.4-next.7
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 +40 -47
- package/dist/index.mjs +37 -42
- 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
|
|
|
34
|
+
declare function hasAttribute(name: string, attributes: TSESTree$1.JSXOpeningElement["attributes"], initialScope?: Scope): boolean;
|
|
35
|
+
declare function hasAnyAttribute(names: string[], attributes: TSESTree$1.JSXOpeningElement["attributes"], initialScope?: Scope): boolean;
|
|
36
|
+
declare function hasEveryAttribute(names: string[], attributes: TSESTree$1.JSXOpeningElement["attributes"], initialScope?: Scope): boolean;
|
|
37
|
+
|
|
42
38
|
/**
|
|
43
|
-
*
|
|
39
|
+
* Find the parent JSX attribute node of a node
|
|
40
|
+
* @param node The node to find the parent attribute of
|
|
41
|
+
* @param test The test to apply to the parent attribute
|
|
42
|
+
* @returns The parent attribute node or undefined
|
|
43
|
+
*/
|
|
44
|
+
declare function findParentAttribute(node: TSESTree$1.Node, test?: (node: TSESTree$1.JSXAttribute) => boolean): TSESTree$1.JSXAttribute | _;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Get the stringified type of a JSX element
|
|
44
48
|
* @param node The JSX element node
|
|
45
|
-
* @returns The
|
|
49
|
+
* @returns The type of the element
|
|
46
50
|
*/
|
|
47
|
-
declare function getElementType(node: TSESTree.JSXElement | TSESTree.JSXFragment): string;
|
|
51
|
+
declare function getElementType(node: TSESTree$1.JSXElement | TSESTree$1.JSXFragment): string;
|
|
48
52
|
|
|
49
|
-
declare function
|
|
50
|
-
declare function
|
|
51
|
-
declare function
|
|
53
|
+
declare function isHostElement(node: TSESTree$1.Node): boolean;
|
|
54
|
+
declare function isKeyedElement(node: TSESTree$1.Node, initialScope?: Scope): boolean;
|
|
55
|
+
declare function isFragmentElement(node: TSESTree$1.Node | null | _, allowJSXFragment?: false): node is TSESTree$1.JSXElement;
|
|
56
|
+
declare function isFragmentElement(node: TSESTree$1.Node | null | _, allowJSXFragment?: true): node is TSESTree$1.JSXElement | TSESTree$1.JSXFragment;
|
|
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
|
|
|
34
|
+
declare function hasAttribute(name: string, attributes: TSESTree$1.JSXOpeningElement["attributes"], initialScope?: Scope): boolean;
|
|
35
|
+
declare function hasAnyAttribute(names: string[], attributes: TSESTree$1.JSXOpeningElement["attributes"], initialScope?: Scope): boolean;
|
|
36
|
+
declare function hasEveryAttribute(names: string[], attributes: TSESTree$1.JSXOpeningElement["attributes"], initialScope?: Scope): boolean;
|
|
37
|
+
|
|
42
38
|
/**
|
|
43
|
-
*
|
|
39
|
+
* Find the parent JSX attribute node of a node
|
|
40
|
+
* @param node The node to find the parent attribute of
|
|
41
|
+
* @param test The test to apply to the parent attribute
|
|
42
|
+
* @returns The parent attribute node or undefined
|
|
43
|
+
*/
|
|
44
|
+
declare function findParentAttribute(node: TSESTree$1.Node, test?: (node: TSESTree$1.JSXAttribute) => boolean): TSESTree$1.JSXAttribute | _;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Get the stringified type of a JSX element
|
|
44
48
|
* @param node The JSX element node
|
|
45
|
-
* @returns The
|
|
49
|
+
* @returns The type of the element
|
|
46
50
|
*/
|
|
47
|
-
declare function getElementType(node: TSESTree.JSXElement | TSESTree.JSXFragment): string;
|
|
51
|
+
declare function getElementType(node: TSESTree$1.JSXElement | TSESTree$1.JSXFragment): string;
|
|
48
52
|
|
|
49
|
-
declare function
|
|
50
|
-
declare function
|
|
51
|
-
declare function
|
|
53
|
+
declare function isHostElement(node: TSESTree$1.Node): boolean;
|
|
54
|
+
declare function isKeyedElement(node: TSESTree$1.Node, initialScope?: Scope): boolean;
|
|
55
|
+
declare function isFragmentElement(node: TSESTree$1.Node | null | _, allowJSXFragment?: false): node is TSESTree$1.JSXElement;
|
|
56
|
+
declare function isFragmentElement(node: TSESTree$1.Node | null | _, allowJSXFragment?: true): node is TSESTree$1.JSXElement | TSESTree$1.JSXFragment;
|
|
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,14 +115,8 @@ function getAttributeValue(node, name, initialScope) {
|
|
|
121
115
|
return { kind: "none", node, initialScope };
|
|
122
116
|
}
|
|
123
117
|
}
|
|
124
|
-
function getElementType(node) {
|
|
125
|
-
if (node.type === types.AST_NODE_TYPES.JSXFragment) {
|
|
126
|
-
return "";
|
|
127
|
-
}
|
|
128
|
-
return toString(node.openingElement.name);
|
|
129
|
-
}
|
|
130
118
|
|
|
131
|
-
// src/has
|
|
119
|
+
// src/attribute/has.ts
|
|
132
120
|
function hasAttribute(name, attributes, initialScope) {
|
|
133
121
|
return getAttribute(name, attributes, initialScope) != null;
|
|
134
122
|
}
|
|
@@ -138,6 +126,30 @@ function hasAnyAttribute(names, attributes, initialScope) {
|
|
|
138
126
|
function hasEveryAttribute(names, attributes, initialScope) {
|
|
139
127
|
return names.every((n) => hasAttribute(n, attributes, initialScope));
|
|
140
128
|
}
|
|
129
|
+
function findParentAttribute(node, test = eff.constTrue) {
|
|
130
|
+
const guard = (node2) => {
|
|
131
|
+
return node2.type === types.AST_NODE_TYPES.JSXAttribute && test(node2);
|
|
132
|
+
};
|
|
133
|
+
return AST__namespace.findParentNode(node, guard);
|
|
134
|
+
}
|
|
135
|
+
function getElementType(node) {
|
|
136
|
+
if (node.type === types.AST_NODE_TYPES.JSXFragment) {
|
|
137
|
+
return "";
|
|
138
|
+
}
|
|
139
|
+
return toString(node.openingElement.name);
|
|
140
|
+
}
|
|
141
|
+
function isHostElement(node) {
|
|
142
|
+
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);
|
|
143
|
+
}
|
|
144
|
+
function isKeyedElement(node, initialScope) {
|
|
145
|
+
return node.type === types.AST_NODE_TYPES.JSXElement && hasAttribute("key", node.openingElement.attributes, initialScope);
|
|
146
|
+
}
|
|
147
|
+
function isFragmentElement(node, allowJSXFragment = false) {
|
|
148
|
+
if (node == null) return false;
|
|
149
|
+
if (node.type !== types.AST_NODE_TYPES.JSXElement && node.type !== types.AST_NODE_TYPES.JSXFragment) return false;
|
|
150
|
+
if (node.type === types.AST_NODE_TYPES.JSXFragment) return allowJSXFragment;
|
|
151
|
+
return getElementType(node).split(".").at(-1) === "Fragment";
|
|
152
|
+
}
|
|
141
153
|
|
|
142
154
|
// src/jsx-detection-hint.ts
|
|
143
155
|
var JSXDetectionHint = {
|
|
@@ -156,7 +168,11 @@ var JSXDetectionHint = {
|
|
|
156
168
|
};
|
|
157
169
|
var DEFAULT_JSX_DETECTION_HINT = 0n | JSXDetectionHint.SkipUndefined | JSXDetectionHint.SkipBooleanLiteral;
|
|
158
170
|
|
|
159
|
-
// src/
|
|
171
|
+
// src/jsx-detection.ts
|
|
172
|
+
function isJsxText(node) {
|
|
173
|
+
if (node == null) return false;
|
|
174
|
+
return node.type === types.AST_NODE_TYPES.JSXText || node.type === types.AST_NODE_TYPES.Literal;
|
|
175
|
+
}
|
|
160
176
|
function isJsxLike(code, node, hint = DEFAULT_JSX_DETECTION_HINT) {
|
|
161
177
|
switch (node?.type) {
|
|
162
178
|
case types.AST_NODE_TYPES.JSXText:
|
|
@@ -258,27 +274,6 @@ function isJsxLike(code, node, hint = DEFAULT_JSX_DETECTION_HINT) {
|
|
|
258
274
|
}
|
|
259
275
|
return false;
|
|
260
276
|
}
|
|
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
277
|
|
|
283
278
|
exports.DEFAULT_JSX_DETECTION_HINT = DEFAULT_JSX_DETECTION_HINT;
|
|
284
279
|
exports.JSXDetectionHint = JSXDetectionHint;
|
|
@@ -290,11 +285,9 @@ exports.getElementType = getElementType;
|
|
|
290
285
|
exports.hasAnyAttribute = hasAnyAttribute;
|
|
291
286
|
exports.hasAttribute = hasAttribute;
|
|
292
287
|
exports.hasEveryAttribute = hasEveryAttribute;
|
|
293
|
-
exports.
|
|
294
|
-
exports.
|
|
295
|
-
exports.isJsxFragmentElement = isJsxFragmentElement;
|
|
296
|
-
exports.isJsxKeyedElement = isJsxKeyedElement;
|
|
288
|
+
exports.isFragmentElement = isFragmentElement;
|
|
289
|
+
exports.isHostElement = isHostElement;
|
|
297
290
|
exports.isJsxLike = isJsxLike;
|
|
298
291
|
exports.isJsxText = isJsxText;
|
|
299
|
-
exports.
|
|
292
|
+
exports.isKeyedElement = isKeyedElement;
|
|
300
293
|
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,14 +92,8 @@ function getAttributeValue(node, name, initialScope) {
|
|
|
98
92
|
return { kind: "none", node, initialScope };
|
|
99
93
|
}
|
|
100
94
|
}
|
|
101
|
-
function getElementType(node) {
|
|
102
|
-
if (node.type === AST_NODE_TYPES.JSXFragment) {
|
|
103
|
-
return "";
|
|
104
|
-
}
|
|
105
|
-
return toString(node.openingElement.name);
|
|
106
|
-
}
|
|
107
95
|
|
|
108
|
-
// src/has
|
|
96
|
+
// src/attribute/has.ts
|
|
109
97
|
function hasAttribute(name, attributes, initialScope) {
|
|
110
98
|
return getAttribute(name, attributes, initialScope) != null;
|
|
111
99
|
}
|
|
@@ -115,6 +103,30 @@ function hasAnyAttribute(names, attributes, initialScope) {
|
|
|
115
103
|
function hasEveryAttribute(names, attributes, initialScope) {
|
|
116
104
|
return names.every((n) => hasAttribute(n, attributes, initialScope));
|
|
117
105
|
}
|
|
106
|
+
function findParentAttribute(node, test = constTrue) {
|
|
107
|
+
const guard = (node2) => {
|
|
108
|
+
return node2.type === AST_NODE_TYPES.JSXAttribute && test(node2);
|
|
109
|
+
};
|
|
110
|
+
return AST.findParentNode(node, guard);
|
|
111
|
+
}
|
|
112
|
+
function getElementType(node) {
|
|
113
|
+
if (node.type === AST_NODE_TYPES.JSXFragment) {
|
|
114
|
+
return "";
|
|
115
|
+
}
|
|
116
|
+
return toString(node.openingElement.name);
|
|
117
|
+
}
|
|
118
|
+
function isHostElement(node) {
|
|
119
|
+
return node.type === AST_NODE_TYPES.JSXElement && node.openingElement.name.type === AST_NODE_TYPES.JSXIdentifier && /^[a-z]/u.test(node.openingElement.name.name);
|
|
120
|
+
}
|
|
121
|
+
function isKeyedElement(node, initialScope) {
|
|
122
|
+
return node.type === AST_NODE_TYPES.JSXElement && hasAttribute("key", node.openingElement.attributes, initialScope);
|
|
123
|
+
}
|
|
124
|
+
function isFragmentElement(node, allowJSXFragment = false) {
|
|
125
|
+
if (node == null) return false;
|
|
126
|
+
if (node.type !== AST_NODE_TYPES.JSXElement && node.type !== AST_NODE_TYPES.JSXFragment) return false;
|
|
127
|
+
if (node.type === AST_NODE_TYPES.JSXFragment) return allowJSXFragment;
|
|
128
|
+
return getElementType(node).split(".").at(-1) === "Fragment";
|
|
129
|
+
}
|
|
118
130
|
|
|
119
131
|
// src/jsx-detection-hint.ts
|
|
120
132
|
var JSXDetectionHint = {
|
|
@@ -133,7 +145,11 @@ var JSXDetectionHint = {
|
|
|
133
145
|
};
|
|
134
146
|
var DEFAULT_JSX_DETECTION_HINT = 0n | JSXDetectionHint.SkipUndefined | JSXDetectionHint.SkipBooleanLiteral;
|
|
135
147
|
|
|
136
|
-
// src/
|
|
148
|
+
// src/jsx-detection.ts
|
|
149
|
+
function isJsxText(node) {
|
|
150
|
+
if (node == null) return false;
|
|
151
|
+
return node.type === AST_NODE_TYPES.JSXText || node.type === AST_NODE_TYPES.Literal;
|
|
152
|
+
}
|
|
137
153
|
function isJsxLike(code, node, hint = DEFAULT_JSX_DETECTION_HINT) {
|
|
138
154
|
switch (node?.type) {
|
|
139
155
|
case AST_NODE_TYPES.JSXText:
|
|
@@ -235,26 +251,5 @@ function isJsxLike(code, node, hint = DEFAULT_JSX_DETECTION_HINT) {
|
|
|
235
251
|
}
|
|
236
252
|
return false;
|
|
237
253
|
}
|
|
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
254
|
|
|
260
|
-
export { DEFAULT_JSX_DETECTION_HINT, JSXDetectionHint, findParentAttribute, getAttribute, getAttributeName, getAttributeValue, getElementType, hasAnyAttribute, hasAttribute, hasEveryAttribute,
|
|
255
|
+
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.7",
|
|
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/ast": "1.40.4-next.
|
|
43
|
-
"@eslint-react/eff": "1.40.4-next.
|
|
44
|
-
"@eslint-react/var": "1.40.4-next.
|
|
42
|
+
"@eslint-react/ast": "1.40.4-next.7",
|
|
43
|
+
"@eslint-react/eff": "1.40.4-next.7",
|
|
44
|
+
"@eslint-react/var": "1.40.4-next.7"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"tsup": "^8.4.0",
|