@eslint-react/jsx 1.24.0-next.8 → 1.24.0
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 +69 -31
- package/dist/index.d.ts +69 -31
- package/dist/index.js +70 -329
- package/dist/index.mjs +67 -325
- package/package.json +5 -5
package/dist/index.d.mts
CHANGED
|
@@ -1,40 +1,54 @@
|
|
|
1
1
|
import { _ } from '@eslint-react/eff';
|
|
2
2
|
import { TSESTree } from '@typescript-eslint/types';
|
|
3
|
-
import * as VAR from '@eslint-react/var';
|
|
4
3
|
import { Scope } from '@typescript-eslint/scope-manager';
|
|
5
4
|
import { TSESTree as TSESTree$1 } from '@typescript-eslint/utils';
|
|
5
|
+
import * as VAR from '@eslint-react/var';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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 | _;
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
|
-
*
|
|
16
|
-
* @param
|
|
17
|
-
* @
|
|
16
|
+
* Get the JSX attribute node with the given name
|
|
17
|
+
* @param name The name of the attribute
|
|
18
|
+
* @param attributes The attributes to search
|
|
19
|
+
* @param initialScope The initial scope to use for variable resolution
|
|
20
|
+
* @returns The JSX attribute node or undefined
|
|
18
21
|
*/
|
|
19
|
-
declare function
|
|
22
|
+
declare function getAttribute(name: string, attributes: (TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute)[], initialScope?: Scope): TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute | _;
|
|
20
23
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Get the stringified name of a JSX attribute
|
|
26
|
+
* @param node The JSX attribute node
|
|
27
|
+
* @returns The name of the attribute
|
|
28
|
+
*/
|
|
29
|
+
declare function getAttributeName(node: TSESTree$1.JSXAttribute): string;
|
|
24
30
|
|
|
25
|
-
declare function isKeyedElement(node: TSESTree.Node, initialScope: Scope): boolean;
|
|
26
31
|
/**
|
|
27
|
-
*
|
|
28
|
-
* @param node The
|
|
29
|
-
* @
|
|
32
|
+
* Get a StaticValue of the attribute value
|
|
33
|
+
* @param node The JSX attribute node
|
|
34
|
+
* @param name The name of the attribute
|
|
35
|
+
* @param initialScope The initial scope to use
|
|
36
|
+
* @returns The StaticValue of the attribute value
|
|
30
37
|
*/
|
|
31
|
-
declare function
|
|
38
|
+
declare function getAttributeValue(node: TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute, name: string, initialScope: Scope): Exclude<VAR.LazyValue, {
|
|
39
|
+
kind: "lazy";
|
|
40
|
+
}>;
|
|
41
|
+
|
|
32
42
|
/**
|
|
33
|
-
*
|
|
34
|
-
* @param node The
|
|
35
|
-
* @returns
|
|
43
|
+
* Get the stringified name of a JSX element
|
|
44
|
+
* @param node The JSX element node
|
|
45
|
+
* @returns The name of the element
|
|
36
46
|
*/
|
|
37
|
-
declare function
|
|
47
|
+
declare function getElementName(node: TSESTree.JSXElement | TSESTree.JSXFragment): string;
|
|
48
|
+
|
|
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;
|
|
38
52
|
|
|
39
53
|
declare const JSXValueHint: {
|
|
40
54
|
readonly None: 0n;
|
|
@@ -52,7 +66,7 @@ declare const JSXValueHint: {
|
|
|
52
66
|
};
|
|
53
67
|
declare const DEFAULT_JSX_VALUE_HINT: bigint;
|
|
54
68
|
/**
|
|
55
|
-
*
|
|
69
|
+
* Heruistic decision to determine if a node is a JSX value
|
|
56
70
|
* @param node The AST node to check
|
|
57
71
|
* @param jsxCtx The requirements for the check
|
|
58
72
|
* @param jsxCtx.getScope The function to get the scope of a node
|
|
@@ -63,6 +77,32 @@ declare function isJSXValue(node: TSESTree$1.Node | _ | null, jsxCtx: {
|
|
|
63
77
|
getScope: (node: TSESTree$1.Node) => Scope;
|
|
64
78
|
}, hint?: bigint): boolean;
|
|
65
79
|
|
|
80
|
+
/**
|
|
81
|
+
* Check if a node is a Fragment element
|
|
82
|
+
* @param node The AST node to check
|
|
83
|
+
* @returns `true` if the node is a `JSXElement` of `Fragment` type
|
|
84
|
+
*/
|
|
85
|
+
declare function isFragmentElement(node: TSESTree.Node): boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Check if a node has a `key` prop
|
|
88
|
+
* @param node The AST node to check
|
|
89
|
+
* @param initialScope The initial scope to start searching for the `key` attribute
|
|
90
|
+
* @returns `true` if the node is a `JSXElement` of `Keyed Component` type
|
|
91
|
+
*/
|
|
92
|
+
declare function isKeyedElement(node: TSESTree.Node, initialScope?: Scope): boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Check if a node is a `JSXFragment` of `Built-in Component` type
|
|
95
|
+
* @param node The AST node to check
|
|
96
|
+
* @returns `true` if the node is a `JSXFragment` of `Built-in Component` type
|
|
97
|
+
*/
|
|
98
|
+
declare function isBuiltInElement(node: TSESTree.Node): boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Check if a node is a `JSXElement` of `User-Defined Component` type
|
|
101
|
+
* @param node The AST node to check
|
|
102
|
+
* @returns `true` if the node is a `JSXElement` of `User-Defined Component` type
|
|
103
|
+
*/
|
|
104
|
+
declare function isUserDefinedElement(node: TSESTree.Node): boolean;
|
|
105
|
+
|
|
66
106
|
/**
|
|
67
107
|
* Check if a node is a Literal or JSXText
|
|
68
108
|
* @param node The AST node to check
|
|
@@ -89,12 +129,10 @@ declare function isLineBreak(node: TSESTree.Node): boolean;
|
|
|
89
129
|
declare function isPaddingSpaces(node: TSESTree.Node): boolean;
|
|
90
130
|
|
|
91
131
|
/**
|
|
92
|
-
*
|
|
93
|
-
* @param
|
|
94
|
-
* @returns The
|
|
132
|
+
* Get the stringified representation of a JSX node
|
|
133
|
+
* @param node The JSX node
|
|
134
|
+
* @returns The stringified representation
|
|
95
135
|
*/
|
|
96
|
-
declare function
|
|
97
|
-
|
|
98
|
-
declare const xhtmlEntities: Record<string, string>;
|
|
136
|
+
declare function toString(node: TSESTree$1.JSXIdentifier | TSESTree$1.JSXMemberExpression | TSESTree$1.JSXNamespacedName | TSESTree$1.JSXOpeningElement | TSESTree$1.JSXClosingElement | TSESTree$1.JSXOpeningFragment | TSESTree$1.JSXClosingFragment | TSESTree$1.JSXText): string;
|
|
99
137
|
|
|
100
|
-
export { DEFAULT_JSX_VALUE_HINT, JSXValueHint,
|
|
138
|
+
export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, findParentAttribute, getAttribute, getAttributeName, getAttributeValue, getElementName, hasAnyAttribute, hasAttribute, hasEveryAttribute, isBuiltInElement, isFragmentElement, isJSXValue, isKeyedElement, isLineBreak, isLiteral, isPaddingSpaces, isUserDefinedElement, isWhiteSpace, toString };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,40 +1,54 @@
|
|
|
1
1
|
import { _ } from '@eslint-react/eff';
|
|
2
2
|
import { TSESTree } from '@typescript-eslint/types';
|
|
3
|
-
import * as VAR from '@eslint-react/var';
|
|
4
3
|
import { Scope } from '@typescript-eslint/scope-manager';
|
|
5
4
|
import { TSESTree as TSESTree$1 } from '@typescript-eslint/utils';
|
|
5
|
+
import * as VAR from '@eslint-react/var';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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 | _;
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
|
-
*
|
|
16
|
-
* @param
|
|
17
|
-
* @
|
|
16
|
+
* Get the JSX attribute node with the given name
|
|
17
|
+
* @param name The name of the attribute
|
|
18
|
+
* @param attributes The attributes to search
|
|
19
|
+
* @param initialScope The initial scope to use for variable resolution
|
|
20
|
+
* @returns The JSX attribute node or undefined
|
|
18
21
|
*/
|
|
19
|
-
declare function
|
|
22
|
+
declare function getAttribute(name: string, attributes: (TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute)[], initialScope?: Scope): TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute | _;
|
|
20
23
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Get the stringified name of a JSX attribute
|
|
26
|
+
* @param node The JSX attribute node
|
|
27
|
+
* @returns The name of the attribute
|
|
28
|
+
*/
|
|
29
|
+
declare function getAttributeName(node: TSESTree$1.JSXAttribute): string;
|
|
24
30
|
|
|
25
|
-
declare function isKeyedElement(node: TSESTree.Node, initialScope: Scope): boolean;
|
|
26
31
|
/**
|
|
27
|
-
*
|
|
28
|
-
* @param node The
|
|
29
|
-
* @
|
|
32
|
+
* Get a StaticValue of the attribute value
|
|
33
|
+
* @param node The JSX attribute node
|
|
34
|
+
* @param name The name of the attribute
|
|
35
|
+
* @param initialScope The initial scope to use
|
|
36
|
+
* @returns The StaticValue of the attribute value
|
|
30
37
|
*/
|
|
31
|
-
declare function
|
|
38
|
+
declare function getAttributeValue(node: TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute, name: string, initialScope: Scope): Exclude<VAR.LazyValue, {
|
|
39
|
+
kind: "lazy";
|
|
40
|
+
}>;
|
|
41
|
+
|
|
32
42
|
/**
|
|
33
|
-
*
|
|
34
|
-
* @param node The
|
|
35
|
-
* @returns
|
|
43
|
+
* Get the stringified name of a JSX element
|
|
44
|
+
* @param node The JSX element node
|
|
45
|
+
* @returns The name of the element
|
|
36
46
|
*/
|
|
37
|
-
declare function
|
|
47
|
+
declare function getElementName(node: TSESTree.JSXElement | TSESTree.JSXFragment): string;
|
|
48
|
+
|
|
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;
|
|
38
52
|
|
|
39
53
|
declare const JSXValueHint: {
|
|
40
54
|
readonly None: 0n;
|
|
@@ -52,7 +66,7 @@ declare const JSXValueHint: {
|
|
|
52
66
|
};
|
|
53
67
|
declare const DEFAULT_JSX_VALUE_HINT: bigint;
|
|
54
68
|
/**
|
|
55
|
-
*
|
|
69
|
+
* Heruistic decision to determine if a node is a JSX value
|
|
56
70
|
* @param node The AST node to check
|
|
57
71
|
* @param jsxCtx The requirements for the check
|
|
58
72
|
* @param jsxCtx.getScope The function to get the scope of a node
|
|
@@ -63,6 +77,32 @@ declare function isJSXValue(node: TSESTree$1.Node | _ | null, jsxCtx: {
|
|
|
63
77
|
getScope: (node: TSESTree$1.Node) => Scope;
|
|
64
78
|
}, hint?: bigint): boolean;
|
|
65
79
|
|
|
80
|
+
/**
|
|
81
|
+
* Check if a node is a Fragment element
|
|
82
|
+
* @param node The AST node to check
|
|
83
|
+
* @returns `true` if the node is a `JSXElement` of `Fragment` type
|
|
84
|
+
*/
|
|
85
|
+
declare function isFragmentElement(node: TSESTree.Node): boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Check if a node has a `key` prop
|
|
88
|
+
* @param node The AST node to check
|
|
89
|
+
* @param initialScope The initial scope to start searching for the `key` attribute
|
|
90
|
+
* @returns `true` if the node is a `JSXElement` of `Keyed Component` type
|
|
91
|
+
*/
|
|
92
|
+
declare function isKeyedElement(node: TSESTree.Node, initialScope?: Scope): boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Check if a node is a `JSXFragment` of `Built-in Component` type
|
|
95
|
+
* @param node The AST node to check
|
|
96
|
+
* @returns `true` if the node is a `JSXFragment` of `Built-in Component` type
|
|
97
|
+
*/
|
|
98
|
+
declare function isBuiltInElement(node: TSESTree.Node): boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Check if a node is a `JSXElement` of `User-Defined Component` type
|
|
101
|
+
* @param node The AST node to check
|
|
102
|
+
* @returns `true` if the node is a `JSXElement` of `User-Defined Component` type
|
|
103
|
+
*/
|
|
104
|
+
declare function isUserDefinedElement(node: TSESTree.Node): boolean;
|
|
105
|
+
|
|
66
106
|
/**
|
|
67
107
|
* Check if a node is a Literal or JSXText
|
|
68
108
|
* @param node The AST node to check
|
|
@@ -89,12 +129,10 @@ declare function isLineBreak(node: TSESTree.Node): boolean;
|
|
|
89
129
|
declare function isPaddingSpaces(node: TSESTree.Node): boolean;
|
|
90
130
|
|
|
91
131
|
/**
|
|
92
|
-
*
|
|
93
|
-
* @param
|
|
94
|
-
* @returns The
|
|
132
|
+
* Get the stringified representation of a JSX node
|
|
133
|
+
* @param node The JSX node
|
|
134
|
+
* @returns The stringified representation
|
|
95
135
|
*/
|
|
96
|
-
declare function
|
|
97
|
-
|
|
98
|
-
declare const xhtmlEntities: Record<string, string>;
|
|
136
|
+
declare function toString(node: TSESTree$1.JSXIdentifier | TSESTree$1.JSXMemberExpression | TSESTree$1.JSXNamespacedName | TSESTree$1.JSXOpeningElement | TSESTree$1.JSXClosingElement | TSESTree$1.JSXOpeningFragment | TSESTree$1.JSXClosingFragment | TSESTree$1.JSXText): string;
|
|
99
137
|
|
|
100
|
-
export { DEFAULT_JSX_VALUE_HINT, JSXValueHint,
|
|
138
|
+
export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, findParentAttribute, getAttribute, getAttributeName, getAttributeValue, getElementName, hasAnyAttribute, hasAttribute, hasEveryAttribute, isBuiltInElement, isFragmentElement, isJSXValue, isKeyedElement, isLineBreak, isLiteral, isPaddingSpaces, isUserDefinedElement, isWhiteSpace, toString };
|
package/dist/index.js
CHANGED
|
@@ -27,26 +27,46 @@ function _interopNamespace(e) {
|
|
|
27
27
|
var AST3__namespace = /*#__PURE__*/_interopNamespace(AST3);
|
|
28
28
|
var VAR__namespace = /*#__PURE__*/_interopNamespace(VAR);
|
|
29
29
|
|
|
30
|
-
// src/find-parent-attribute
|
|
31
|
-
function
|
|
30
|
+
// src/find-parent-attribute.ts
|
|
31
|
+
function findParentAttribute(node, test = eff.returnTrue) {
|
|
32
32
|
const guard = (node2) => {
|
|
33
33
|
return node2.type === types.AST_NODE_TYPES.JSXAttribute && test(node2);
|
|
34
34
|
};
|
|
35
35
|
return AST3__namespace.findParentNode(node, guard);
|
|
36
36
|
}
|
|
37
|
-
function
|
|
38
|
-
switch (node.
|
|
37
|
+
function toString(node) {
|
|
38
|
+
switch (node.type) {
|
|
39
39
|
case types.AST_NODE_TYPES.JSXIdentifier:
|
|
40
|
-
return node.name
|
|
40
|
+
return node.name;
|
|
41
41
|
case types.AST_NODE_TYPES.JSXNamespacedName:
|
|
42
|
-
return `${node.
|
|
42
|
+
return `${node.namespace.name}:${node.name.name}`;
|
|
43
|
+
case types.AST_NODE_TYPES.JSXMemberExpression:
|
|
44
|
+
return `${toString(node.object)}.${toString(node.property)}`;
|
|
45
|
+
case types.AST_NODE_TYPES.JSXText:
|
|
46
|
+
return node.value;
|
|
47
|
+
case types.AST_NODE_TYPES.JSXOpeningElement:
|
|
48
|
+
return `<${toString(node.name)}>`;
|
|
49
|
+
case types.AST_NODE_TYPES.JSXClosingElement:
|
|
50
|
+
return `</${toString(node.name)}>`;
|
|
51
|
+
case types.AST_NODE_TYPES.JSXOpeningFragment:
|
|
52
|
+
return "<>";
|
|
53
|
+
case types.AST_NODE_TYPES.JSXClosingFragment:
|
|
54
|
+
return "</>";
|
|
43
55
|
}
|
|
44
56
|
}
|
|
45
|
-
|
|
57
|
+
|
|
58
|
+
// src/get-attribute-name.ts
|
|
59
|
+
function getAttributeName(node) {
|
|
60
|
+
return toString(node.name);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// src/get-attribute.ts
|
|
64
|
+
function getAttribute(name, attributes, initialScope) {
|
|
46
65
|
return attributes.findLast((attr) => {
|
|
47
66
|
if (attr.type === types.AST_NODE_TYPES.JSXAttribute) {
|
|
48
67
|
return getAttributeName(attr) === name;
|
|
49
68
|
}
|
|
69
|
+
if (initialScope == null) return false;
|
|
50
70
|
switch (attr.argument.type) {
|
|
51
71
|
case types.AST_NODE_TYPES.Identifier: {
|
|
52
72
|
const variable = VAR__namespace.findVariable(attr.argument.name, initialScope);
|
|
@@ -62,7 +82,7 @@ function getAttributeNode(name, initialScope, attributes) {
|
|
|
62
82
|
return false;
|
|
63
83
|
});
|
|
64
84
|
}
|
|
65
|
-
function
|
|
85
|
+
function getAttributeValue(node, name, initialScope) {
|
|
66
86
|
switch (node.type) {
|
|
67
87
|
case types.AST_NODE_TYPES.JSXAttribute:
|
|
68
88
|
if (node.value?.type === types.AST_NODE_TYPES.Literal) {
|
|
@@ -74,71 +94,49 @@ function getAttributeStaticValue(node, initialScope) {
|
|
|
74
94
|
};
|
|
75
95
|
}
|
|
76
96
|
if (node.value?.type === types.AST_NODE_TYPES.JSXExpressionContainer) {
|
|
77
|
-
return {
|
|
97
|
+
return VAR__namespace.toStaticValue({
|
|
78
98
|
kind: "lazy",
|
|
79
99
|
node: node.value.expression,
|
|
80
100
|
initialScope
|
|
81
|
-
};
|
|
101
|
+
});
|
|
82
102
|
}
|
|
83
103
|
return { kind: "none", node, initialScope };
|
|
84
|
-
case types.AST_NODE_TYPES.JSXSpreadAttribute:
|
|
85
|
-
|
|
104
|
+
case types.AST_NODE_TYPES.JSXSpreadAttribute: {
|
|
105
|
+
const staticValue = VAR__namespace.toStaticValue({
|
|
86
106
|
kind: "lazy",
|
|
87
107
|
node: node.argument,
|
|
88
108
|
initialScope
|
|
89
|
-
};
|
|
109
|
+
});
|
|
110
|
+
if (staticValue.kind === "none") {
|
|
111
|
+
return staticValue;
|
|
112
|
+
}
|
|
113
|
+
return tsPattern.match(staticValue.value).with({ [name]: tsPattern.P.select(tsPattern.P.any) }, (value) => ({
|
|
114
|
+
kind: "some",
|
|
115
|
+
node: node.argument,
|
|
116
|
+
initialScope,
|
|
117
|
+
value
|
|
118
|
+
})).otherwise(() => ({ kind: "none", node, initialScope }));
|
|
119
|
+
}
|
|
90
120
|
default:
|
|
91
121
|
return { kind: "none", node, initialScope };
|
|
92
122
|
}
|
|
93
123
|
}
|
|
94
|
-
function getAttributeStringValue(name, node, initialScope) {
|
|
95
|
-
if (node == null) return eff._;
|
|
96
|
-
const attributeValue = getAttributeStaticValue(node, initialScope);
|
|
97
|
-
const attributeValueResolved = VAR__namespace.toResolved(attributeValue).value;
|
|
98
|
-
return tsPattern.match(attributeValueResolved).with(tsPattern.P.string, eff.identity).with({ [name]: tsPattern.P.select(tsPattern.P.string) }, eff.identity).otherwise(() => eff._);
|
|
99
|
-
}
|
|
100
|
-
function resolveJSXMemberExpressions(object, property) {
|
|
101
|
-
if (object.type === types.AST_NODE_TYPES.JSXMemberExpression) {
|
|
102
|
-
return `${resolveJSXMemberExpressions(object.object, object.property)}.${property.name}`;
|
|
103
|
-
}
|
|
104
|
-
if (object.type === types.AST_NODE_TYPES.JSXNamespacedName) {
|
|
105
|
-
return `${object.namespace.name}:${object.name.name}.${property.name}`;
|
|
106
|
-
}
|
|
107
|
-
return `${object.name}.${property.name}`;
|
|
108
|
-
}
|
|
109
124
|
function getElementName(node) {
|
|
110
|
-
if (node.type === types.AST_NODE_TYPES.
|
|
111
|
-
return "
|
|
112
|
-
}
|
|
113
|
-
const { name } = node;
|
|
114
|
-
if (name.type === types.AST_NODE_TYPES.JSXMemberExpression) {
|
|
115
|
-
const { object, property } = name;
|
|
116
|
-
return resolveJSXMemberExpressions(object, property);
|
|
117
|
-
}
|
|
118
|
-
if (name.type === types.AST_NODE_TYPES.JSXNamespacedName) {
|
|
119
|
-
return `${name.namespace.name}:${name.name.name}`;
|
|
125
|
+
if (node.type === types.AST_NODE_TYPES.JSXFragment) {
|
|
126
|
+
return "";
|
|
120
127
|
}
|
|
121
|
-
return
|
|
128
|
+
return toString(node.openingElement.name);
|
|
122
129
|
}
|
|
123
130
|
|
|
124
131
|
// src/has-attribute.ts
|
|
125
|
-
function hasAttribute(name,
|
|
126
|
-
return
|
|
132
|
+
function hasAttribute(name, attributes, initialScope) {
|
|
133
|
+
return getAttribute(name, attributes, initialScope) != null;
|
|
127
134
|
}
|
|
128
|
-
function hasAnyAttribute(names,
|
|
129
|
-
return names.some((n) => hasAttribute(n,
|
|
135
|
+
function hasAnyAttribute(names, attributes, initialScope) {
|
|
136
|
+
return names.some((n) => hasAttribute(n, attributes, initialScope));
|
|
130
137
|
}
|
|
131
|
-
function hasEveryAttribute(names,
|
|
132
|
-
return names.every((n) => hasAttribute(n,
|
|
133
|
-
}
|
|
134
|
-
function isKeyedElement(node, initialScope) {
|
|
135
|
-
return node.type === types.AST_NODE_TYPES.JSXElement && hasAttribute("key", initialScope, node.openingElement.attributes);
|
|
136
|
-
}
|
|
137
|
-
function isBuiltInElement(node) {
|
|
138
|
-
return node.type === types.AST_NODE_TYPES.JSXElement && node.openingElement.name.type === types.AST_NODE_TYPES.JSXIdentifier && node.openingElement.name.name.toLowerCase() === node.openingElement.name.name && /^[a-z]/u.test(node.openingElement.name.name);
|
|
139
|
-
}
|
|
140
|
-
function isUserDefinedElement(node) {
|
|
141
|
-
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);
|
|
138
|
+
function hasEveryAttribute(names, attributes, initialScope) {
|
|
139
|
+
return names.every((n) => hasAttribute(n, attributes, initialScope));
|
|
142
140
|
}
|
|
143
141
|
var JSXValueHint = {
|
|
144
142
|
None: 0n,
|
|
@@ -245,6 +243,19 @@ function isJSXValue(node, jsxCtx, hint = DEFAULT_JSX_VALUE_HINT) {
|
|
|
245
243
|
}
|
|
246
244
|
return false;
|
|
247
245
|
}
|
|
246
|
+
function isFragmentElement(node) {
|
|
247
|
+
if (node.type !== types.AST_NODE_TYPES.JSXElement) return false;
|
|
248
|
+
return getElementName(node).split(".").at(-1) === "Fragment";
|
|
249
|
+
}
|
|
250
|
+
function isKeyedElement(node, initialScope) {
|
|
251
|
+
return node.type === types.AST_NODE_TYPES.JSXElement && hasAttribute("key", node.openingElement.attributes, initialScope);
|
|
252
|
+
}
|
|
253
|
+
function isBuiltInElement(node) {
|
|
254
|
+
return node.type === types.AST_NODE_TYPES.JSXElement && node.openingElement.name.type === types.AST_NODE_TYPES.JSXIdentifier && node.openingElement.name.name.toLowerCase() === node.openingElement.name.name && /^[a-z]/u.test(node.openingElement.name.name);
|
|
255
|
+
}
|
|
256
|
+
function isUserDefinedElement(node) {
|
|
257
|
+
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);
|
|
258
|
+
}
|
|
248
259
|
var isLiteral = AST3__namespace.isOneOf([types.AST_NODE_TYPES.Literal, types.AST_NODE_TYPES.JSXText]);
|
|
249
260
|
function isWhiteSpace(node) {
|
|
250
261
|
return typeof node.value === "string" && node.value.trim() === "";
|
|
@@ -256,287 +267,18 @@ function isPaddingSpaces(node) {
|
|
|
256
267
|
return isLiteral(node) && isWhiteSpace(node) && node.raw.includes("\n");
|
|
257
268
|
}
|
|
258
269
|
|
|
259
|
-
// src/xhtml-entities.ts
|
|
260
|
-
var xhtmlEntities = {
|
|
261
|
-
Aacute: "\xC1",
|
|
262
|
-
aacute: "\xE1",
|
|
263
|
-
Acirc: "\xC2",
|
|
264
|
-
acirc: "\xE2",
|
|
265
|
-
acute: "\xB4",
|
|
266
|
-
AElig: "\xC6",
|
|
267
|
-
aelig: "\xE6",
|
|
268
|
-
Agrave: "\xC0",
|
|
269
|
-
agrave: "\xE0",
|
|
270
|
-
alefsym: "\u2135",
|
|
271
|
-
Alpha: "\u0391",
|
|
272
|
-
alpha: "\u03B1",
|
|
273
|
-
amp: "&",
|
|
274
|
-
and: "\u2227",
|
|
275
|
-
ang: "\u2220",
|
|
276
|
-
apos: "'",
|
|
277
|
-
Aring: "\xC5",
|
|
278
|
-
aring: "\xE5",
|
|
279
|
-
asymp: "\u2248",
|
|
280
|
-
Atilde: "\xC3",
|
|
281
|
-
atilde: "\xE3",
|
|
282
|
-
Auml: "\xC4",
|
|
283
|
-
auml: "\xE4",
|
|
284
|
-
bdquo: "\u201E",
|
|
285
|
-
Beta: "\u0392",
|
|
286
|
-
beta: "\u03B2",
|
|
287
|
-
brvbar: "\xA6",
|
|
288
|
-
bull: "\u2022",
|
|
289
|
-
cap: "\u2229",
|
|
290
|
-
Ccedil: "\xC7",
|
|
291
|
-
ccedil: "\xE7",
|
|
292
|
-
cedil: "\xB8",
|
|
293
|
-
cent: "\xA2",
|
|
294
|
-
Chi: "\u03A7",
|
|
295
|
-
chi: "\u03C7",
|
|
296
|
-
circ: "\u02C6",
|
|
297
|
-
clubs: "\u2663",
|
|
298
|
-
cong: "\u2245",
|
|
299
|
-
copy: "\xA9",
|
|
300
|
-
crarr: "\u21B5",
|
|
301
|
-
cup: "\u222A",
|
|
302
|
-
curren: "\xA4",
|
|
303
|
-
dagger: "\u2020",
|
|
304
|
-
Dagger: "\u2021",
|
|
305
|
-
darr: "\u2193",
|
|
306
|
-
dArr: "\u21D3",
|
|
307
|
-
deg: "\xB0",
|
|
308
|
-
Delta: "\u0394",
|
|
309
|
-
delta: "\u03B4",
|
|
310
|
-
diams: "\u2666",
|
|
311
|
-
divide: "\xF7",
|
|
312
|
-
Eacute: "\xC9",
|
|
313
|
-
eacute: "\xE9",
|
|
314
|
-
Ecirc: "\xCA",
|
|
315
|
-
ecirc: "\xEA",
|
|
316
|
-
Egrave: "\xC8",
|
|
317
|
-
egrave: "\xE8",
|
|
318
|
-
empty: "\u2205",
|
|
319
|
-
emsp: "\u2003",
|
|
320
|
-
ensp: "\u2002",
|
|
321
|
-
Epsilon: "\u0395",
|
|
322
|
-
epsilon: "\u03B5",
|
|
323
|
-
equiv: "\u2261",
|
|
324
|
-
Eta: "\u0397",
|
|
325
|
-
eta: "\u03B7",
|
|
326
|
-
ETH: "\xD0",
|
|
327
|
-
eth: "\xF0",
|
|
328
|
-
Euml: "\xCB",
|
|
329
|
-
euml: "\xEB",
|
|
330
|
-
euro: "\u20AC",
|
|
331
|
-
exist: "\u2203",
|
|
332
|
-
fnof: "\u0192",
|
|
333
|
-
forall: "\u2200",
|
|
334
|
-
frac12: "\xBD",
|
|
335
|
-
frac14: "\xBC",
|
|
336
|
-
frac34: "\xBE",
|
|
337
|
-
frasl: "\u2044",
|
|
338
|
-
Gamma: "\u0393",
|
|
339
|
-
gamma: "\u03B3",
|
|
340
|
-
ge: "\u2265",
|
|
341
|
-
gt: ">",
|
|
342
|
-
harr: "\u2194",
|
|
343
|
-
hArr: "\u21D4",
|
|
344
|
-
hearts: "\u2665",
|
|
345
|
-
hellip: "\u2026",
|
|
346
|
-
Iacute: "\xCD",
|
|
347
|
-
iacute: "\xED",
|
|
348
|
-
Icirc: "\xCE",
|
|
349
|
-
icirc: "\xEE",
|
|
350
|
-
iexcl: "\xA1",
|
|
351
|
-
Igrave: "\xCC",
|
|
352
|
-
igrave: "\xEC",
|
|
353
|
-
image: "\u2111",
|
|
354
|
-
infin: "\u221E",
|
|
355
|
-
int: "\u222B",
|
|
356
|
-
Iota: "\u0399",
|
|
357
|
-
iota: "\u03B9",
|
|
358
|
-
iquest: "\xBF",
|
|
359
|
-
isin: "\u2208",
|
|
360
|
-
Iuml: "\xCF",
|
|
361
|
-
iuml: "\xEF",
|
|
362
|
-
Kappa: "\u039A",
|
|
363
|
-
kappa: "\u03BA",
|
|
364
|
-
Lambda: "\u039B",
|
|
365
|
-
lambda: "\u03BB",
|
|
366
|
-
lang: "\u2329",
|
|
367
|
-
laquo: "\xAB",
|
|
368
|
-
larr: "\u2190",
|
|
369
|
-
lArr: "\u21D0",
|
|
370
|
-
lceil: "\u2308",
|
|
371
|
-
ldquo: "\u201C",
|
|
372
|
-
le: "\u2264",
|
|
373
|
-
lfloor: "\u230A",
|
|
374
|
-
lowast: "\u2217",
|
|
375
|
-
loz: "\u25CA",
|
|
376
|
-
lrm: "\u200E",
|
|
377
|
-
lsaquo: "\u2039",
|
|
378
|
-
lsquo: "\u2018",
|
|
379
|
-
lt: "<",
|
|
380
|
-
macr: "\xAF",
|
|
381
|
-
mdash: "\u2014",
|
|
382
|
-
micro: "\xB5",
|
|
383
|
-
middot: "\xB7",
|
|
384
|
-
minus: "\u2212",
|
|
385
|
-
Mu: "\u039C",
|
|
386
|
-
mu: "\u03BC",
|
|
387
|
-
nabla: "\u2207",
|
|
388
|
-
nbsp: "\xA0",
|
|
389
|
-
ndash: "\u2013",
|
|
390
|
-
ne: "\u2260",
|
|
391
|
-
ni: "\u220B",
|
|
392
|
-
not: "\xAC",
|
|
393
|
-
notin: "\u2209",
|
|
394
|
-
nsub: "\u2284",
|
|
395
|
-
Ntilde: "\xD1",
|
|
396
|
-
ntilde: "\xF1",
|
|
397
|
-
Nu: "\u039D",
|
|
398
|
-
nu: "\u03BD",
|
|
399
|
-
Oacute: "\xD3",
|
|
400
|
-
oacute: "\xF3",
|
|
401
|
-
Ocirc: "\xD4",
|
|
402
|
-
ocirc: "\xF4",
|
|
403
|
-
OElig: "\u0152",
|
|
404
|
-
oelig: "\u0153",
|
|
405
|
-
Ograve: "\xD2",
|
|
406
|
-
ograve: "\xF2",
|
|
407
|
-
oline: "\u203E",
|
|
408
|
-
Omega: "\u03A9",
|
|
409
|
-
omega: "\u03C9",
|
|
410
|
-
Omicron: "\u039F",
|
|
411
|
-
omicron: "\u03BF",
|
|
412
|
-
oplus: "\u2295",
|
|
413
|
-
or: "\u2228",
|
|
414
|
-
ordf: "\xAA",
|
|
415
|
-
ordm: "\xBA",
|
|
416
|
-
Oslash: "\xD8",
|
|
417
|
-
oslash: "\xF8",
|
|
418
|
-
Otilde: "\xD5",
|
|
419
|
-
otilde: "\xF5",
|
|
420
|
-
otimes: "\u2297",
|
|
421
|
-
Ouml: "\xD6",
|
|
422
|
-
ouml: "\xF6",
|
|
423
|
-
para: "\xB6",
|
|
424
|
-
part: "\u2202",
|
|
425
|
-
permil: "\u2030",
|
|
426
|
-
perp: "\u22A5",
|
|
427
|
-
Phi: "\u03A6",
|
|
428
|
-
phi: "\u03C6",
|
|
429
|
-
Pi: "\u03A0",
|
|
430
|
-
pi: "\u03C0",
|
|
431
|
-
piv: "\u03D6",
|
|
432
|
-
plusmn: "\xB1",
|
|
433
|
-
pound: "\xA3",
|
|
434
|
-
prime: "\u2032",
|
|
435
|
-
Prime: "\u2033",
|
|
436
|
-
prod: "\u220F",
|
|
437
|
-
prop: "\u221D",
|
|
438
|
-
Psi: "\u03A8",
|
|
439
|
-
psi: "\u03C8",
|
|
440
|
-
quot: '"',
|
|
441
|
-
radic: "\u221A",
|
|
442
|
-
rang: "\u232A",
|
|
443
|
-
raquo: "\xBB",
|
|
444
|
-
rarr: "\u2192",
|
|
445
|
-
rArr: "\u21D2",
|
|
446
|
-
rceil: "\u2309",
|
|
447
|
-
rdquo: "\u201D",
|
|
448
|
-
real: "\u211C",
|
|
449
|
-
reg: "\xAE",
|
|
450
|
-
rfloor: "\u230B",
|
|
451
|
-
Rho: "\u03A1",
|
|
452
|
-
rho: "\u03C1",
|
|
453
|
-
rlm: "\u200F",
|
|
454
|
-
rsaquo: "\u203A",
|
|
455
|
-
rsquo: "\u2019",
|
|
456
|
-
sbquo: "\u201A",
|
|
457
|
-
Scaron: "\u0160",
|
|
458
|
-
scaron: "\u0161",
|
|
459
|
-
sdot: "\u22C5",
|
|
460
|
-
sect: "\xA7",
|
|
461
|
-
shy: "\xAD",
|
|
462
|
-
Sigma: "\u03A3",
|
|
463
|
-
sigma: "\u03C3",
|
|
464
|
-
sigmaf: "\u03C2",
|
|
465
|
-
sim: "\u223C",
|
|
466
|
-
spades: "\u2660",
|
|
467
|
-
sub: "\u2282",
|
|
468
|
-
sube: "\u2286",
|
|
469
|
-
sum: "\u2211",
|
|
470
|
-
sup: "\u2283",
|
|
471
|
-
sup1: "\xB9",
|
|
472
|
-
sup2: "\xB2",
|
|
473
|
-
sup3: "\xB3",
|
|
474
|
-
supe: "\u2287",
|
|
475
|
-
szlig: "\xDF",
|
|
476
|
-
Tau: "\u03A4",
|
|
477
|
-
tau: "\u03C4",
|
|
478
|
-
there4: "\u2234",
|
|
479
|
-
Theta: "\u0398",
|
|
480
|
-
theta: "\u03B8",
|
|
481
|
-
thetasym: "\u03D1",
|
|
482
|
-
thinsp: "\u2009",
|
|
483
|
-
THORN: "\xDE",
|
|
484
|
-
thorn: "\xFE",
|
|
485
|
-
tilde: "\u02DC",
|
|
486
|
-
times: "\xD7",
|
|
487
|
-
trade: "\u2122",
|
|
488
|
-
Uacute: "\xDA",
|
|
489
|
-
uacute: "\xFA",
|
|
490
|
-
uarr: "\u2191",
|
|
491
|
-
uArr: "\u21D1",
|
|
492
|
-
Ucirc: "\xDB",
|
|
493
|
-
ucirc: "\xFB",
|
|
494
|
-
Ugrave: "\xD9",
|
|
495
|
-
ugrave: "\xF9",
|
|
496
|
-
uml: "\xA8",
|
|
497
|
-
upsih: "\u03D2",
|
|
498
|
-
Upsilon: "\u03A5",
|
|
499
|
-
upsilon: "\u03C5",
|
|
500
|
-
Uuml: "\xDC",
|
|
501
|
-
uuml: "\xFC",
|
|
502
|
-
weierp: "\u2118",
|
|
503
|
-
Xi: "\u039E",
|
|
504
|
-
xi: "\u03BE",
|
|
505
|
-
Yacute: "\xDD",
|
|
506
|
-
yacute: "\xFD",
|
|
507
|
-
yen: "\xA5",
|
|
508
|
-
yuml: "\xFF",
|
|
509
|
-
Yuml: "\u0178",
|
|
510
|
-
Zeta: "\u0396",
|
|
511
|
-
zeta: "\u03B6",
|
|
512
|
-
zwj: "\u200D",
|
|
513
|
-
zwnj: "\u200C"
|
|
514
|
-
};
|
|
515
|
-
|
|
516
|
-
// src/unescape-string-literal-text.ts
|
|
517
|
-
function unescapeStringLiteralText(text) {
|
|
518
|
-
return text.replaceAll(/&(?:#\d+|#x[\da-fA-F]+|[0-9a-zA-Z]+);/g, (entity) => {
|
|
519
|
-
const item = entity.slice(1, -1);
|
|
520
|
-
if (item[0] === "#") {
|
|
521
|
-
const codePoint = item[1] === "x" ? parseInt(item.slice(2), 16) : parseInt(item.slice(1), 10);
|
|
522
|
-
return codePoint > 1114111 ? entity : String.fromCodePoint(codePoint);
|
|
523
|
-
}
|
|
524
|
-
return xhtmlEntities[item] ?? entity;
|
|
525
|
-
});
|
|
526
|
-
}
|
|
527
|
-
|
|
528
270
|
exports.DEFAULT_JSX_VALUE_HINT = DEFAULT_JSX_VALUE_HINT;
|
|
529
271
|
exports.JSXValueHint = JSXValueHint;
|
|
530
|
-
exports.
|
|
272
|
+
exports.findParentAttribute = findParentAttribute;
|
|
273
|
+
exports.getAttribute = getAttribute;
|
|
531
274
|
exports.getAttributeName = getAttributeName;
|
|
532
|
-
exports.
|
|
533
|
-
exports.getAttributeStaticValue = getAttributeStaticValue;
|
|
534
|
-
exports.getAttributeStringValue = getAttributeStringValue;
|
|
275
|
+
exports.getAttributeValue = getAttributeValue;
|
|
535
276
|
exports.getElementName = getElementName;
|
|
536
277
|
exports.hasAnyAttribute = hasAnyAttribute;
|
|
537
278
|
exports.hasAttribute = hasAttribute;
|
|
538
279
|
exports.hasEveryAttribute = hasEveryAttribute;
|
|
539
280
|
exports.isBuiltInElement = isBuiltInElement;
|
|
281
|
+
exports.isFragmentElement = isFragmentElement;
|
|
540
282
|
exports.isJSXValue = isJSXValue;
|
|
541
283
|
exports.isKeyedElement = isKeyedElement;
|
|
542
284
|
exports.isLineBreak = isLineBreak;
|
|
@@ -544,5 +286,4 @@ exports.isLiteral = isLiteral;
|
|
|
544
286
|
exports.isPaddingSpaces = isPaddingSpaces;
|
|
545
287
|
exports.isUserDefinedElement = isUserDefinedElement;
|
|
546
288
|
exports.isWhiteSpace = isWhiteSpace;
|
|
547
|
-
exports.
|
|
548
|
-
exports.xhtmlEntities = xhtmlEntities;
|
|
289
|
+
exports.toString = toString;
|
package/dist/index.mjs
CHANGED
|
@@ -1,29 +1,49 @@
|
|
|
1
1
|
import * as AST3 from '@eslint-react/ast';
|
|
2
|
-
import { returnTrue
|
|
2
|
+
import { returnTrue } from '@eslint-react/eff';
|
|
3
3
|
import { AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
4
4
|
import * as VAR from '@eslint-react/var';
|
|
5
5
|
import { match, P } from 'ts-pattern';
|
|
6
6
|
|
|
7
|
-
// src/find-parent-attribute
|
|
8
|
-
function
|
|
7
|
+
// src/find-parent-attribute.ts
|
|
8
|
+
function findParentAttribute(node, test = returnTrue) {
|
|
9
9
|
const guard = (node2) => {
|
|
10
10
|
return node2.type === AST_NODE_TYPES.JSXAttribute && test(node2);
|
|
11
11
|
};
|
|
12
12
|
return AST3.findParentNode(node, guard);
|
|
13
13
|
}
|
|
14
|
-
function
|
|
15
|
-
switch (node.
|
|
14
|
+
function toString(node) {
|
|
15
|
+
switch (node.type) {
|
|
16
16
|
case AST_NODE_TYPES.JSXIdentifier:
|
|
17
|
-
return node.name
|
|
17
|
+
return node.name;
|
|
18
18
|
case AST_NODE_TYPES.JSXNamespacedName:
|
|
19
|
-
return `${node.
|
|
19
|
+
return `${node.namespace.name}:${node.name.name}`;
|
|
20
|
+
case AST_NODE_TYPES.JSXMemberExpression:
|
|
21
|
+
return `${toString(node.object)}.${toString(node.property)}`;
|
|
22
|
+
case AST_NODE_TYPES.JSXText:
|
|
23
|
+
return node.value;
|
|
24
|
+
case AST_NODE_TYPES.JSXOpeningElement:
|
|
25
|
+
return `<${toString(node.name)}>`;
|
|
26
|
+
case AST_NODE_TYPES.JSXClosingElement:
|
|
27
|
+
return `</${toString(node.name)}>`;
|
|
28
|
+
case AST_NODE_TYPES.JSXOpeningFragment:
|
|
29
|
+
return "<>";
|
|
30
|
+
case AST_NODE_TYPES.JSXClosingFragment:
|
|
31
|
+
return "</>";
|
|
20
32
|
}
|
|
21
33
|
}
|
|
22
|
-
|
|
34
|
+
|
|
35
|
+
// src/get-attribute-name.ts
|
|
36
|
+
function getAttributeName(node) {
|
|
37
|
+
return toString(node.name);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// src/get-attribute.ts
|
|
41
|
+
function getAttribute(name, attributes, initialScope) {
|
|
23
42
|
return attributes.findLast((attr) => {
|
|
24
43
|
if (attr.type === AST_NODE_TYPES.JSXAttribute) {
|
|
25
44
|
return getAttributeName(attr) === name;
|
|
26
45
|
}
|
|
46
|
+
if (initialScope == null) return false;
|
|
27
47
|
switch (attr.argument.type) {
|
|
28
48
|
case AST_NODE_TYPES.Identifier: {
|
|
29
49
|
const variable = VAR.findVariable(attr.argument.name, initialScope);
|
|
@@ -39,7 +59,7 @@ function getAttributeNode(name, initialScope, attributes) {
|
|
|
39
59
|
return false;
|
|
40
60
|
});
|
|
41
61
|
}
|
|
42
|
-
function
|
|
62
|
+
function getAttributeValue(node, name, initialScope) {
|
|
43
63
|
switch (node.type) {
|
|
44
64
|
case AST_NODE_TYPES.JSXAttribute:
|
|
45
65
|
if (node.value?.type === AST_NODE_TYPES.Literal) {
|
|
@@ -51,71 +71,49 @@ function getAttributeStaticValue(node, initialScope) {
|
|
|
51
71
|
};
|
|
52
72
|
}
|
|
53
73
|
if (node.value?.type === AST_NODE_TYPES.JSXExpressionContainer) {
|
|
54
|
-
return {
|
|
74
|
+
return VAR.toStaticValue({
|
|
55
75
|
kind: "lazy",
|
|
56
76
|
node: node.value.expression,
|
|
57
77
|
initialScope
|
|
58
|
-
};
|
|
78
|
+
});
|
|
59
79
|
}
|
|
60
80
|
return { kind: "none", node, initialScope };
|
|
61
|
-
case AST_NODE_TYPES.JSXSpreadAttribute:
|
|
62
|
-
|
|
81
|
+
case AST_NODE_TYPES.JSXSpreadAttribute: {
|
|
82
|
+
const staticValue = VAR.toStaticValue({
|
|
63
83
|
kind: "lazy",
|
|
64
84
|
node: node.argument,
|
|
65
85
|
initialScope
|
|
66
|
-
};
|
|
86
|
+
});
|
|
87
|
+
if (staticValue.kind === "none") {
|
|
88
|
+
return staticValue;
|
|
89
|
+
}
|
|
90
|
+
return match(staticValue.value).with({ [name]: P.select(P.any) }, (value) => ({
|
|
91
|
+
kind: "some",
|
|
92
|
+
node: node.argument,
|
|
93
|
+
initialScope,
|
|
94
|
+
value
|
|
95
|
+
})).otherwise(() => ({ kind: "none", node, initialScope }));
|
|
96
|
+
}
|
|
67
97
|
default:
|
|
68
98
|
return { kind: "none", node, initialScope };
|
|
69
99
|
}
|
|
70
100
|
}
|
|
71
|
-
function getAttributeStringValue(name, node, initialScope) {
|
|
72
|
-
if (node == null) return _;
|
|
73
|
-
const attributeValue = getAttributeStaticValue(node, initialScope);
|
|
74
|
-
const attributeValueResolved = VAR.toResolved(attributeValue).value;
|
|
75
|
-
return match(attributeValueResolved).with(P.string, identity).with({ [name]: P.select(P.string) }, identity).otherwise(() => _);
|
|
76
|
-
}
|
|
77
|
-
function resolveJSXMemberExpressions(object, property) {
|
|
78
|
-
if (object.type === AST_NODE_TYPES.JSXMemberExpression) {
|
|
79
|
-
return `${resolveJSXMemberExpressions(object.object, object.property)}.${property.name}`;
|
|
80
|
-
}
|
|
81
|
-
if (object.type === AST_NODE_TYPES.JSXNamespacedName) {
|
|
82
|
-
return `${object.namespace.name}:${object.name.name}.${property.name}`;
|
|
83
|
-
}
|
|
84
|
-
return `${object.name}.${property.name}`;
|
|
85
|
-
}
|
|
86
101
|
function getElementName(node) {
|
|
87
|
-
if (node.type === AST_NODE_TYPES.
|
|
88
|
-
return "
|
|
89
|
-
}
|
|
90
|
-
const { name } = node;
|
|
91
|
-
if (name.type === AST_NODE_TYPES.JSXMemberExpression) {
|
|
92
|
-
const { object, property } = name;
|
|
93
|
-
return resolveJSXMemberExpressions(object, property);
|
|
94
|
-
}
|
|
95
|
-
if (name.type === AST_NODE_TYPES.JSXNamespacedName) {
|
|
96
|
-
return `${name.namespace.name}:${name.name.name}`;
|
|
102
|
+
if (node.type === AST_NODE_TYPES.JSXFragment) {
|
|
103
|
+
return "";
|
|
97
104
|
}
|
|
98
|
-
return
|
|
105
|
+
return toString(node.openingElement.name);
|
|
99
106
|
}
|
|
100
107
|
|
|
101
108
|
// src/has-attribute.ts
|
|
102
|
-
function hasAttribute(name,
|
|
103
|
-
return
|
|
104
|
-
}
|
|
105
|
-
function hasAnyAttribute(names, initialScope, attributes) {
|
|
106
|
-
return names.some((n) => hasAttribute(n, initialScope, attributes));
|
|
107
|
-
}
|
|
108
|
-
function hasEveryAttribute(names, initialScope, attributes) {
|
|
109
|
-
return names.every((n) => hasAttribute(n, initialScope, attributes));
|
|
109
|
+
function hasAttribute(name, attributes, initialScope) {
|
|
110
|
+
return getAttribute(name, attributes, initialScope) != null;
|
|
110
111
|
}
|
|
111
|
-
function
|
|
112
|
-
return
|
|
113
|
-
}
|
|
114
|
-
function isBuiltInElement(node) {
|
|
115
|
-
return node.type === AST_NODE_TYPES.JSXElement && node.openingElement.name.type === AST_NODE_TYPES.JSXIdentifier && node.openingElement.name.name.toLowerCase() === node.openingElement.name.name && /^[a-z]/u.test(node.openingElement.name.name);
|
|
112
|
+
function hasAnyAttribute(names, attributes, initialScope) {
|
|
113
|
+
return names.some((n) => hasAttribute(n, attributes, initialScope));
|
|
116
114
|
}
|
|
117
|
-
function
|
|
118
|
-
return
|
|
115
|
+
function hasEveryAttribute(names, attributes, initialScope) {
|
|
116
|
+
return names.every((n) => hasAttribute(n, attributes, initialScope));
|
|
119
117
|
}
|
|
120
118
|
var JSXValueHint = {
|
|
121
119
|
None: 0n,
|
|
@@ -222,6 +220,19 @@ function isJSXValue(node, jsxCtx, hint = DEFAULT_JSX_VALUE_HINT) {
|
|
|
222
220
|
}
|
|
223
221
|
return false;
|
|
224
222
|
}
|
|
223
|
+
function isFragmentElement(node) {
|
|
224
|
+
if (node.type !== AST_NODE_TYPES.JSXElement) return false;
|
|
225
|
+
return getElementName(node).split(".").at(-1) === "Fragment";
|
|
226
|
+
}
|
|
227
|
+
function isKeyedElement(node, initialScope) {
|
|
228
|
+
return node.type === AST_NODE_TYPES.JSXElement && hasAttribute("key", node.openingElement.attributes, initialScope);
|
|
229
|
+
}
|
|
230
|
+
function isBuiltInElement(node) {
|
|
231
|
+
return node.type === AST_NODE_TYPES.JSXElement && node.openingElement.name.type === AST_NODE_TYPES.JSXIdentifier && node.openingElement.name.name.toLowerCase() === node.openingElement.name.name && /^[a-z]/u.test(node.openingElement.name.name);
|
|
232
|
+
}
|
|
233
|
+
function isUserDefinedElement(node) {
|
|
234
|
+
return node.type === AST_NODE_TYPES.JSXElement && node.openingElement.name.type === AST_NODE_TYPES.JSXIdentifier && /^[A-Z]/u.test(node.openingElement.name.name);
|
|
235
|
+
}
|
|
225
236
|
var isLiteral = AST3.isOneOf([AST_NODE_TYPES.Literal, AST_NODE_TYPES.JSXText]);
|
|
226
237
|
function isWhiteSpace(node) {
|
|
227
238
|
return typeof node.value === "string" && node.value.trim() === "";
|
|
@@ -233,273 +244,4 @@ function isPaddingSpaces(node) {
|
|
|
233
244
|
return isLiteral(node) && isWhiteSpace(node) && node.raw.includes("\n");
|
|
234
245
|
}
|
|
235
246
|
|
|
236
|
-
|
|
237
|
-
var xhtmlEntities = {
|
|
238
|
-
Aacute: "\xC1",
|
|
239
|
-
aacute: "\xE1",
|
|
240
|
-
Acirc: "\xC2",
|
|
241
|
-
acirc: "\xE2",
|
|
242
|
-
acute: "\xB4",
|
|
243
|
-
AElig: "\xC6",
|
|
244
|
-
aelig: "\xE6",
|
|
245
|
-
Agrave: "\xC0",
|
|
246
|
-
agrave: "\xE0",
|
|
247
|
-
alefsym: "\u2135",
|
|
248
|
-
Alpha: "\u0391",
|
|
249
|
-
alpha: "\u03B1",
|
|
250
|
-
amp: "&",
|
|
251
|
-
and: "\u2227",
|
|
252
|
-
ang: "\u2220",
|
|
253
|
-
apos: "'",
|
|
254
|
-
Aring: "\xC5",
|
|
255
|
-
aring: "\xE5",
|
|
256
|
-
asymp: "\u2248",
|
|
257
|
-
Atilde: "\xC3",
|
|
258
|
-
atilde: "\xE3",
|
|
259
|
-
Auml: "\xC4",
|
|
260
|
-
auml: "\xE4",
|
|
261
|
-
bdquo: "\u201E",
|
|
262
|
-
Beta: "\u0392",
|
|
263
|
-
beta: "\u03B2",
|
|
264
|
-
brvbar: "\xA6",
|
|
265
|
-
bull: "\u2022",
|
|
266
|
-
cap: "\u2229",
|
|
267
|
-
Ccedil: "\xC7",
|
|
268
|
-
ccedil: "\xE7",
|
|
269
|
-
cedil: "\xB8",
|
|
270
|
-
cent: "\xA2",
|
|
271
|
-
Chi: "\u03A7",
|
|
272
|
-
chi: "\u03C7",
|
|
273
|
-
circ: "\u02C6",
|
|
274
|
-
clubs: "\u2663",
|
|
275
|
-
cong: "\u2245",
|
|
276
|
-
copy: "\xA9",
|
|
277
|
-
crarr: "\u21B5",
|
|
278
|
-
cup: "\u222A",
|
|
279
|
-
curren: "\xA4",
|
|
280
|
-
dagger: "\u2020",
|
|
281
|
-
Dagger: "\u2021",
|
|
282
|
-
darr: "\u2193",
|
|
283
|
-
dArr: "\u21D3",
|
|
284
|
-
deg: "\xB0",
|
|
285
|
-
Delta: "\u0394",
|
|
286
|
-
delta: "\u03B4",
|
|
287
|
-
diams: "\u2666",
|
|
288
|
-
divide: "\xF7",
|
|
289
|
-
Eacute: "\xC9",
|
|
290
|
-
eacute: "\xE9",
|
|
291
|
-
Ecirc: "\xCA",
|
|
292
|
-
ecirc: "\xEA",
|
|
293
|
-
Egrave: "\xC8",
|
|
294
|
-
egrave: "\xE8",
|
|
295
|
-
empty: "\u2205",
|
|
296
|
-
emsp: "\u2003",
|
|
297
|
-
ensp: "\u2002",
|
|
298
|
-
Epsilon: "\u0395",
|
|
299
|
-
epsilon: "\u03B5",
|
|
300
|
-
equiv: "\u2261",
|
|
301
|
-
Eta: "\u0397",
|
|
302
|
-
eta: "\u03B7",
|
|
303
|
-
ETH: "\xD0",
|
|
304
|
-
eth: "\xF0",
|
|
305
|
-
Euml: "\xCB",
|
|
306
|
-
euml: "\xEB",
|
|
307
|
-
euro: "\u20AC",
|
|
308
|
-
exist: "\u2203",
|
|
309
|
-
fnof: "\u0192",
|
|
310
|
-
forall: "\u2200",
|
|
311
|
-
frac12: "\xBD",
|
|
312
|
-
frac14: "\xBC",
|
|
313
|
-
frac34: "\xBE",
|
|
314
|
-
frasl: "\u2044",
|
|
315
|
-
Gamma: "\u0393",
|
|
316
|
-
gamma: "\u03B3",
|
|
317
|
-
ge: "\u2265",
|
|
318
|
-
gt: ">",
|
|
319
|
-
harr: "\u2194",
|
|
320
|
-
hArr: "\u21D4",
|
|
321
|
-
hearts: "\u2665",
|
|
322
|
-
hellip: "\u2026",
|
|
323
|
-
Iacute: "\xCD",
|
|
324
|
-
iacute: "\xED",
|
|
325
|
-
Icirc: "\xCE",
|
|
326
|
-
icirc: "\xEE",
|
|
327
|
-
iexcl: "\xA1",
|
|
328
|
-
Igrave: "\xCC",
|
|
329
|
-
igrave: "\xEC",
|
|
330
|
-
image: "\u2111",
|
|
331
|
-
infin: "\u221E",
|
|
332
|
-
int: "\u222B",
|
|
333
|
-
Iota: "\u0399",
|
|
334
|
-
iota: "\u03B9",
|
|
335
|
-
iquest: "\xBF",
|
|
336
|
-
isin: "\u2208",
|
|
337
|
-
Iuml: "\xCF",
|
|
338
|
-
iuml: "\xEF",
|
|
339
|
-
Kappa: "\u039A",
|
|
340
|
-
kappa: "\u03BA",
|
|
341
|
-
Lambda: "\u039B",
|
|
342
|
-
lambda: "\u03BB",
|
|
343
|
-
lang: "\u2329",
|
|
344
|
-
laquo: "\xAB",
|
|
345
|
-
larr: "\u2190",
|
|
346
|
-
lArr: "\u21D0",
|
|
347
|
-
lceil: "\u2308",
|
|
348
|
-
ldquo: "\u201C",
|
|
349
|
-
le: "\u2264",
|
|
350
|
-
lfloor: "\u230A",
|
|
351
|
-
lowast: "\u2217",
|
|
352
|
-
loz: "\u25CA",
|
|
353
|
-
lrm: "\u200E",
|
|
354
|
-
lsaquo: "\u2039",
|
|
355
|
-
lsquo: "\u2018",
|
|
356
|
-
lt: "<",
|
|
357
|
-
macr: "\xAF",
|
|
358
|
-
mdash: "\u2014",
|
|
359
|
-
micro: "\xB5",
|
|
360
|
-
middot: "\xB7",
|
|
361
|
-
minus: "\u2212",
|
|
362
|
-
Mu: "\u039C",
|
|
363
|
-
mu: "\u03BC",
|
|
364
|
-
nabla: "\u2207",
|
|
365
|
-
nbsp: "\xA0",
|
|
366
|
-
ndash: "\u2013",
|
|
367
|
-
ne: "\u2260",
|
|
368
|
-
ni: "\u220B",
|
|
369
|
-
not: "\xAC",
|
|
370
|
-
notin: "\u2209",
|
|
371
|
-
nsub: "\u2284",
|
|
372
|
-
Ntilde: "\xD1",
|
|
373
|
-
ntilde: "\xF1",
|
|
374
|
-
Nu: "\u039D",
|
|
375
|
-
nu: "\u03BD",
|
|
376
|
-
Oacute: "\xD3",
|
|
377
|
-
oacute: "\xF3",
|
|
378
|
-
Ocirc: "\xD4",
|
|
379
|
-
ocirc: "\xF4",
|
|
380
|
-
OElig: "\u0152",
|
|
381
|
-
oelig: "\u0153",
|
|
382
|
-
Ograve: "\xD2",
|
|
383
|
-
ograve: "\xF2",
|
|
384
|
-
oline: "\u203E",
|
|
385
|
-
Omega: "\u03A9",
|
|
386
|
-
omega: "\u03C9",
|
|
387
|
-
Omicron: "\u039F",
|
|
388
|
-
omicron: "\u03BF",
|
|
389
|
-
oplus: "\u2295",
|
|
390
|
-
or: "\u2228",
|
|
391
|
-
ordf: "\xAA",
|
|
392
|
-
ordm: "\xBA",
|
|
393
|
-
Oslash: "\xD8",
|
|
394
|
-
oslash: "\xF8",
|
|
395
|
-
Otilde: "\xD5",
|
|
396
|
-
otilde: "\xF5",
|
|
397
|
-
otimes: "\u2297",
|
|
398
|
-
Ouml: "\xD6",
|
|
399
|
-
ouml: "\xF6",
|
|
400
|
-
para: "\xB6",
|
|
401
|
-
part: "\u2202",
|
|
402
|
-
permil: "\u2030",
|
|
403
|
-
perp: "\u22A5",
|
|
404
|
-
Phi: "\u03A6",
|
|
405
|
-
phi: "\u03C6",
|
|
406
|
-
Pi: "\u03A0",
|
|
407
|
-
pi: "\u03C0",
|
|
408
|
-
piv: "\u03D6",
|
|
409
|
-
plusmn: "\xB1",
|
|
410
|
-
pound: "\xA3",
|
|
411
|
-
prime: "\u2032",
|
|
412
|
-
Prime: "\u2033",
|
|
413
|
-
prod: "\u220F",
|
|
414
|
-
prop: "\u221D",
|
|
415
|
-
Psi: "\u03A8",
|
|
416
|
-
psi: "\u03C8",
|
|
417
|
-
quot: '"',
|
|
418
|
-
radic: "\u221A",
|
|
419
|
-
rang: "\u232A",
|
|
420
|
-
raquo: "\xBB",
|
|
421
|
-
rarr: "\u2192",
|
|
422
|
-
rArr: "\u21D2",
|
|
423
|
-
rceil: "\u2309",
|
|
424
|
-
rdquo: "\u201D",
|
|
425
|
-
real: "\u211C",
|
|
426
|
-
reg: "\xAE",
|
|
427
|
-
rfloor: "\u230B",
|
|
428
|
-
Rho: "\u03A1",
|
|
429
|
-
rho: "\u03C1",
|
|
430
|
-
rlm: "\u200F",
|
|
431
|
-
rsaquo: "\u203A",
|
|
432
|
-
rsquo: "\u2019",
|
|
433
|
-
sbquo: "\u201A",
|
|
434
|
-
Scaron: "\u0160",
|
|
435
|
-
scaron: "\u0161",
|
|
436
|
-
sdot: "\u22C5",
|
|
437
|
-
sect: "\xA7",
|
|
438
|
-
shy: "\xAD",
|
|
439
|
-
Sigma: "\u03A3",
|
|
440
|
-
sigma: "\u03C3",
|
|
441
|
-
sigmaf: "\u03C2",
|
|
442
|
-
sim: "\u223C",
|
|
443
|
-
spades: "\u2660",
|
|
444
|
-
sub: "\u2282",
|
|
445
|
-
sube: "\u2286",
|
|
446
|
-
sum: "\u2211",
|
|
447
|
-
sup: "\u2283",
|
|
448
|
-
sup1: "\xB9",
|
|
449
|
-
sup2: "\xB2",
|
|
450
|
-
sup3: "\xB3",
|
|
451
|
-
supe: "\u2287",
|
|
452
|
-
szlig: "\xDF",
|
|
453
|
-
Tau: "\u03A4",
|
|
454
|
-
tau: "\u03C4",
|
|
455
|
-
there4: "\u2234",
|
|
456
|
-
Theta: "\u0398",
|
|
457
|
-
theta: "\u03B8",
|
|
458
|
-
thetasym: "\u03D1",
|
|
459
|
-
thinsp: "\u2009",
|
|
460
|
-
THORN: "\xDE",
|
|
461
|
-
thorn: "\xFE",
|
|
462
|
-
tilde: "\u02DC",
|
|
463
|
-
times: "\xD7",
|
|
464
|
-
trade: "\u2122",
|
|
465
|
-
Uacute: "\xDA",
|
|
466
|
-
uacute: "\xFA",
|
|
467
|
-
uarr: "\u2191",
|
|
468
|
-
uArr: "\u21D1",
|
|
469
|
-
Ucirc: "\xDB",
|
|
470
|
-
ucirc: "\xFB",
|
|
471
|
-
Ugrave: "\xD9",
|
|
472
|
-
ugrave: "\xF9",
|
|
473
|
-
uml: "\xA8",
|
|
474
|
-
upsih: "\u03D2",
|
|
475
|
-
Upsilon: "\u03A5",
|
|
476
|
-
upsilon: "\u03C5",
|
|
477
|
-
Uuml: "\xDC",
|
|
478
|
-
uuml: "\xFC",
|
|
479
|
-
weierp: "\u2118",
|
|
480
|
-
Xi: "\u039E",
|
|
481
|
-
xi: "\u03BE",
|
|
482
|
-
Yacute: "\xDD",
|
|
483
|
-
yacute: "\xFD",
|
|
484
|
-
yen: "\xA5",
|
|
485
|
-
yuml: "\xFF",
|
|
486
|
-
Yuml: "\u0178",
|
|
487
|
-
Zeta: "\u0396",
|
|
488
|
-
zeta: "\u03B6",
|
|
489
|
-
zwj: "\u200D",
|
|
490
|
-
zwnj: "\u200C"
|
|
491
|
-
};
|
|
492
|
-
|
|
493
|
-
// src/unescape-string-literal-text.ts
|
|
494
|
-
function unescapeStringLiteralText(text) {
|
|
495
|
-
return text.replaceAll(/&(?:#\d+|#x[\da-fA-F]+|[0-9a-zA-Z]+);/g, (entity) => {
|
|
496
|
-
const item = entity.slice(1, -1);
|
|
497
|
-
if (item[0] === "#") {
|
|
498
|
-
const codePoint = item[1] === "x" ? parseInt(item.slice(2), 16) : parseInt(item.slice(1), 10);
|
|
499
|
-
return codePoint > 1114111 ? entity : String.fromCodePoint(codePoint);
|
|
500
|
-
}
|
|
501
|
-
return xhtmlEntities[item] ?? entity;
|
|
502
|
-
});
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, findParentAttributeNode, getAttributeName, getAttributeNode, getAttributeStaticValue, getAttributeStringValue, getElementName, hasAnyAttribute, hasAttribute, hasEveryAttribute, isBuiltInElement, isJSXValue, isKeyedElement, isLineBreak, isLiteral, isPaddingSpaces, isUserDefinedElement, isWhiteSpace, unescapeStringLiteralText, xhtmlEntities };
|
|
247
|
+
export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, findParentAttribute, getAttribute, getAttributeName, getAttributeValue, getElementName, hasAnyAttribute, hasAttribute, hasEveryAttribute, isBuiltInElement, isFragmentElement, isJSXValue, isKeyedElement, isLineBreak, isLiteral, isPaddingSpaces, isUserDefinedElement, isWhiteSpace, toString };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/jsx",
|
|
3
|
-
"version": "1.24.0
|
|
3
|
+
"version": "1.24.0",
|
|
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": {
|
|
@@ -36,10 +36,10 @@
|
|
|
36
36
|
"@typescript-eslint/scope-manager": "^8.20.0",
|
|
37
37
|
"@typescript-eslint/types": "^8.20.0",
|
|
38
38
|
"@typescript-eslint/utils": "^8.20.0",
|
|
39
|
-
"ts-pattern": "^5.6.
|
|
40
|
-
"@eslint-react/ast": "1.24.0
|
|
41
|
-
"@eslint-react/var": "1.24.0
|
|
42
|
-
"@eslint-react/eff": "1.24.0
|
|
39
|
+
"ts-pattern": "^5.6.1",
|
|
40
|
+
"@eslint-react/ast": "1.24.0",
|
|
41
|
+
"@eslint-react/var": "1.24.0",
|
|
42
|
+
"@eslint-react/eff": "1.24.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"tsup": "^8.3.5",
|