@eslint-react/jsx 1.46.1-next.0 → 4.0.0-beta.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@eslint-react/jsx",
3
- "version": "1.46.1-next.0",
4
- "description": "ESLint React's TSESTree AST utility module for static analysis of JSX.",
3
+ "version": "4.0.0-beta.0",
4
+ "description": "ESLint React's TSESTree JSX utility module for static analysis of JSX patterns.",
5
5
  "homepage": "https://github.com/Rel1cx/eslint-react",
6
6
  "bugs": {
7
7
  "url": "https://github.com/Rel1cx/eslint-react/issues"
@@ -12,48 +12,45 @@
12
12
  "directory": "packages/utilities/jsx"
13
13
  },
14
14
  "license": "MIT",
15
- "author": "Rel1cx<rel1cx@proton.me>",
15
+ "author": "Rel1cx",
16
16
  "sideEffects": false,
17
+ "type": "module",
17
18
  "exports": {
18
19
  ".": {
19
- "import": {
20
- "types": "./dist/index.d.mts",
21
- "default": "./dist/index.mjs"
22
- },
23
- "require": {
24
- "types": "./dist/index.d.ts",
25
- "default": "./dist/index.js"
26
- }
20
+ "types": "./dist/index.d.ts",
21
+ "import": "./dist/index.js"
27
22
  },
28
23
  "./package.json": "./package.json"
29
24
  },
30
- "main": "dist/index.js",
31
- "module": "dist/index.mjs",
32
- "types": "dist/index.d.ts",
25
+ "main": "./dist/index.js",
26
+ "module": "./dist/index.js",
27
+ "types": "./dist/index.d.ts",
33
28
  "files": [
34
29
  "dist",
35
30
  "./package.json"
36
31
  ],
37
32
  "dependencies": {
38
- "@typescript-eslint/scope-manager": "^8.29.1",
39
- "@typescript-eslint/types": "^8.29.1",
40
- "@typescript-eslint/utils": "^8.29.1",
41
- "ts-pattern": "^5.7.0",
42
- "@eslint-react/ast": "1.46.1-next.0",
43
- "@eslint-react/var": "1.46.1-next.0",
44
- "@eslint-react/eff": "1.46.1-next.0"
33
+ "@typescript-eslint/types": "^8.57.2",
34
+ "@typescript-eslint/utils": "^8.57.2",
35
+ "ts-pattern": "^5.9.0",
36
+ "@eslint-react/ast": "4.0.0-beta.0",
37
+ "@eslint-react/shared": "4.0.0-beta.0",
38
+ "@eslint-react/var": "4.0.0-beta.0"
45
39
  },
46
40
  "devDependencies": {
47
- "tsup": "^8.4.0",
41
+ "tsdown": "^0.21.4",
48
42
  "@local/configs": "0.0.0"
49
43
  },
44
+ "peerDependencies": {
45
+ "eslint": "^10.0.0",
46
+ "typescript": "*"
47
+ },
50
48
  "engines": {
51
- "bun": ">=1.0.15",
52
- "node": ">=18.18.0"
49
+ "node": ">=22.0.0"
53
50
  },
54
51
  "scripts": {
55
- "build": "tsup",
52
+ "build": "tsdown --dts-resolve",
56
53
  "lint:publish": "publint",
57
- "lint:ts": "tsc --noEmit"
54
+ "lint:ts": "tsl"
58
55
  }
59
56
  }
