@eslint-react/jsx 1.24.0-next.1 → 1.24.0-next.11
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 +13 -37
- package/dist/index.d.ts +13 -37
- package/dist/index.js +74 -111
- package/dist/index.mjs +68 -104
- package/package.json +7 -8
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
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
|
+
|
|
7
|
+
declare function findParentAttributeNode(node: TSESTree.Node, test?: (node: TSESTree.JSXAttribute) => boolean): TSESTree.JSXAttribute | _;
|
|
8
|
+
|
|
9
|
+
declare function getAttributeName(node: TSESTree$1.JSXAttribute): string;
|
|
10
|
+
declare function getAttributeNode(name: string, initialScope: Scope, attributes: (TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute)[]): TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute | _;
|
|
6
11
|
|
|
7
|
-
declare function
|
|
12
|
+
declare function getAttributeStaticValue(node: TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute, initialScope: Scope): VAR.StaticValue;
|
|
8
13
|
|
|
9
14
|
/**
|
|
10
15
|
* Returns the tag name associated with a JSXOpeningElement.
|
|
@@ -13,40 +18,9 @@ declare function findParentProp(node: TSESTree.Node, test?: (node: TSESTree.JSXA
|
|
|
13
18
|
*/
|
|
14
19
|
declare function getElementName(node: TSESTree.JSXOpeningElement | TSESTree.JSXOpeningFragment): string;
|
|
15
20
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
* @returns string
|
|
20
|
-
*/
|
|
21
|
-
declare function getPropName(node: TSESTree$1.JSXAttribute): string;
|
|
22
|
-
declare function getProp(name: string, initialScope: Scope, props: (TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute)[]): TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute | _;
|
|
23
|
-
/**
|
|
24
|
-
* Gets and resolves the static value of a JSX attribute
|
|
25
|
-
* @param attribute The JSX attribute to get the value of
|
|
26
|
-
* @param initialScope The initial scope to start from
|
|
27
|
-
* @returns The static value of the given JSX attribute
|
|
28
|
-
*/
|
|
29
|
-
declare function getPropValue(attribute: TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute, initialScope: Scope): VAR.StaticValue;
|
|
30
|
-
declare function findPropInProperties(name: string, properties: (TSESTree$1.Property | TSESTree$1.RestElement | TSESTree$1.SpreadElement)[], initialScope: Scope, seenProps?: string[]): (typeof properties)[number] | _;
|
|
31
|
-
declare function findPropInAttributes(name: string, initialScope: Scope, attributes: (TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute)[]): TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute | _;
|
|
32
|
-
|
|
33
|
-
declare function hasProp(propName: string, initialScope: Scope, attributes: (TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute)[]): boolean;
|
|
34
|
-
/**
|
|
35
|
-
* Check if any of the given prop names are present in the given attributes
|
|
36
|
-
* @param attributes The attributes to search in
|
|
37
|
-
* @param propNames The prop names to search for
|
|
38
|
-
* @param initialScope The initial scope to start from
|
|
39
|
-
* @returns `true` if any of the given prop names are present in the given attributes
|
|
40
|
-
*/
|
|
41
|
-
declare function hasAnyProp(attributes: (TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute)[], propNames: string[], initialScope: Scope): boolean;
|
|
42
|
-
/**
|
|
43
|
-
* Check if all of the given prop names are present in the given attributes
|
|
44
|
-
* @param attributes The attributes to search in
|
|
45
|
-
* @param propNames The prop names to search for
|
|
46
|
-
* @param initialScope The initial scope to start from
|
|
47
|
-
* @returns `true` if all of the given prop names are present in the given attributes
|
|
48
|
-
*/
|
|
49
|
-
declare function hasEveryProp(attributes: (TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute)[], propNames: string[], initialScope: Scope): boolean;
|
|
21
|
+
declare function hasAttribute(name: string, initialScope: Scope, attributes: TSESTree.JSXOpeningElement["attributes"]): boolean;
|
|
22
|
+
declare function hasAnyAttribute(names: string[], initialScope: Scope, attributes: TSESTree.JSXOpeningElement["attributes"]): boolean;
|
|
23
|
+
declare function hasEveryAttribute(names: string[], initialScope: Scope, attributes: TSESTree.JSXOpeningElement["attributes"]): boolean;
|
|
50
24
|
|
|
51
25
|
declare function isKeyedElement(node: TSESTree.Node, initialScope: Scope): boolean;
|
|
52
26
|
/**
|
|
@@ -114,6 +88,8 @@ declare function isLineBreak(node: TSESTree.Node): boolean;
|
|
|
114
88
|
*/
|
|
115
89
|
declare function isPaddingSpaces(node: TSESTree.Node): boolean;
|
|
116
90
|
|
|
91
|
+
declare function toResolvedAttributeValue(name: string, value: VAR.StaticValue): string | undefined;
|
|
92
|
+
|
|
117
93
|
/**
|
|
118
94
|
* Unescape the text content of string literals, e.g. & -> &
|
|
119
95
|
* @param text The escaped string literal text.
|
|
@@ -123,4 +99,4 @@ declare function unescapeStringLiteralText(text: string): string;
|
|
|
123
99
|
|
|
124
100
|
declare const xhtmlEntities: Record<string, string>;
|
|
125
101
|
|
|
126
|
-
export { DEFAULT_JSX_VALUE_HINT, JSXValueHint,
|
|
102
|
+
export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, findParentAttributeNode, getAttributeName, getAttributeNode, getAttributeStaticValue, getElementName, hasAnyAttribute, hasAttribute, hasEveryAttribute, isBuiltInElement, isJSXValue, isKeyedElement, isLineBreak, isLiteral, isPaddingSpaces, isUserDefinedElement, isWhiteSpace, toResolvedAttributeValue, unescapeStringLiteralText, xhtmlEntities };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
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
|
+
|
|
7
|
+
declare function findParentAttributeNode(node: TSESTree.Node, test?: (node: TSESTree.JSXAttribute) => boolean): TSESTree.JSXAttribute | _;
|
|
8
|
+
|
|
9
|
+
declare function getAttributeName(node: TSESTree$1.JSXAttribute): string;
|
|
10
|
+
declare function getAttributeNode(name: string, initialScope: Scope, attributes: (TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute)[]): TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute | _;
|
|
6
11
|
|
|
7
|
-
declare function
|
|
12
|
+
declare function getAttributeStaticValue(node: TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute, initialScope: Scope): VAR.StaticValue;
|
|
8
13
|
|
|
9
14
|
/**
|
|
10
15
|
* Returns the tag name associated with a JSXOpeningElement.
|
|
@@ -13,40 +18,9 @@ declare function findParentProp(node: TSESTree.Node, test?: (node: TSESTree.JSXA
|
|
|
13
18
|
*/
|
|
14
19
|
declare function getElementName(node: TSESTree.JSXOpeningElement | TSESTree.JSXOpeningFragment): string;
|
|
15
20
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
* @returns string
|
|
20
|
-
*/
|
|
21
|
-
declare function getPropName(node: TSESTree$1.JSXAttribute): string;
|
|
22
|
-
declare function getProp(name: string, initialScope: Scope, props: (TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute)[]): TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute | _;
|
|
23
|
-
/**
|
|
24
|
-
* Gets and resolves the static value of a JSX attribute
|
|
25
|
-
* @param attribute The JSX attribute to get the value of
|
|
26
|
-
* @param initialScope The initial scope to start from
|
|
27
|
-
* @returns The static value of the given JSX attribute
|
|
28
|
-
*/
|
|
29
|
-
declare function getPropValue(attribute: TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute, initialScope: Scope): VAR.StaticValue;
|
|
30
|
-
declare function findPropInProperties(name: string, properties: (TSESTree$1.Property | TSESTree$1.RestElement | TSESTree$1.SpreadElement)[], initialScope: Scope, seenProps?: string[]): (typeof properties)[number] | _;
|
|
31
|
-
declare function findPropInAttributes(name: string, initialScope: Scope, attributes: (TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute)[]): TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute | _;
|
|
32
|
-
|
|
33
|
-
declare function hasProp(propName: string, initialScope: Scope, attributes: (TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute)[]): boolean;
|
|
34
|
-
/**
|
|
35
|
-
* Check if any of the given prop names are present in the given attributes
|
|
36
|
-
* @param attributes The attributes to search in
|
|
37
|
-
* @param propNames The prop names to search for
|
|
38
|
-
* @param initialScope The initial scope to start from
|
|
39
|
-
* @returns `true` if any of the given prop names are present in the given attributes
|
|
40
|
-
*/
|
|
41
|
-
declare function hasAnyProp(attributes: (TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute)[], propNames: string[], initialScope: Scope): boolean;
|
|
42
|
-
/**
|
|
43
|
-
* Check if all of the given prop names are present in the given attributes
|
|
44
|
-
* @param attributes The attributes to search in
|
|
45
|
-
* @param propNames The prop names to search for
|
|
46
|
-
* @param initialScope The initial scope to start from
|
|
47
|
-
* @returns `true` if all of the given prop names are present in the given attributes
|
|
48
|
-
*/
|
|
49
|
-
declare function hasEveryProp(attributes: (TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute)[], propNames: string[], initialScope: Scope): boolean;
|
|
21
|
+
declare function hasAttribute(name: string, initialScope: Scope, attributes: TSESTree.JSXOpeningElement["attributes"]): boolean;
|
|
22
|
+
declare function hasAnyAttribute(names: string[], initialScope: Scope, attributes: TSESTree.JSXOpeningElement["attributes"]): boolean;
|
|
23
|
+
declare function hasEveryAttribute(names: string[], initialScope: Scope, attributes: TSESTree.JSXOpeningElement["attributes"]): boolean;
|
|
50
24
|
|
|
51
25
|
declare function isKeyedElement(node: TSESTree.Node, initialScope: Scope): boolean;
|
|
52
26
|
/**
|
|
@@ -114,6 +88,8 @@ declare function isLineBreak(node: TSESTree.Node): boolean;
|
|
|
114
88
|
*/
|
|
115
89
|
declare function isPaddingSpaces(node: TSESTree.Node): boolean;
|
|
116
90
|
|
|
91
|
+
declare function toResolvedAttributeValue(name: string, value: VAR.StaticValue): string | undefined;
|
|
92
|
+
|
|
117
93
|
/**
|
|
118
94
|
* Unescape the text content of string literals, e.g. & -> &
|
|
119
95
|
* @param text The escaped string literal text.
|
|
@@ -123,4 +99,4 @@ declare function unescapeStringLiteralText(text: string): string;
|
|
|
123
99
|
|
|
124
100
|
declare const xhtmlEntities: Record<string, string>;
|
|
125
101
|
|
|
126
|
-
export { DEFAULT_JSX_VALUE_HINT, JSXValueHint,
|
|
102
|
+
export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, findParentAttributeNode, getAttributeName, getAttributeNode, getAttributeStaticValue, getElementName, hasAnyAttribute, hasAttribute, hasEveryAttribute, isBuiltInElement, isJSXValue, isKeyedElement, isLineBreak, isLiteral, isPaddingSpaces, isUserDefinedElement, isWhiteSpace, toResolvedAttributeValue, unescapeStringLiteralText, xhtmlEntities };
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@ var AST3 = require('@eslint-react/ast');
|
|
|
4
4
|
var eff = require('@eslint-react/eff');
|
|
5
5
|
var types = require('@typescript-eslint/types');
|
|
6
6
|
var VAR = require('@eslint-react/var');
|
|
7
|
+
var tsPattern = require('ts-pattern');
|
|
7
8
|
|
|
8
9
|
function _interopNamespace(e) {
|
|
9
10
|
if (e && e.__esModule) return e;
|
|
@@ -26,37 +27,14 @@ function _interopNamespace(e) {
|
|
|
26
27
|
var AST3__namespace = /*#__PURE__*/_interopNamespace(AST3);
|
|
27
28
|
var VAR__namespace = /*#__PURE__*/_interopNamespace(VAR);
|
|
28
29
|
|
|
29
|
-
// src/find-parent-
|
|
30
|
-
function
|
|
30
|
+
// src/find-parent-attribute-node.ts
|
|
31
|
+
function findParentAttributeNode(node, test = eff.returnTrue) {
|
|
31
32
|
const guard = (node2) => {
|
|
32
33
|
return node2.type === types.AST_NODE_TYPES.JSXAttribute && test(node2);
|
|
33
34
|
};
|
|
34
|
-
return AST3__namespace.
|
|
35
|
+
return AST3__namespace.findParentNode(node, guard);
|
|
35
36
|
}
|
|
36
|
-
function
|
|
37
|
-
if (object.type === types.AST_NODE_TYPES.JSXMemberExpression) {
|
|
38
|
-
return `${resolveJSXMemberExpressions(object.object, object.property)}.${property.name}`;
|
|
39
|
-
}
|
|
40
|
-
if (object.type === types.AST_NODE_TYPES.JSXNamespacedName) {
|
|
41
|
-
return `${object.namespace.name}:${object.name.name}.${property.name}`;
|
|
42
|
-
}
|
|
43
|
-
return `${object.name}.${property.name}`;
|
|
44
|
-
}
|
|
45
|
-
function getElementName(node) {
|
|
46
|
-
if (node.type === types.AST_NODE_TYPES.JSXOpeningFragment) {
|
|
47
|
-
return "<>";
|
|
48
|
-
}
|
|
49
|
-
const { name } = node;
|
|
50
|
-
if (name.type === types.AST_NODE_TYPES.JSXMemberExpression) {
|
|
51
|
-
const { object, property } = name;
|
|
52
|
-
return resolveJSXMemberExpressions(object, property);
|
|
53
|
-
}
|
|
54
|
-
if (name.type === types.AST_NODE_TYPES.JSXNamespacedName) {
|
|
55
|
-
return `${name.namespace.name}:${name.name.name}`;
|
|
56
|
-
}
|
|
57
|
-
return name.name;
|
|
58
|
-
}
|
|
59
|
-
function getPropName(node) {
|
|
37
|
+
function getAttributeName(node) {
|
|
60
38
|
switch (node.name.type) {
|
|
61
39
|
case types.AST_NODE_TYPES.JSXIdentifier:
|
|
62
40
|
return node.name.name;
|
|
@@ -64,108 +42,91 @@ function getPropName(node) {
|
|
|
64
42
|
return `${node.name.namespace.name}:${node.name.name.name}`;
|
|
65
43
|
}
|
|
66
44
|
}
|
|
67
|
-
function
|
|
68
|
-
return
|
|
45
|
+
function getAttributeNode(name, initialScope, attributes) {
|
|
46
|
+
return attributes.findLast((attr) => {
|
|
47
|
+
if (attr.type === types.AST_NODE_TYPES.JSXAttribute) {
|
|
48
|
+
return getAttributeName(attr) === name;
|
|
49
|
+
}
|
|
50
|
+
switch (attr.argument.type) {
|
|
51
|
+
case types.AST_NODE_TYPES.Identifier: {
|
|
52
|
+
const variable = VAR__namespace.findVariable(attr.argument.name, initialScope);
|
|
53
|
+
const variableNode = VAR__namespace.getVariableNode(variable, 0);
|
|
54
|
+
if (variableNode?.type === types.AST_NODE_TYPES.ObjectExpression) {
|
|
55
|
+
return VAR__namespace.findPropertyInProperties(name, variableNode.properties, initialScope) != null;
|
|
56
|
+
}
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
case types.AST_NODE_TYPES.ObjectExpression:
|
|
60
|
+
return VAR__namespace.findPropertyInProperties(name, attr.argument.properties, initialScope) != null;
|
|
61
|
+
}
|
|
62
|
+
return false;
|
|
63
|
+
});
|
|
69
64
|
}
|
|
70
|
-
function
|
|
71
|
-
switch (
|
|
65
|
+
function getAttributeStaticValue(node, initialScope) {
|
|
66
|
+
switch (node.type) {
|
|
72
67
|
case types.AST_NODE_TYPES.JSXAttribute:
|
|
73
|
-
if (
|
|
68
|
+
if (node.value?.type === types.AST_NODE_TYPES.Literal) {
|
|
74
69
|
return {
|
|
75
70
|
kind: "some",
|
|
76
|
-
node:
|
|
71
|
+
node: node.value,
|
|
77
72
|
initialScope,
|
|
78
|
-
value:
|
|
73
|
+
value: node.value.value
|
|
79
74
|
};
|
|
80
75
|
}
|
|
81
|
-
if (
|
|
76
|
+
if (node.value?.type === types.AST_NODE_TYPES.JSXExpressionContainer) {
|
|
82
77
|
return {
|
|
83
78
|
kind: "lazy",
|
|
84
|
-
node:
|
|
79
|
+
node: node.value.expression,
|
|
85
80
|
initialScope
|
|
86
81
|
};
|
|
87
82
|
}
|
|
88
|
-
return { kind: "none", node
|
|
83
|
+
return { kind: "none", node, initialScope };
|
|
89
84
|
case types.AST_NODE_TYPES.JSXSpreadAttribute:
|
|
90
85
|
return {
|
|
91
86
|
kind: "lazy",
|
|
92
|
-
node:
|
|
87
|
+
node: node.argument,
|
|
93
88
|
initialScope
|
|
94
89
|
};
|
|
95
90
|
default:
|
|
96
|
-
return { kind: "none", node
|
|
91
|
+
return { kind: "none", node, initialScope };
|
|
97
92
|
}
|
|
98
93
|
}
|
|
99
|
-
function
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
if (seenProps.includes(prop.argument.name)) {
|
|
108
|
-
return false;
|
|
109
|
-
}
|
|
110
|
-
const variable = VAR__namespace.findVariable(prop.argument.name, initialScope);
|
|
111
|
-
const variableNode = VAR__namespace.getVariableNode(variable, 0);
|
|
112
|
-
if (variableNode?.type === types.AST_NODE_TYPES.ObjectExpression) {
|
|
113
|
-
return findPropInProperties(
|
|
114
|
-
name,
|
|
115
|
-
variableNode.properties,
|
|
116
|
-
initialScope,
|
|
117
|
-
[...seenProps, prop.argument.name]
|
|
118
|
-
) != null;
|
|
119
|
-
}
|
|
120
|
-
return false;
|
|
121
|
-
}
|
|
122
|
-
case types.AST_NODE_TYPES.ObjectExpression: {
|
|
123
|
-
return findPropInProperties(
|
|
124
|
-
name,
|
|
125
|
-
prop.argument.properties,
|
|
126
|
-
initialScope,
|
|
127
|
-
seenProps
|
|
128
|
-
) != null;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
return false;
|
|
132
|
-
}
|
|
133
|
-
return false;
|
|
134
|
-
});
|
|
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}`;
|
|
135
102
|
}
|
|
136
|
-
function
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
case types.AST_NODE_TYPES.ObjectExpression:
|
|
151
|
-
return findPropInProperties(name, attr.argument.properties, initialScope) != null;
|
|
152
|
-
}
|
|
153
|
-
return false;
|
|
154
|
-
});
|
|
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;
|
|
155
116
|
}
|
|
156
117
|
|
|
157
|
-
// src/has-
|
|
158
|
-
function
|
|
159
|
-
return
|
|
118
|
+
// src/has-attribute.ts
|
|
119
|
+
function hasAttribute(name, initialScope, attributes) {
|
|
120
|
+
return getAttributeNode(name, initialScope, attributes) != null;
|
|
160
121
|
}
|
|
161
|
-
function
|
|
162
|
-
return
|
|
122
|
+
function hasAnyAttribute(names, initialScope, attributes) {
|
|
123
|
+
return names.some((n) => hasAttribute(n, initialScope, attributes));
|
|
163
124
|
}
|
|
164
|
-
function
|
|
165
|
-
return
|
|
125
|
+
function hasEveryAttribute(names, initialScope, attributes) {
|
|
126
|
+
return names.every((n) => hasAttribute(n, initialScope, attributes));
|
|
166
127
|
}
|
|
167
128
|
function isKeyedElement(node, initialScope) {
|
|
168
|
-
return node.type === types.AST_NODE_TYPES.JSXElement &&
|
|
129
|
+
return node.type === types.AST_NODE_TYPES.JSXElement && hasAttribute("key", initialScope, node.openingElement.attributes);
|
|
169
130
|
}
|
|
170
131
|
function isBuiltInElement(node) {
|
|
171
132
|
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);
|
|
@@ -288,6 +249,9 @@ function isLineBreak(node) {
|
|
|
288
249
|
function isPaddingSpaces(node) {
|
|
289
250
|
return isLiteral(node) && isWhiteSpace(node) && node.raw.includes("\n");
|
|
290
251
|
}
|
|
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
|
+
}
|
|
291
255
|
|
|
292
256
|
// src/xhtml-entities.ts
|
|
293
257
|
var xhtmlEntities = {
|
|
@@ -560,16 +524,14 @@ function unescapeStringLiteralText(text) {
|
|
|
560
524
|
|
|
561
525
|
exports.DEFAULT_JSX_VALUE_HINT = DEFAULT_JSX_VALUE_HINT;
|
|
562
526
|
exports.JSXValueHint = JSXValueHint;
|
|
563
|
-
exports.
|
|
564
|
-
exports.
|
|
565
|
-
exports.
|
|
527
|
+
exports.findParentAttributeNode = findParentAttributeNode;
|
|
528
|
+
exports.getAttributeName = getAttributeName;
|
|
529
|
+
exports.getAttributeNode = getAttributeNode;
|
|
530
|
+
exports.getAttributeStaticValue = getAttributeStaticValue;
|
|
566
531
|
exports.getElementName = getElementName;
|
|
567
|
-
exports.
|
|
568
|
-
exports.
|
|
569
|
-
exports.
|
|
570
|
-
exports.hasAnyProp = hasAnyProp;
|
|
571
|
-
exports.hasEveryProp = hasEveryProp;
|
|
572
|
-
exports.hasProp = hasProp;
|
|
532
|
+
exports.hasAnyAttribute = hasAnyAttribute;
|
|
533
|
+
exports.hasAttribute = hasAttribute;
|
|
534
|
+
exports.hasEveryAttribute = hasEveryAttribute;
|
|
573
535
|
exports.isBuiltInElement = isBuiltInElement;
|
|
574
536
|
exports.isJSXValue = isJSXValue;
|
|
575
537
|
exports.isKeyedElement = isKeyedElement;
|
|
@@ -578,5 +540,6 @@ exports.isLiteral = isLiteral;
|
|
|
578
540
|
exports.isPaddingSpaces = isPaddingSpaces;
|
|
579
541
|
exports.isUserDefinedElement = isUserDefinedElement;
|
|
580
542
|
exports.isWhiteSpace = isWhiteSpace;
|
|
543
|
+
exports.toResolvedAttributeValue = toResolvedAttributeValue;
|
|
581
544
|
exports.unescapeStringLiteralText = unescapeStringLiteralText;
|
|
582
545
|
exports.xhtmlEntities = xhtmlEntities;
|
package/dist/index.mjs
CHANGED
|
@@ -1,39 +1,17 @@
|
|
|
1
1
|
import * as AST3 from '@eslint-react/ast';
|
|
2
|
-
import { returnTrue } from '@eslint-react/eff';
|
|
2
|
+
import { returnTrue, identity, _ } from '@eslint-react/eff';
|
|
3
3
|
import { AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
4
4
|
import * as VAR from '@eslint-react/var';
|
|
5
|
+
import { match, P } from 'ts-pattern';
|
|
5
6
|
|
|
6
|
-
// src/find-parent-
|
|
7
|
-
function
|
|
7
|
+
// src/find-parent-attribute-node.ts
|
|
8
|
+
function findParentAttributeNode(node, test = returnTrue) {
|
|
8
9
|
const guard = (node2) => {
|
|
9
10
|
return node2.type === AST_NODE_TYPES.JSXAttribute && test(node2);
|
|
10
11
|
};
|
|
11
|
-
return AST3.
|
|
12
|
+
return AST3.findParentNode(node, guard);
|
|
12
13
|
}
|
|
13
|
-
function
|
|
14
|
-
if (object.type === AST_NODE_TYPES.JSXMemberExpression) {
|
|
15
|
-
return `${resolveJSXMemberExpressions(object.object, object.property)}.${property.name}`;
|
|
16
|
-
}
|
|
17
|
-
if (object.type === AST_NODE_TYPES.JSXNamespacedName) {
|
|
18
|
-
return `${object.namespace.name}:${object.name.name}.${property.name}`;
|
|
19
|
-
}
|
|
20
|
-
return `${object.name}.${property.name}`;
|
|
21
|
-
}
|
|
22
|
-
function getElementName(node) {
|
|
23
|
-
if (node.type === AST_NODE_TYPES.JSXOpeningFragment) {
|
|
24
|
-
return "<>";
|
|
25
|
-
}
|
|
26
|
-
const { name } = node;
|
|
27
|
-
if (name.type === AST_NODE_TYPES.JSXMemberExpression) {
|
|
28
|
-
const { object, property } = name;
|
|
29
|
-
return resolveJSXMemberExpressions(object, property);
|
|
30
|
-
}
|
|
31
|
-
if (name.type === AST_NODE_TYPES.JSXNamespacedName) {
|
|
32
|
-
return `${name.namespace.name}:${name.name.name}`;
|
|
33
|
-
}
|
|
34
|
-
return name.name;
|
|
35
|
-
}
|
|
36
|
-
function getPropName(node) {
|
|
14
|
+
function getAttributeName(node) {
|
|
37
15
|
switch (node.name.type) {
|
|
38
16
|
case AST_NODE_TYPES.JSXIdentifier:
|
|
39
17
|
return node.name.name;
|
|
@@ -41,108 +19,91 @@ function getPropName(node) {
|
|
|
41
19
|
return `${node.name.namespace.name}:${node.name.name.name}`;
|
|
42
20
|
}
|
|
43
21
|
}
|
|
44
|
-
function
|
|
45
|
-
return
|
|
22
|
+
function getAttributeNode(name, initialScope, attributes) {
|
|
23
|
+
return attributes.findLast((attr) => {
|
|
24
|
+
if (attr.type === AST_NODE_TYPES.JSXAttribute) {
|
|
25
|
+
return getAttributeName(attr) === name;
|
|
26
|
+
}
|
|
27
|
+
switch (attr.argument.type) {
|
|
28
|
+
case AST_NODE_TYPES.Identifier: {
|
|
29
|
+
const variable = VAR.findVariable(attr.argument.name, initialScope);
|
|
30
|
+
const variableNode = VAR.getVariableNode(variable, 0);
|
|
31
|
+
if (variableNode?.type === AST_NODE_TYPES.ObjectExpression) {
|
|
32
|
+
return VAR.findPropertyInProperties(name, variableNode.properties, initialScope) != null;
|
|
33
|
+
}
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
case AST_NODE_TYPES.ObjectExpression:
|
|
37
|
+
return VAR.findPropertyInProperties(name, attr.argument.properties, initialScope) != null;
|
|
38
|
+
}
|
|
39
|
+
return false;
|
|
40
|
+
});
|
|
46
41
|
}
|
|
47
|
-
function
|
|
48
|
-
switch (
|
|
42
|
+
function getAttributeStaticValue(node, initialScope) {
|
|
43
|
+
switch (node.type) {
|
|
49
44
|
case AST_NODE_TYPES.JSXAttribute:
|
|
50
|
-
if (
|
|
45
|
+
if (node.value?.type === AST_NODE_TYPES.Literal) {
|
|
51
46
|
return {
|
|
52
47
|
kind: "some",
|
|
53
|
-
node:
|
|
48
|
+
node: node.value,
|
|
54
49
|
initialScope,
|
|
55
|
-
value:
|
|
50
|
+
value: node.value.value
|
|
56
51
|
};
|
|
57
52
|
}
|
|
58
|
-
if (
|
|
53
|
+
if (node.value?.type === AST_NODE_TYPES.JSXExpressionContainer) {
|
|
59
54
|
return {
|
|
60
55
|
kind: "lazy",
|
|
61
|
-
node:
|
|
56
|
+
node: node.value.expression,
|
|
62
57
|
initialScope
|
|
63
58
|
};
|
|
64
59
|
}
|
|
65
|
-
return { kind: "none", node
|
|
60
|
+
return { kind: "none", node, initialScope };
|
|
66
61
|
case AST_NODE_TYPES.JSXSpreadAttribute:
|
|
67
62
|
return {
|
|
68
63
|
kind: "lazy",
|
|
69
|
-
node:
|
|
64
|
+
node: node.argument,
|
|
70
65
|
initialScope
|
|
71
66
|
};
|
|
72
67
|
default:
|
|
73
|
-
return { kind: "none", node
|
|
68
|
+
return { kind: "none", node, initialScope };
|
|
74
69
|
}
|
|
75
70
|
}
|
|
76
|
-
function
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (seenProps.includes(prop.argument.name)) {
|
|
85
|
-
return false;
|
|
86
|
-
}
|
|
87
|
-
const variable = VAR.findVariable(prop.argument.name, initialScope);
|
|
88
|
-
const variableNode = VAR.getVariableNode(variable, 0);
|
|
89
|
-
if (variableNode?.type === AST_NODE_TYPES.ObjectExpression) {
|
|
90
|
-
return findPropInProperties(
|
|
91
|
-
name,
|
|
92
|
-
variableNode.properties,
|
|
93
|
-
initialScope,
|
|
94
|
-
[...seenProps, prop.argument.name]
|
|
95
|
-
) != null;
|
|
96
|
-
}
|
|
97
|
-
return false;
|
|
98
|
-
}
|
|
99
|
-
case AST_NODE_TYPES.ObjectExpression: {
|
|
100
|
-
return findPropInProperties(
|
|
101
|
-
name,
|
|
102
|
-
prop.argument.properties,
|
|
103
|
-
initialScope,
|
|
104
|
-
seenProps
|
|
105
|
-
) != null;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
return false;
|
|
109
|
-
}
|
|
110
|
-
return false;
|
|
111
|
-
});
|
|
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}`;
|
|
112
79
|
}
|
|
113
|
-
function
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
case AST_NODE_TYPES.ObjectExpression:
|
|
128
|
-
return findPropInProperties(name, attr.argument.properties, initialScope) != null;
|
|
129
|
-
}
|
|
130
|
-
return false;
|
|
131
|
-
});
|
|
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;
|
|
132
93
|
}
|
|
133
94
|
|
|
134
|
-
// src/has-
|
|
135
|
-
function
|
|
136
|
-
return
|
|
95
|
+
// src/has-attribute.ts
|
|
96
|
+
function hasAttribute(name, initialScope, attributes) {
|
|
97
|
+
return getAttributeNode(name, initialScope, attributes) != null;
|
|
137
98
|
}
|
|
138
|
-
function
|
|
139
|
-
return
|
|
99
|
+
function hasAnyAttribute(names, initialScope, attributes) {
|
|
100
|
+
return names.some((n) => hasAttribute(n, initialScope, attributes));
|
|
140
101
|
}
|
|
141
|
-
function
|
|
142
|
-
return
|
|
102
|
+
function hasEveryAttribute(names, initialScope, attributes) {
|
|
103
|
+
return names.every((n) => hasAttribute(n, initialScope, attributes));
|
|
143
104
|
}
|
|
144
105
|
function isKeyedElement(node, initialScope) {
|
|
145
|
-
return node.type === AST_NODE_TYPES.JSXElement &&
|
|
106
|
+
return node.type === AST_NODE_TYPES.JSXElement && hasAttribute("key", initialScope, node.openingElement.attributes);
|
|
146
107
|
}
|
|
147
108
|
function isBuiltInElement(node) {
|
|
148
109
|
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);
|
|
@@ -265,6 +226,9 @@ function isLineBreak(node) {
|
|
|
265
226
|
function isPaddingSpaces(node) {
|
|
266
227
|
return isLiteral(node) && isWhiteSpace(node) && node.raw.includes("\n");
|
|
267
228
|
}
|
|
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
|
+
}
|
|
268
232
|
|
|
269
233
|
// src/xhtml-entities.ts
|
|
270
234
|
var xhtmlEntities = {
|
|
@@ -535,4 +499,4 @@ function unescapeStringLiteralText(text) {
|
|
|
535
499
|
});
|
|
536
500
|
}
|
|
537
501
|
|
|
538
|
-
export { DEFAULT_JSX_VALUE_HINT, JSXValueHint,
|
|
502
|
+
export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, findParentAttributeNode, getAttributeName, getAttributeNode, getAttributeStaticValue, getElementName, hasAnyAttribute, hasAttribute, hasEveryAttribute, isBuiltInElement, isJSXValue, isKeyedElement, isLineBreak, isLiteral, isPaddingSpaces, isUserDefinedElement, isWhiteSpace, toResolvedAttributeValue, 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.11",
|
|
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": {
|
|
@@ -33,14 +33,13 @@
|
|
|
33
33
|
"./package.json"
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@typescript-eslint/scope-manager": "^8.
|
|
37
|
-
"@typescript-eslint/types": "^8.
|
|
38
|
-
"@typescript-eslint/utils": "^8.
|
|
36
|
+
"@typescript-eslint/scope-manager": "^8.20.0",
|
|
37
|
+
"@typescript-eslint/types": "^8.20.0",
|
|
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/
|
|
42
|
-
"@eslint-react/var": "1.24.0-next.
|
|
43
|
-
"@eslint-react/eff": "1.24.0-next.1"
|
|
40
|
+
"@eslint-react/ast": "1.24.0-next.11",
|
|
41
|
+
"@eslint-react/eff": "1.24.0-next.11",
|
|
42
|
+
"@eslint-react/var": "1.24.0-next.11"
|
|
44
43
|
},
|
|
45
44
|
"devDependencies": {
|
|
46
45
|
"tsup": "^8.3.5",
|