@eslint-react/jsx 1.24.0-next.11 → 1.24.0-next.12
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 +58 -25
- package/dist/index.d.ts +58 -25
- package/dist/index.js +56 -49
- package/dist/index.mjs +54 -47
- package/package.json +4 -4
package/dist/index.d.mts
CHANGED
|
@@ -1,40 +1,68 @@
|
|
|
1
|
+
import { TSESTree } from '@typescript-eslint/utils';
|
|
2
|
+
import { TSESTree as TSESTree$1 } from '@typescript-eslint/types';
|
|
1
3
|
import { _ } from '@eslint-react/eff';
|
|
2
|
-
import { TSESTree } from '@typescript-eslint/types';
|
|
3
4
|
import { Scope } from '@typescript-eslint/scope-manager';
|
|
4
|
-
import { TSESTree as TSESTree$1 } from '@typescript-eslint/utils';
|
|
5
5
|
import * as VAR from '@eslint-react/var';
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Get the stringified name of a JSX attribute
|
|
9
|
+
* @param node The JSX attribute node
|
|
10
|
+
* @returns The name of the attribute
|
|
11
|
+
*/
|
|
12
|
+
declare function getAttributeName(node: TSESTree.JSXAttribute): string;
|
|
8
13
|
|
|
9
|
-
|
|
10
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Get the stringified name of a JSX element
|
|
16
|
+
* @param node The JSX element node
|
|
17
|
+
* @returns The name of the element
|
|
18
|
+
*/
|
|
19
|
+
declare function getElementName(node: TSESTree$1.JSXElement | TSESTree$1.JSXFragment): string;
|
|
11
20
|
|
|
12
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Find the parent JSX attribute node of a node
|
|
23
|
+
* @param node The node to find the parent attribute of
|
|
24
|
+
* @param test The test to apply to the parent attribute
|
|
25
|
+
* @returns The parent attribute node or undefined
|
|
26
|
+
*/
|
|
27
|
+
declare function findParentAttribute(node: TSESTree$1.Node, test?: (node: TSESTree$1.JSXAttribute) => boolean): TSESTree$1.JSXAttribute | _;
|
|
13
28
|
|
|
14
29
|
/**
|
|
15
|
-
*
|
|
16
|
-
* @param
|
|
17
|
-
* @
|
|
30
|
+
* Get the JSX attribute node with the given name
|
|
31
|
+
* @param name The name of the attribute
|
|
32
|
+
* @param initialScope The initial scope to use for variable resolution
|
|
33
|
+
* @param attributes The attributes to search
|
|
34
|
+
* @returns The JSX attribute node or undefined
|
|
18
35
|
*/
|
|
19
|
-
declare function
|
|
36
|
+
declare function getAttribute(name: string, initialScope: Scope, attributes: (TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute)[]): TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute | _;
|
|
20
37
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Get a StaticValue of the attribute value
|
|
40
|
+
* @param name The name of the attribute
|
|
41
|
+
* @param node The JSX attribute node
|
|
42
|
+
* @param initialScope The initial scope to use
|
|
43
|
+
* @returns The StaticValue of the attribute value
|
|
44
|
+
*/
|
|
45
|
+
declare function getAttributeValue(name: string, node: TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute, initialScope: Scope): Exclude<VAR.LazyValue, {
|
|
46
|
+
kind: "lazy";
|
|
47
|
+
}>;
|
|
48
|
+
|
|
49
|
+
declare function hasAttribute(name: string, initialScope: Scope, attributes: TSESTree$1.JSXOpeningElement["attributes"]): boolean;
|
|
50
|
+
declare function hasAnyAttribute(names: string[], initialScope: Scope, attributes: TSESTree$1.JSXOpeningElement["attributes"]): boolean;
|
|
51
|
+
declare function hasEveryAttribute(names: string[], initialScope: Scope, attributes: TSESTree$1.JSXOpeningElement["attributes"]): boolean;
|
|
24
52
|
|
|
25
|
-
declare function isKeyedElement(node: TSESTree.Node, initialScope: Scope): boolean;
|
|
53
|
+
declare function isKeyedElement(node: TSESTree$1.Node, initialScope: Scope): boolean;
|
|
26
54
|
/**
|
|
27
55
|
* Check if a node is a `JSXFragment` of `Built-in Component` type
|
|
28
56
|
* @param node The AST node to check
|
|
29
57
|
* @returns `true` if the node is a `JSXFragment` of `Built-in Component` type
|
|
30
58
|
*/
|
|
31
|
-
declare function isBuiltInElement(node: TSESTree.Node): boolean;
|
|
59
|
+
declare function isBuiltInElement(node: TSESTree$1.Node): boolean;
|
|
32
60
|
/**
|
|
33
61
|
* Check if a node is a `JSXElement` of `User-Defined Component` type
|
|
34
62
|
* @param node The AST node to check
|
|
35
63
|
* @returns `true` if the node is a `JSXElement` of `User-Defined Component` type
|
|
36
64
|
*/
|
|
37
|
-
declare function isUserDefinedElement(node: TSESTree.Node): boolean;
|
|
65
|
+
declare function isUserDefinedElement(node: TSESTree$1.Node): boolean;
|
|
38
66
|
|
|
39
67
|
declare const JSXValueHint: {
|
|
40
68
|
readonly None: 0n;
|
|
@@ -52,15 +80,15 @@ declare const JSXValueHint: {
|
|
|
52
80
|
};
|
|
53
81
|
declare const DEFAULT_JSX_VALUE_HINT: bigint;
|
|
54
82
|
/**
|
|
55
|
-
*
|
|
83
|
+
* Heruistic decision to determine if a node is a JSX value
|
|
56
84
|
* @param node The AST node to check
|
|
57
85
|
* @param jsxCtx The requirements for the check
|
|
58
86
|
* @param jsxCtx.getScope The function to get the scope of a node
|
|
59
87
|
* @param hint The `JSXValueHint` to use
|
|
60
88
|
* @returns boolean
|
|
61
89
|
*/
|
|
62
|
-
declare function isJSXValue(node: TSESTree
|
|
63
|
-
getScope: (node: TSESTree
|
|
90
|
+
declare function isJSXValue(node: TSESTree.Node | _ | null, jsxCtx: {
|
|
91
|
+
getScope: (node: TSESTree.Node) => Scope;
|
|
64
92
|
}, hint?: bigint): boolean;
|
|
65
93
|
|
|
66
94
|
/**
|
|
@@ -68,27 +96,32 @@ declare function isJSXValue(node: TSESTree$1.Node | _ | null, jsxCtx: {
|
|
|
68
96
|
* @param node The AST node to check
|
|
69
97
|
* @returns boolean `true` if the node is a Literal or JSXText
|
|
70
98
|
*/
|
|
71
|
-
declare const isLiteral: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXText | TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral;
|
|
99
|
+
declare const isLiteral: (node: TSESTree$1.Node | null | undefined) => node is TSESTree$1.JSXText | TSESTree$1.BigIntLiteral | TSESTree$1.BooleanLiteral | TSESTree$1.NullLiteral | TSESTree$1.NumberLiteral | TSESTree$1.RegExpLiteral | TSESTree$1.StringLiteral;
|
|
72
100
|
/**
|
|
73
101
|
* Check if a Literal or JSXText node is whitespace
|
|
74
102
|
* @param node The AST node to check
|
|
75
103
|
* @returns boolean `true` if the node is whitespace
|
|
76
104
|
*/
|
|
77
|
-
declare function isWhiteSpace(node: TSESTree.JSXText | TSESTree.Literal): boolean;
|
|
105
|
+
declare function isWhiteSpace(node: TSESTree$1.JSXText | TSESTree$1.Literal): boolean;
|
|
78
106
|
/**
|
|
79
107
|
* Check if a Literal or JSXText node is a line break
|
|
80
108
|
* @param node The AST node to check
|
|
81
109
|
* @returns boolean
|
|
82
110
|
*/
|
|
83
|
-
declare function isLineBreak(node: TSESTree.Node): boolean;
|
|
111
|
+
declare function isLineBreak(node: TSESTree$1.Node): boolean;
|
|
84
112
|
/**
|
|
85
113
|
* Check if a Literal or JSXText node is padding spaces
|
|
86
114
|
* @param node The AST node to check
|
|
87
115
|
* @returns boolean
|
|
88
116
|
*/
|
|
89
|
-
declare function isPaddingSpaces(node: TSESTree.Node): boolean;
|
|
117
|
+
declare function isPaddingSpaces(node: TSESTree$1.Node): boolean;
|
|
90
118
|
|
|
91
|
-
|
|
119
|
+
/**
|
|
120
|
+
* Get the stringified representation of a JSX node
|
|
121
|
+
* @param node The JSX node
|
|
122
|
+
* @returns The stringified representation
|
|
123
|
+
*/
|
|
124
|
+
declare function toString(node: TSESTree.JSXIdentifier | TSESTree.JSXMemberExpression | TSESTree.JSXNamespacedName | TSESTree.JSXOpeningElement | TSESTree.JSXClosingElement | TSESTree.JSXOpeningFragment | TSESTree.JSXClosingFragment | TSESTree.JSXText): string;
|
|
92
125
|
|
|
93
126
|
/**
|
|
94
127
|
* Unescape the text content of string literals, e.g. & -> &
|
|
@@ -99,4 +132,4 @@ declare function unescapeStringLiteralText(text: string): string;
|
|
|
99
132
|
|
|
100
133
|
declare const xhtmlEntities: Record<string, string>;
|
|
101
134
|
|
|
102
|
-
export { DEFAULT_JSX_VALUE_HINT, JSXValueHint,
|
|
135
|
+
export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, findParentAttribute, getAttribute, getAttributeName, getAttributeValue, getElementName, hasAnyAttribute, hasAttribute, hasEveryAttribute, isBuiltInElement, isJSXValue, isKeyedElement, isLineBreak, isLiteral, isPaddingSpaces, isUserDefinedElement, isWhiteSpace, toString, unescapeStringLiteralText, xhtmlEntities };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,40 +1,68 @@
|
|
|
1
|
+
import { TSESTree } from '@typescript-eslint/utils';
|
|
2
|
+
import { TSESTree as TSESTree$1 } from '@typescript-eslint/types';
|
|
1
3
|
import { _ } from '@eslint-react/eff';
|
|
2
|
-
import { TSESTree } from '@typescript-eslint/types';
|
|
3
4
|
import { Scope } from '@typescript-eslint/scope-manager';
|
|
4
|
-
import { TSESTree as TSESTree$1 } from '@typescript-eslint/utils';
|
|
5
5
|
import * as VAR from '@eslint-react/var';
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Get the stringified name of a JSX attribute
|
|
9
|
+
* @param node The JSX attribute node
|
|
10
|
+
* @returns The name of the attribute
|
|
11
|
+
*/
|
|
12
|
+
declare function getAttributeName(node: TSESTree.JSXAttribute): string;
|
|
8
13
|
|
|
9
|
-
|
|
10
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Get the stringified name of a JSX element
|
|
16
|
+
* @param node The JSX element node
|
|
17
|
+
* @returns The name of the element
|
|
18
|
+
*/
|
|
19
|
+
declare function getElementName(node: TSESTree$1.JSXElement | TSESTree$1.JSXFragment): string;
|
|
11
20
|
|
|
12
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Find the parent JSX attribute node of a node
|
|
23
|
+
* @param node The node to find the parent attribute of
|
|
24
|
+
* @param test The test to apply to the parent attribute
|
|
25
|
+
* @returns The parent attribute node or undefined
|
|
26
|
+
*/
|
|
27
|
+
declare function findParentAttribute(node: TSESTree$1.Node, test?: (node: TSESTree$1.JSXAttribute) => boolean): TSESTree$1.JSXAttribute | _;
|
|
13
28
|
|
|
14
29
|
/**
|
|
15
|
-
*
|
|
16
|
-
* @param
|
|
17
|
-
* @
|
|
30
|
+
* Get the JSX attribute node with the given name
|
|
31
|
+
* @param name The name of the attribute
|
|
32
|
+
* @param initialScope The initial scope to use for variable resolution
|
|
33
|
+
* @param attributes The attributes to search
|
|
34
|
+
* @returns The JSX attribute node or undefined
|
|
18
35
|
*/
|
|
19
|
-
declare function
|
|
36
|
+
declare function getAttribute(name: string, initialScope: Scope, attributes: (TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute)[]): TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute | _;
|
|
20
37
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Get a StaticValue of the attribute value
|
|
40
|
+
* @param name The name of the attribute
|
|
41
|
+
* @param node The JSX attribute node
|
|
42
|
+
* @param initialScope The initial scope to use
|
|
43
|
+
* @returns The StaticValue of the attribute value
|
|
44
|
+
*/
|
|
45
|
+
declare function getAttributeValue(name: string, node: TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute, initialScope: Scope): Exclude<VAR.LazyValue, {
|
|
46
|
+
kind: "lazy";
|
|
47
|
+
}>;
|
|
48
|
+
|
|
49
|
+
declare function hasAttribute(name: string, initialScope: Scope, attributes: TSESTree$1.JSXOpeningElement["attributes"]): boolean;
|
|
50
|
+
declare function hasAnyAttribute(names: string[], initialScope: Scope, attributes: TSESTree$1.JSXOpeningElement["attributes"]): boolean;
|
|
51
|
+
declare function hasEveryAttribute(names: string[], initialScope: Scope, attributes: TSESTree$1.JSXOpeningElement["attributes"]): boolean;
|
|
24
52
|
|
|
25
|
-
declare function isKeyedElement(node: TSESTree.Node, initialScope: Scope): boolean;
|
|
53
|
+
declare function isKeyedElement(node: TSESTree$1.Node, initialScope: Scope): boolean;
|
|
26
54
|
/**
|
|
27
55
|
* Check if a node is a `JSXFragment` of `Built-in Component` type
|
|
28
56
|
* @param node The AST node to check
|
|
29
57
|
* @returns `true` if the node is a `JSXFragment` of `Built-in Component` type
|
|
30
58
|
*/
|
|
31
|
-
declare function isBuiltInElement(node: TSESTree.Node): boolean;
|
|
59
|
+
declare function isBuiltInElement(node: TSESTree$1.Node): boolean;
|
|
32
60
|
/**
|
|
33
61
|
* Check if a node is a `JSXElement` of `User-Defined Component` type
|
|
34
62
|
* @param node The AST node to check
|
|
35
63
|
* @returns `true` if the node is a `JSXElement` of `User-Defined Component` type
|
|
36
64
|
*/
|
|
37
|
-
declare function isUserDefinedElement(node: TSESTree.Node): boolean;
|
|
65
|
+
declare function isUserDefinedElement(node: TSESTree$1.Node): boolean;
|
|
38
66
|
|
|
39
67
|
declare const JSXValueHint: {
|
|
40
68
|
readonly None: 0n;
|
|
@@ -52,15 +80,15 @@ declare const JSXValueHint: {
|
|
|
52
80
|
};
|
|
53
81
|
declare const DEFAULT_JSX_VALUE_HINT: bigint;
|
|
54
82
|
/**
|
|
55
|
-
*
|
|
83
|
+
* Heruistic decision to determine if a node is a JSX value
|
|
56
84
|
* @param node The AST node to check
|
|
57
85
|
* @param jsxCtx The requirements for the check
|
|
58
86
|
* @param jsxCtx.getScope The function to get the scope of a node
|
|
59
87
|
* @param hint The `JSXValueHint` to use
|
|
60
88
|
* @returns boolean
|
|
61
89
|
*/
|
|
62
|
-
declare function isJSXValue(node: TSESTree
|
|
63
|
-
getScope: (node: TSESTree
|
|
90
|
+
declare function isJSXValue(node: TSESTree.Node | _ | null, jsxCtx: {
|
|
91
|
+
getScope: (node: TSESTree.Node) => Scope;
|
|
64
92
|
}, hint?: bigint): boolean;
|
|
65
93
|
|
|
66
94
|
/**
|
|
@@ -68,27 +96,32 @@ declare function isJSXValue(node: TSESTree$1.Node | _ | null, jsxCtx: {
|
|
|
68
96
|
* @param node The AST node to check
|
|
69
97
|
* @returns boolean `true` if the node is a Literal or JSXText
|
|
70
98
|
*/
|
|
71
|
-
declare const isLiteral: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXText | TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral;
|
|
99
|
+
declare const isLiteral: (node: TSESTree$1.Node | null | undefined) => node is TSESTree$1.JSXText | TSESTree$1.BigIntLiteral | TSESTree$1.BooleanLiteral | TSESTree$1.NullLiteral | TSESTree$1.NumberLiteral | TSESTree$1.RegExpLiteral | TSESTree$1.StringLiteral;
|
|
72
100
|
/**
|
|
73
101
|
* Check if a Literal or JSXText node is whitespace
|
|
74
102
|
* @param node The AST node to check
|
|
75
103
|
* @returns boolean `true` if the node is whitespace
|
|
76
104
|
*/
|
|
77
|
-
declare function isWhiteSpace(node: TSESTree.JSXText | TSESTree.Literal): boolean;
|
|
105
|
+
declare function isWhiteSpace(node: TSESTree$1.JSXText | TSESTree$1.Literal): boolean;
|
|
78
106
|
/**
|
|
79
107
|
* Check if a Literal or JSXText node is a line break
|
|
80
108
|
* @param node The AST node to check
|
|
81
109
|
* @returns boolean
|
|
82
110
|
*/
|
|
83
|
-
declare function isLineBreak(node: TSESTree.Node): boolean;
|
|
111
|
+
declare function isLineBreak(node: TSESTree$1.Node): boolean;
|
|
84
112
|
/**
|
|
85
113
|
* Check if a Literal or JSXText node is padding spaces
|
|
86
114
|
* @param node The AST node to check
|
|
87
115
|
* @returns boolean
|
|
88
116
|
*/
|
|
89
|
-
declare function isPaddingSpaces(node: TSESTree.Node): boolean;
|
|
117
|
+
declare function isPaddingSpaces(node: TSESTree$1.Node): boolean;
|
|
90
118
|
|
|
91
|
-
|
|
119
|
+
/**
|
|
120
|
+
* Get the stringified representation of a JSX node
|
|
121
|
+
* @param node The JSX node
|
|
122
|
+
* @returns The stringified representation
|
|
123
|
+
*/
|
|
124
|
+
declare function toString(node: TSESTree.JSXIdentifier | TSESTree.JSXMemberExpression | TSESTree.JSXNamespacedName | TSESTree.JSXOpeningElement | TSESTree.JSXClosingElement | TSESTree.JSXOpeningFragment | TSESTree.JSXClosingFragment | TSESTree.JSXText): string;
|
|
92
125
|
|
|
93
126
|
/**
|
|
94
127
|
* Unescape the text content of string literals, e.g. & -> &
|
|
@@ -99,4 +132,4 @@ declare function unescapeStringLiteralText(text: string): string;
|
|
|
99
132
|
|
|
100
133
|
declare const xhtmlEntities: Record<string, string>;
|
|
101
134
|
|
|
102
|
-
export { DEFAULT_JSX_VALUE_HINT, JSXValueHint,
|
|
135
|
+
export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, findParentAttribute, getAttribute, getAttributeName, getAttributeValue, getElementName, hasAnyAttribute, hasAttribute, hasEveryAttribute, isBuiltInElement, isJSXValue, isKeyedElement, isLineBreak, isLiteral, isPaddingSpaces, isUserDefinedElement, isWhiteSpace, toString, unescapeStringLiteralText, xhtmlEntities };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var types = require('@typescript-eslint/types');
|
|
3
4
|
var AST3 = require('@eslint-react/ast');
|
|
4
5
|
var eff = require('@eslint-react/eff');
|
|
5
|
-
var types = require('@typescript-eslint/types');
|
|
6
6
|
var VAR = require('@eslint-react/var');
|
|
7
7
|
var tsPattern = require('ts-pattern');
|
|
8
8
|
|
|
@@ -27,22 +27,45 @@ function _interopNamespace(e) {
|
|
|
27
27
|
var AST3__namespace = /*#__PURE__*/_interopNamespace(AST3);
|
|
28
28
|
var VAR__namespace = /*#__PURE__*/_interopNamespace(VAR);
|
|
29
29
|
|
|
30
|
-
// src/
|
|
31
|
-
function
|
|
30
|
+
// src/to-string.ts
|
|
31
|
+
function toString(node) {
|
|
32
|
+
switch (node.type) {
|
|
33
|
+
case types.AST_NODE_TYPES.JSXIdentifier:
|
|
34
|
+
return node.name;
|
|
35
|
+
case types.AST_NODE_TYPES.JSXNamespacedName:
|
|
36
|
+
return `${node.namespace.name}:${node.name.name}`;
|
|
37
|
+
case types.AST_NODE_TYPES.JSXMemberExpression:
|
|
38
|
+
return `${toString(node.object)}.${toString(node.property)}`;
|
|
39
|
+
case types.AST_NODE_TYPES.JSXText:
|
|
40
|
+
return node.value;
|
|
41
|
+
case types.AST_NODE_TYPES.JSXOpeningElement:
|
|
42
|
+
return `<${toString(node.name)}>`;
|
|
43
|
+
case types.AST_NODE_TYPES.JSXClosingElement:
|
|
44
|
+
return `</${toString(node.name)}>`;
|
|
45
|
+
case types.AST_NODE_TYPES.JSXOpeningFragment:
|
|
46
|
+
return "<>";
|
|
47
|
+
case types.AST_NODE_TYPES.JSXClosingFragment:
|
|
48
|
+
return "</>";
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// src/attribute-name.ts
|
|
53
|
+
function getAttributeName(node) {
|
|
54
|
+
return toString(node.name);
|
|
55
|
+
}
|
|
56
|
+
function getElementName(node) {
|
|
57
|
+
if (node.type === types.AST_NODE_TYPES.JSXFragment) {
|
|
58
|
+
return "";
|
|
59
|
+
}
|
|
60
|
+
return toString(node.openingElement.name);
|
|
61
|
+
}
|
|
62
|
+
function findParentAttribute(node, test = eff.returnTrue) {
|
|
32
63
|
const guard = (node2) => {
|
|
33
64
|
return node2.type === types.AST_NODE_TYPES.JSXAttribute && test(node2);
|
|
34
65
|
};
|
|
35
66
|
return AST3__namespace.findParentNode(node, guard);
|
|
36
67
|
}
|
|
37
|
-
function
|
|
38
|
-
switch (node.name.type) {
|
|
39
|
-
case types.AST_NODE_TYPES.JSXIdentifier:
|
|
40
|
-
return node.name.name;
|
|
41
|
-
case types.AST_NODE_TYPES.JSXNamespacedName:
|
|
42
|
-
return `${node.name.namespace.name}:${node.name.name.name}`;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
function getAttributeNode(name, initialScope, attributes) {
|
|
68
|
+
function getAttribute(name, initialScope, attributes) {
|
|
46
69
|
return attributes.findLast((attr) => {
|
|
47
70
|
if (attr.type === types.AST_NODE_TYPES.JSXAttribute) {
|
|
48
71
|
return getAttributeName(attr) === name;
|
|
@@ -62,7 +85,7 @@ function getAttributeNode(name, initialScope, attributes) {
|
|
|
62
85
|
return false;
|
|
63
86
|
});
|
|
64
87
|
}
|
|
65
|
-
function
|
|
88
|
+
function getAttributeValue(name, node, initialScope) {
|
|
66
89
|
switch (node.type) {
|
|
67
90
|
case types.AST_NODE_TYPES.JSXAttribute:
|
|
68
91
|
if (node.value?.type === types.AST_NODE_TYPES.Literal) {
|
|
@@ -74,50 +97,37 @@ function getAttributeStaticValue(node, initialScope) {
|
|
|
74
97
|
};
|
|
75
98
|
}
|
|
76
99
|
if (node.value?.type === types.AST_NODE_TYPES.JSXExpressionContainer) {
|
|
77
|
-
return {
|
|
100
|
+
return VAR__namespace.toStaticValue({
|
|
78
101
|
kind: "lazy",
|
|
79
102
|
node: node.value.expression,
|
|
80
103
|
initialScope
|
|
81
|
-
};
|
|
104
|
+
});
|
|
82
105
|
}
|
|
83
106
|
return { kind: "none", node, initialScope };
|
|
84
|
-
case types.AST_NODE_TYPES.JSXSpreadAttribute:
|
|
85
|
-
|
|
107
|
+
case types.AST_NODE_TYPES.JSXSpreadAttribute: {
|
|
108
|
+
const staticValue = VAR__namespace.toStaticValue({
|
|
86
109
|
kind: "lazy",
|
|
87
110
|
node: node.argument,
|
|
88
111
|
initialScope
|
|
89
|
-
};
|
|
112
|
+
});
|
|
113
|
+
if (staticValue.kind === "none") {
|
|
114
|
+
return staticValue;
|
|
115
|
+
}
|
|
116
|
+
return tsPattern.match(staticValue.value).with({ [name]: tsPattern.P.select(tsPattern.P.any) }, (value) => ({
|
|
117
|
+
kind: "some",
|
|
118
|
+
node: node.argument,
|
|
119
|
+
initialScope,
|
|
120
|
+
value
|
|
121
|
+
})).otherwise(() => ({ kind: "none", node, initialScope }));
|
|
122
|
+
}
|
|
90
123
|
default:
|
|
91
124
|
return { kind: "none", node, initialScope };
|
|
92
125
|
}
|
|
93
126
|
}
|
|
94
|
-
function resolveJSXMemberExpressions(object, property) {
|
|
95
|
-
if (object.type === types.AST_NODE_TYPES.JSXMemberExpression) {
|
|
96
|
-
return `${resolveJSXMemberExpressions(object.object, object.property)}.${property.name}`;
|
|
97
|
-
}
|
|
98
|
-
if (object.type === types.AST_NODE_TYPES.JSXNamespacedName) {
|
|
99
|
-
return `${object.namespace.name}:${object.name.name}.${property.name}`;
|
|
100
|
-
}
|
|
101
|
-
return `${object.name}.${property.name}`;
|
|
102
|
-
}
|
|
103
|
-
function getElementName(node) {
|
|
104
|
-
if (node.type === types.AST_NODE_TYPES.JSXOpeningFragment) {
|
|
105
|
-
return "<>";
|
|
106
|
-
}
|
|
107
|
-
const { name } = node;
|
|
108
|
-
if (name.type === types.AST_NODE_TYPES.JSXMemberExpression) {
|
|
109
|
-
const { object, property } = name;
|
|
110
|
-
return resolveJSXMemberExpressions(object, property);
|
|
111
|
-
}
|
|
112
|
-
if (name.type === types.AST_NODE_TYPES.JSXNamespacedName) {
|
|
113
|
-
return `${name.namespace.name}:${name.name.name}`;
|
|
114
|
-
}
|
|
115
|
-
return name.name;
|
|
116
|
-
}
|
|
117
127
|
|
|
118
128
|
// src/has-attribute.ts
|
|
119
129
|
function hasAttribute(name, initialScope, attributes) {
|
|
120
|
-
return
|
|
130
|
+
return getAttribute(name, initialScope, attributes) != null;
|
|
121
131
|
}
|
|
122
132
|
function hasAnyAttribute(names, initialScope, attributes) {
|
|
123
133
|
return names.some((n) => hasAttribute(n, initialScope, attributes));
|
|
@@ -249,9 +259,6 @@ function isLineBreak(node) {
|
|
|
249
259
|
function isPaddingSpaces(node) {
|
|
250
260
|
return isLiteral(node) && isWhiteSpace(node) && node.raw.includes("\n");
|
|
251
261
|
}
|
|
252
|
-
function toResolvedAttributeValue(name, value) {
|
|
253
|
-
return tsPattern.match(VAR__namespace.toResolved(value).value).with(tsPattern.P.string, eff.identity).with({ [name]: tsPattern.P.select(tsPattern.P.string) }, eff.identity).otherwise(() => eff._);
|
|
254
|
-
}
|
|
255
262
|
|
|
256
263
|
// src/xhtml-entities.ts
|
|
257
264
|
var xhtmlEntities = {
|
|
@@ -524,10 +531,10 @@ function unescapeStringLiteralText(text) {
|
|
|
524
531
|
|
|
525
532
|
exports.DEFAULT_JSX_VALUE_HINT = DEFAULT_JSX_VALUE_HINT;
|
|
526
533
|
exports.JSXValueHint = JSXValueHint;
|
|
527
|
-
exports.
|
|
534
|
+
exports.findParentAttribute = findParentAttribute;
|
|
535
|
+
exports.getAttribute = getAttribute;
|
|
528
536
|
exports.getAttributeName = getAttributeName;
|
|
529
|
-
exports.
|
|
530
|
-
exports.getAttributeStaticValue = getAttributeStaticValue;
|
|
537
|
+
exports.getAttributeValue = getAttributeValue;
|
|
531
538
|
exports.getElementName = getElementName;
|
|
532
539
|
exports.hasAnyAttribute = hasAnyAttribute;
|
|
533
540
|
exports.hasAttribute = hasAttribute;
|
|
@@ -540,6 +547,6 @@ exports.isLiteral = isLiteral;
|
|
|
540
547
|
exports.isPaddingSpaces = isPaddingSpaces;
|
|
541
548
|
exports.isUserDefinedElement = isUserDefinedElement;
|
|
542
549
|
exports.isWhiteSpace = isWhiteSpace;
|
|
543
|
-
exports.
|
|
550
|
+
exports.toString = toString;
|
|
544
551
|
exports.unescapeStringLiteralText = unescapeStringLiteralText;
|
|
545
552
|
exports.xhtmlEntities = xhtmlEntities;
|
package/dist/index.mjs
CHANGED
|
@@ -1,25 +1,48 @@
|
|
|
1
|
-
import * as AST3 from '@eslint-react/ast';
|
|
2
|
-
import { returnTrue, identity, _ } from '@eslint-react/eff';
|
|
3
1
|
import { AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
2
|
+
import * as AST3 from '@eslint-react/ast';
|
|
3
|
+
import { returnTrue } from '@eslint-react/eff';
|
|
4
4
|
import * as VAR from '@eslint-react/var';
|
|
5
5
|
import { match, P } from 'ts-pattern';
|
|
6
6
|
|
|
7
|
-
// src/
|
|
8
|
-
function
|
|
7
|
+
// src/to-string.ts
|
|
8
|
+
function toString(node) {
|
|
9
|
+
switch (node.type) {
|
|
10
|
+
case AST_NODE_TYPES.JSXIdentifier:
|
|
11
|
+
return node.name;
|
|
12
|
+
case AST_NODE_TYPES.JSXNamespacedName:
|
|
13
|
+
return `${node.namespace.name}:${node.name.name}`;
|
|
14
|
+
case AST_NODE_TYPES.JSXMemberExpression:
|
|
15
|
+
return `${toString(node.object)}.${toString(node.property)}`;
|
|
16
|
+
case AST_NODE_TYPES.JSXText:
|
|
17
|
+
return node.value;
|
|
18
|
+
case AST_NODE_TYPES.JSXOpeningElement:
|
|
19
|
+
return `<${toString(node.name)}>`;
|
|
20
|
+
case AST_NODE_TYPES.JSXClosingElement:
|
|
21
|
+
return `</${toString(node.name)}>`;
|
|
22
|
+
case AST_NODE_TYPES.JSXOpeningFragment:
|
|
23
|
+
return "<>";
|
|
24
|
+
case AST_NODE_TYPES.JSXClosingFragment:
|
|
25
|
+
return "</>";
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// src/attribute-name.ts
|
|
30
|
+
function getAttributeName(node) {
|
|
31
|
+
return toString(node.name);
|
|
32
|
+
}
|
|
33
|
+
function getElementName(node) {
|
|
34
|
+
if (node.type === AST_NODE_TYPES.JSXFragment) {
|
|
35
|
+
return "";
|
|
36
|
+
}
|
|
37
|
+
return toString(node.openingElement.name);
|
|
38
|
+
}
|
|
39
|
+
function findParentAttribute(node, test = returnTrue) {
|
|
9
40
|
const guard = (node2) => {
|
|
10
41
|
return node2.type === AST_NODE_TYPES.JSXAttribute && test(node2);
|
|
11
42
|
};
|
|
12
43
|
return AST3.findParentNode(node, guard);
|
|
13
44
|
}
|
|
14
|
-
function
|
|
15
|
-
switch (node.name.type) {
|
|
16
|
-
case AST_NODE_TYPES.JSXIdentifier:
|
|
17
|
-
return node.name.name;
|
|
18
|
-
case AST_NODE_TYPES.JSXNamespacedName:
|
|
19
|
-
return `${node.name.namespace.name}:${node.name.name.name}`;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
function getAttributeNode(name, initialScope, attributes) {
|
|
45
|
+
function getAttribute(name, initialScope, attributes) {
|
|
23
46
|
return attributes.findLast((attr) => {
|
|
24
47
|
if (attr.type === AST_NODE_TYPES.JSXAttribute) {
|
|
25
48
|
return getAttributeName(attr) === name;
|
|
@@ -39,7 +62,7 @@ function getAttributeNode(name, initialScope, attributes) {
|
|
|
39
62
|
return false;
|
|
40
63
|
});
|
|
41
64
|
}
|
|
42
|
-
function
|
|
65
|
+
function getAttributeValue(name, node, initialScope) {
|
|
43
66
|
switch (node.type) {
|
|
44
67
|
case AST_NODE_TYPES.JSXAttribute:
|
|
45
68
|
if (node.value?.type === AST_NODE_TYPES.Literal) {
|
|
@@ -51,50 +74,37 @@ function getAttributeStaticValue(node, initialScope) {
|
|
|
51
74
|
};
|
|
52
75
|
}
|
|
53
76
|
if (node.value?.type === AST_NODE_TYPES.JSXExpressionContainer) {
|
|
54
|
-
return {
|
|
77
|
+
return VAR.toStaticValue({
|
|
55
78
|
kind: "lazy",
|
|
56
79
|
node: node.value.expression,
|
|
57
80
|
initialScope
|
|
58
|
-
};
|
|
81
|
+
});
|
|
59
82
|
}
|
|
60
83
|
return { kind: "none", node, initialScope };
|
|
61
|
-
case AST_NODE_TYPES.JSXSpreadAttribute:
|
|
62
|
-
|
|
84
|
+
case AST_NODE_TYPES.JSXSpreadAttribute: {
|
|
85
|
+
const staticValue = VAR.toStaticValue({
|
|
63
86
|
kind: "lazy",
|
|
64
87
|
node: node.argument,
|
|
65
88
|
initialScope
|
|
66
|
-
};
|
|
89
|
+
});
|
|
90
|
+
if (staticValue.kind === "none") {
|
|
91
|
+
return staticValue;
|
|
92
|
+
}
|
|
93
|
+
return match(staticValue.value).with({ [name]: P.select(P.any) }, (value) => ({
|
|
94
|
+
kind: "some",
|
|
95
|
+
node: node.argument,
|
|
96
|
+
initialScope,
|
|
97
|
+
value
|
|
98
|
+
})).otherwise(() => ({ kind: "none", node, initialScope }));
|
|
99
|
+
}
|
|
67
100
|
default:
|
|
68
101
|
return { kind: "none", node, initialScope };
|
|
69
102
|
}
|
|
70
103
|
}
|
|
71
|
-
function resolveJSXMemberExpressions(object, property) {
|
|
72
|
-
if (object.type === AST_NODE_TYPES.JSXMemberExpression) {
|
|
73
|
-
return `${resolveJSXMemberExpressions(object.object, object.property)}.${property.name}`;
|
|
74
|
-
}
|
|
75
|
-
if (object.type === AST_NODE_TYPES.JSXNamespacedName) {
|
|
76
|
-
return `${object.namespace.name}:${object.name.name}.${property.name}`;
|
|
77
|
-
}
|
|
78
|
-
return `${object.name}.${property.name}`;
|
|
79
|
-
}
|
|
80
|
-
function getElementName(node) {
|
|
81
|
-
if (node.type === AST_NODE_TYPES.JSXOpeningFragment) {
|
|
82
|
-
return "<>";
|
|
83
|
-
}
|
|
84
|
-
const { name } = node;
|
|
85
|
-
if (name.type === AST_NODE_TYPES.JSXMemberExpression) {
|
|
86
|
-
const { object, property } = name;
|
|
87
|
-
return resolveJSXMemberExpressions(object, property);
|
|
88
|
-
}
|
|
89
|
-
if (name.type === AST_NODE_TYPES.JSXNamespacedName) {
|
|
90
|
-
return `${name.namespace.name}:${name.name.name}`;
|
|
91
|
-
}
|
|
92
|
-
return name.name;
|
|
93
|
-
}
|
|
94
104
|
|
|
95
105
|
// src/has-attribute.ts
|
|
96
106
|
function hasAttribute(name, initialScope, attributes) {
|
|
97
|
-
return
|
|
107
|
+
return getAttribute(name, initialScope, attributes) != null;
|
|
98
108
|
}
|
|
99
109
|
function hasAnyAttribute(names, initialScope, attributes) {
|
|
100
110
|
return names.some((n) => hasAttribute(n, initialScope, attributes));
|
|
@@ -226,9 +236,6 @@ function isLineBreak(node) {
|
|
|
226
236
|
function isPaddingSpaces(node) {
|
|
227
237
|
return isLiteral(node) && isWhiteSpace(node) && node.raw.includes("\n");
|
|
228
238
|
}
|
|
229
|
-
function toResolvedAttributeValue(name, value) {
|
|
230
|
-
return match(VAR.toResolved(value).value).with(P.string, identity).with({ [name]: P.select(P.string) }, identity).otherwise(() => _);
|
|
231
|
-
}
|
|
232
239
|
|
|
233
240
|
// src/xhtml-entities.ts
|
|
234
241
|
var xhtmlEntities = {
|
|
@@ -499,4 +506,4 @@ function unescapeStringLiteralText(text) {
|
|
|
499
506
|
});
|
|
500
507
|
}
|
|
501
508
|
|
|
502
|
-
export { DEFAULT_JSX_VALUE_HINT, JSXValueHint,
|
|
509
|
+
export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, findParentAttribute, getAttribute, getAttributeName, getAttributeValue, getElementName, hasAnyAttribute, hasAttribute, hasEveryAttribute, isBuiltInElement, isJSXValue, isKeyedElement, isLineBreak, isLiteral, isPaddingSpaces, isUserDefinedElement, isWhiteSpace, toString, unescapeStringLiteralText, xhtmlEntities };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/jsx",
|
|
3
|
-
"version": "1.24.0-next.
|
|
3
|
+
"version": "1.24.0-next.12",
|
|
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": {
|
|
@@ -37,9 +37,9 @@
|
|
|
37
37
|
"@typescript-eslint/types": "^8.20.0",
|
|
38
38
|
"@typescript-eslint/utils": "^8.20.0",
|
|
39
39
|
"ts-pattern": "^5.6.0",
|
|
40
|
-
"@eslint-react/ast": "1.24.0-next.
|
|
41
|
-
"@eslint-react/eff": "1.24.0-next.
|
|
42
|
-
"@eslint-react/var": "1.24.0-next.
|
|
40
|
+
"@eslint-react/ast": "1.24.0-next.12",
|
|
41
|
+
"@eslint-react/eff": "1.24.0-next.12",
|
|
42
|
+
"@eslint-react/var": "1.24.0-next.12"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"tsup": "^8.3.5",
|