package/dist/index.d.mts DELETED
@@ -1,102 +0,0 @@
1
- import { _ } from '@eslint-react/eff';
2
- import { Scope } from '@typescript-eslint/scope-manager';
3
- import { TSESTree } from '@typescript-eslint/utils';
4
- import * as VAR from '@eslint-react/var';
5
- import { TSESTree as TSESTree$1 } from '@typescript-eslint/types';
6
-
7
- /**
8
- * Get the JSX attribute node with the given name
9
- * @param name The name of the attribute
10
- * @param attributes The attributes to search
11
- * @param initialScope The initial scope to use for variable resolution
12
- * @returns The JSX attribute node or undefined
13
- */
14
- declare function getAttribute(name: string, attributes: (TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute)[], initialScope?: Scope): TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute | _;
15
-
16
- /**
17
- * Get the stringified name of a JSX attribute
18
- * @param node The JSX attribute node
19
- * @returns The name of the attribute
20
- */
21
- declare function getAttributeName(node: TSESTree.JSXAttribute): string;
22
-
23
- /**
24
- * Get a StaticValue of the attribute value
25
- * @param node The JSX attribute node
26
- * @param name The name of the attribute
27
- * @param initialScope The initial scope to use
28
- * @returns The StaticValue of the attribute value
29
- */
30
- declare function getAttributeValue(node: TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute, name: string, initialScope: Scope): Exclude<VAR.LazyValue, {
31
- kind: "lazy";
32
- }>;
33
-
34
- declare function hasAttribute(name: string, attributes: TSESTree$1.JSXOpeningElement["attributes"], initialScope?: Scope): boolean;
35
- declare function hasAnyAttribute(names: string[], attributes: TSESTree$1.JSXOpeningElement["attributes"], initialScope?: Scope): boolean;
36
- declare function hasEveryAttribute(names: string[], attributes: TSESTree$1.JSXOpeningElement["attributes"], initialScope?: Scope): boolean;
37
-
38
- /**
39
- * Find the parent JSX attribute node of a node
40
- * @param node The node to find the parent attribute of
41
- * @param test The test to apply to the parent attribute
42
- * @returns The parent attribute node or undefined
43
- */
44
- declare function findParentAttribute(node: TSESTree$1.Node, test?: (node: TSESTree$1.JSXAttribute) => boolean): TSESTree$1.JSXAttribute | _;
45
-
46
- /**
47
- * Get the stringified type of a JSX element
48
- * @param node The JSX element node
49
- * @returns The type of the element
50
- */
51
- declare function getElementType(node: TSESTree$1.JSXElement | TSESTree$1.JSXFragment): string;
52
-
53
- declare function isHostElement(node: TSESTree$1.Node): boolean;
54
- declare function isKeyedElement(node: TSESTree$1.Node, initialScope?: Scope): boolean;
55
- declare function isFragmentElement(node: TSESTree$1.Node | null | _, allowJSXFragment?: false): node is TSESTree$1.JSXElement;
56
- declare function isFragmentElement(node: TSESTree$1.Node | null | _, allowJSXFragment?: true): node is TSESTree$1.JSXElement | TSESTree$1.JSXFragment;
57
-
58
- type JSXDetectionHint = bigint;
59
- declare const JSXDetectionHint: {
60
- readonly None: 0n;
61
- readonly SkipUndefined: bigint;
62
- readonly SkipNullLiteral: bigint;
63
- readonly SkipBooleanLiteral: bigint;
64
- readonly SkipStringLiteral: bigint;
65
- readonly SkipNumberLiteral: bigint;
66
- readonly SkipBigIntLiteral: bigint;
67
- readonly SkipEmptyArray: bigint;
68
- readonly SkipCreateElement: bigint;
69
- readonly StrictArray: bigint;
70
- readonly StrictLogical: bigint;
71
- readonly StrictConditional: bigint;
72
- };
73
- declare const DEFAULT_JSX_DETECTION_HINT: bigint;
74
-
75
- type TSESTreeJSX = TSESTree.JSXAttribute | TSESTree.JSXClosingElement | TSESTree.JSXClosingFragment | TSESTree.JSXElement | TSESTree.JSXEmptyExpression | TSESTree.JSXExpressionContainer | TSESTree.JSXFragment | TSESTree.JSXIdentifier | TSESTree.JSXMemberExpression | TSESTree.JSXNamespacedName | TSESTree.JSXOpeningElement | TSESTree.JSXOpeningFragment | TSESTree.JSXSpreadAttribute | TSESTree.JSXSpreadChild | TSESTree.JSXText;
76
- declare const isJSX: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXIdentifier | TSESTree.JSXMemberExpression | TSESTree.JSXNamespacedName | TSESTree.JSXOpeningElement | TSESTree.JSXClosingElement | TSESTree.JSXOpeningFragment | TSESTree.JSXClosingFragment | TSESTree.JSXText | TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute | TSESTree.JSXElement | TSESTree.JSXFragment | TSESTree.JSXExpressionContainer | TSESTree.JSXSpreadChild | TSESTree.JSXEmptyExpression;
77
- /**
78
- * Check if a node is a `JSXText` or a `Literal` node
79
- * @param node The AST node to check
80
- * @returns `true` if the node is a `JSXText` or a `Literal` node
81
- */
82
- declare function isJsxText(node: TSESTree.Node | null | _): node is TSESTree.JSXText | TSESTree.Literal;
83
- /**
84
- * Heuristic decision to determine if a node is a JSX-like node.
85
- * @param code The sourceCode object
86
- * @param code.getScope The function to get the scope of a node
87
- * @param node The AST node to check
88
- * @param hint The `JSXDetectionHint` to use
89
- * @returns boolean
90
- */
91
- declare function isJsxLike(code: {
92
- getScope: (node: TSESTree.Node) => Scope;
93
- }, node: TSESTree.Node | _ | null, hint?: JSXDetectionHint): boolean;
94
-
95
- /**
96
- * Get the stringified representation of a JSX node
97
- * @param node The JSX node
98
- * @returns The stringified representation
99
- */
100
- declare function toString(node: TSESTree.JSXIdentifier | TSESTree.JSXMemberExpression | TSESTree.JSXNamespacedName | TSESTree.JSXOpeningElement | TSESTree.JSXClosingElement | TSESTree.JSXOpeningFragment | TSESTree.JSXClosingFragment | TSESTree.JSXText): string;
101
-
102
- export { DEFAULT_JSX_DETECTION_HINT, JSXDetectionHint, type TSESTreeJSX, findParentAttribute, getAttribute, getAttributeName, getAttributeValue, getElementType, hasAnyAttribute, hasAttribute, hasEveryAttribute, isFragmentElement, isHostElement, isJSX, isJsxLike, isJsxText, isKeyedElement, toString };
package/dist/index.mjs DELETED
@@ -1,257 +0,0 @@
1
- import * as VAR from '@eslint-react/var';
2
- import { AST_NODE_TYPES } from '@typescript-eslint/types';
3
- import { match, P } from 'ts-pattern';
4
- import * as AST2 from '@eslint-react/ast';
5
- import { constTrue } from '@eslint-react/eff';
6
-
7
- // src/attribute/attribute.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/attribute-name.ts
30
- function getAttributeName(node) {
31
- return toString(node.name);
32
- }
33
-
34
- // src/attribute/attribute.ts
35
- function getAttribute(name, attributes, initialScope) {
36
- return attributes.findLast((attr) => {
37
- if (attr.type === AST_NODE_TYPES.JSXAttribute) {
38
- return getAttributeName(attr) === name;
39
- }
40
- if (initialScope == null) return false;
41
- switch (attr.argument.type) {
42
- case AST_NODE_TYPES.Identifier: {
43
- const variable = VAR.findVariable(attr.argument.name, initialScope);
44
- const variableNode = VAR.getVariableInitNode(variable, 0);
45
- if (variableNode?.type === AST_NODE_TYPES.ObjectExpression) {
46
- return VAR.findPropertyInProperties(name, variableNode.properties, initialScope) != null;
47
- }
48
- return false;
49
- }
50
- case AST_NODE_TYPES.ObjectExpression:
51
- return VAR.findPropertyInProperties(name, attr.argument.properties, initialScope) != null;
52
- }
53
- return false;
54
- });
55
- }
56
- function getAttributeValue(node, name, initialScope) {
57
- switch (node.type) {
58
- case AST_NODE_TYPES.JSXAttribute:
59
- if (node.value?.type === AST_NODE_TYPES.Literal) {
60
- return {
61
- kind: "some",
62
- node: node.value,
63
- initialScope,
64
- value: node.value.value
65
- };
66
- }
67
- if (node.value?.type === AST_NODE_TYPES.JSXExpressionContainer) {
68
- return VAR.toStaticValue({
69
- kind: "lazy",
70
- node: node.value.expression,
71
- initialScope
72
- });
73
- }
74
- return { kind: "none", node, initialScope };
75
- case AST_NODE_TYPES.JSXSpreadAttribute: {
76
- const staticValue = VAR.toStaticValue({
77
- kind: "lazy",
78
- node: node.argument,
79
- initialScope
80
- });
81
- if (staticValue.kind === "none") {
82
- return staticValue;
83
- }
84
- return match(staticValue.value).with({ [name]: P.select(P.any) }, (value) => ({
85
- kind: "some",
86
- node: node.argument,
87
- initialScope,
88
- value
89
- })).otherwise(() => ({ kind: "none", node, initialScope }));
90
- }
91
- default:
92
- return { kind: "none", node, initialScope };
93
- }
94
- }
95
-
96
- // src/attribute/has.ts
97
- function hasAttribute(name, attributes, initialScope) {
98
- return getAttribute(name, attributes, initialScope) != null;
99
- }
100
- function hasAnyAttribute(names, attributes, initialScope) {
101
- return names.some((n) => hasAttribute(n, attributes, initialScope));
102
- }
103
- function hasEveryAttribute(names, attributes, initialScope) {
104
- return names.every((n) => hasAttribute(n, attributes, initialScope));
105
- }
106
- function findParentAttribute(node, test = constTrue) {
107
- const guard = (node2) => {
108
- return node2.type === AST_NODE_TYPES.JSXAttribute && test(node2);
109
- };
110
- return AST2.findParentNode(node, guard);
111
- }
112
- function getElementType(node) {
113
- if (node.type === AST_NODE_TYPES.JSXFragment) {
114
- return "";
115
- }
116
- return toString(node.openingElement.name);
117
- }
118
- function isHostElement(node) {
119
- return node.type === AST_NODE_TYPES.JSXElement && node.openingElement.name.type === AST_NODE_TYPES.JSXIdentifier && /^[a-z]/u.test(node.openingElement.name.name);
120
- }
121
- function isKeyedElement(node, initialScope) {
122
- return node.type === AST_NODE_TYPES.JSXElement && hasAttribute("key", node.openingElement.attributes, initialScope);
123
- }
124
- function isFragmentElement(node, allowJSXFragment = false) {
125
- if (node == null) return false;
126
- if (node.type !== AST_NODE_TYPES.JSXElement && node.type !== AST_NODE_TYPES.JSXFragment) return false;
127
- if (node.type === AST_NODE_TYPES.JSXFragment) return allowJSXFragment;
128
- return getElementType(node).split(".").at(-1) === "Fragment";
129
- }
130
-
131
- // src/jsx-detection-hint.ts
132
- var JSXDetectionHint = {
133
- None: 0n,
134
- SkipUndefined: 1n << 0n,
135
- SkipNullLiteral: 1n << 1n,
136
- SkipBooleanLiteral: 1n << 2n,
137
- SkipStringLiteral: 1n << 3n,
138
- SkipNumberLiteral: 1n << 4n,
139
- SkipBigIntLiteral: 1n << 5n,
140
- SkipEmptyArray: 1n << 6n,
141
- SkipCreateElement: 1n << 7n,
142
- StrictArray: 1n << 8n,
143
- StrictLogical: 1n << 9n,
144
- StrictConditional: 1n << 10n
145
- };
146
- var DEFAULT_JSX_DETECTION_HINT = 0n | JSXDetectionHint.SkipUndefined | JSXDetectionHint.SkipBooleanLiteral;
147
-
148
- // src/jsx-detection.ts
149
- var isJSX = AST2.isOneOf([
150
- AST_NODE_TYPES.JSXAttribute,
151
- AST_NODE_TYPES.JSXClosingElement,
152
- AST_NODE_TYPES.JSXClosingFragment,
153
- AST_NODE_TYPES.JSXElement,
154
- AST_NODE_TYPES.JSXEmptyExpression,
155
- AST_NODE_TYPES.JSXExpressionContainer,
156
- AST_NODE_TYPES.JSXFragment,
157
- AST_NODE_TYPES.JSXIdentifier,
158
- AST_NODE_TYPES.JSXMemberExpression,
159
- AST_NODE_TYPES.JSXNamespacedName,
160
- AST_NODE_TYPES.JSXOpeningElement,
161
- AST_NODE_TYPES.JSXOpeningFragment,
162
- AST_NODE_TYPES.JSXSpreadAttribute,
163
- AST_NODE_TYPES.JSXSpreadChild,
164
- AST_NODE_TYPES.JSXText
165
- ]);
166
- function isJsxText(node) {
167
- if (node == null) return false;
168
- return node.type === AST_NODE_TYPES.JSXText || node.type === AST_NODE_TYPES.Literal;
169
- }
170
- function isJsxLike(code, node, hint = DEFAULT_JSX_DETECTION_HINT) {
171
- if (node == null) return false;
172
- if (isJSX(node)) return true;
173
- switch (node.type) {
174
- case AST_NODE_TYPES.Literal: {
175
- switch (typeof node.value) {
176
- case "boolean":
177
- return !(hint & JSXDetectionHint.SkipBooleanLiteral);
178
- case "string":
179
- return !(hint & JSXDetectionHint.SkipStringLiteral);
180
- case "number":
181
- return !(hint & JSXDetectionHint.SkipNumberLiteral);
182
- case "bigint":
183
- return !(hint & JSXDetectionHint.SkipBigIntLiteral);
184
- }
185
- if (node.value == null) {
186
- return !(hint & JSXDetectionHint.SkipNullLiteral);
187
- }
188
- return false;
189
- }
190
- case AST_NODE_TYPES.TemplateLiteral: {
191
- return !(hint & JSXDetectionHint.SkipStringLiteral);
192
- }
193
- case AST_NODE_TYPES.ArrayExpression: {
194
- if (hint & JSXDetectionHint.StrictArray) {
195
- return node.elements.every((n) => isJsxLike(code, n, hint));
196
- }
197
- return node.elements.some((n) => isJsxLike(code, n, hint));
198
- }
199
- case AST_NODE_TYPES.LogicalExpression: {
200
- if (hint & JSXDetectionHint.StrictLogical) {
201
- return isJsxLike(code, node.left, hint) && isJsxLike(code, node.right, hint);
202
- }
203
- return isJsxLike(code, node.left, hint) || isJsxLike(code, node.right, hint);
204
- }
205
- case AST_NODE_TYPES.ConditionalExpression: {
206
- let leftHasJSX2 = function(node2) {
207
- if (Array.isArray(node2.consequent)) {
208
- if (node2.consequent.length === 0) {
209
- return !(hint & JSXDetectionHint.SkipEmptyArray);
210
- }
211
- if (hint & JSXDetectionHint.StrictArray) {
212
- return node2.consequent.every((n) => isJsxLike(code, n, hint));
213
- }
214
- return node2.consequent.some((n) => isJsxLike(code, n, hint));
215
- }
216
- return isJsxLike(code, node2.consequent, hint);
217
- }, rightHasJSX2 = function(node2) {
218
- return isJsxLike(code, node2.alternate, hint);
219
- };
220
- if (hint & JSXDetectionHint.StrictConditional) {
221
- return leftHasJSX2(node) && rightHasJSX2(node);
222
- }
223
- return leftHasJSX2(node) || rightHasJSX2(node);
224
- }
225
- case AST_NODE_TYPES.SequenceExpression: {
226
- const exp = node.expressions.at(-1);
227
- return isJsxLike(code, exp, hint);
228
- }
229
- case AST_NODE_TYPES.CallExpression: {
230
- if (hint & JSXDetectionHint.SkipCreateElement) {
231
- return false;
232
- }
233
- switch (node.callee.type) {
234
- case AST_NODE_TYPES.Identifier:
235
- return node.callee.name === "createElement";
236
- case AST_NODE_TYPES.MemberExpression:
237
- return node.callee.property.type === AST_NODE_TYPES.Identifier && node.callee.property.name === "createElement";
238
- }
239
- return false;
240
- }
241
- case AST_NODE_TYPES.Identifier: {
242
- const { name } = node;
243
- if (name === "undefined") {
244
- return !(hint & JSXDetectionHint.SkipUndefined);
245
- }
246
- if (AST2.isJSXTagNameExpression(node)) {
247
- return true;
248
- }
249
- const variable = VAR.findVariable(name, code.getScope(node));
250
- const variableNode = variable && VAR.getVariableInitNode(variable, 0);
251
- return !!variableNode && isJsxLike(code, variableNode, hint);
252
- }
253
- }
254
- return false;
255
- }
256
-
257
- export { DEFAULT_JSX_DETECTION_HINT, JSXDetectionHint, findParentAttribute, getAttribute, getAttributeName, getAttributeValue, getElementType, hasAnyAttribute, hasAttribute, hasEveryAttribute, isFragmentElement, isHostElement, isJSX, isJsxLike, isJsxText, isKeyedElement, toString };