@eslint-react/jsx 1.23.3-next.0 → 1.23.3-next.1
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 +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +89 -57
- package/dist/index.mjs +89 -57
- package/package.json +5 -5
package/dist/index.d.mts
CHANGED
|
@@ -82,13 +82,14 @@ declare function isUserDefinedElement(node: TSESTree.Node): boolean;
|
|
|
82
82
|
|
|
83
83
|
declare const JSXValueHint: {
|
|
84
84
|
readonly None: 0n;
|
|
85
|
+
readonly SkipUndefined: bigint;
|
|
85
86
|
readonly SkipNullLiteral: bigint;
|
|
86
|
-
readonly SkipUndefinedLiteral: bigint;
|
|
87
87
|
readonly SkipBooleanLiteral: bigint;
|
|
88
88
|
readonly SkipStringLiteral: bigint;
|
|
89
89
|
readonly SkipNumberLiteral: bigint;
|
|
90
|
-
readonly
|
|
90
|
+
readonly SkipBigIntLiteral: bigint;
|
|
91
91
|
readonly SkipEmptyArray: bigint;
|
|
92
|
+
readonly SkipCreateElement: bigint;
|
|
92
93
|
readonly StrictArray: bigint;
|
|
93
94
|
readonly StrictLogical: bigint;
|
|
94
95
|
readonly StrictConditional: bigint;
|
package/dist/index.d.ts
CHANGED
|
@@ -82,13 +82,14 @@ declare function isUserDefinedElement(node: TSESTree.Node): boolean;
|
|
|
82
82
|
|
|
83
83
|
declare const JSXValueHint: {
|
|
84
84
|
readonly None: 0n;
|
|
85
|
+
readonly SkipUndefined: bigint;
|
|
85
86
|
readonly SkipNullLiteral: bigint;
|
|
86
|
-
readonly SkipUndefinedLiteral: bigint;
|
|
87
87
|
readonly SkipBooleanLiteral: bigint;
|
|
88
88
|
readonly SkipStringLiteral: bigint;
|
|
89
89
|
readonly SkipNumberLiteral: bigint;
|
|
90
|
-
readonly
|
|
90
|
+
readonly SkipBigIntLiteral: bigint;
|
|
91
91
|
readonly SkipEmptyArray: bigint;
|
|
92
|
+
readonly SkipCreateElement: bigint;
|
|
92
93
|
readonly StrictArray: bigint;
|
|
93
94
|
readonly StrictLogical: bigint;
|
|
94
95
|
readonly StrictConditional: bigint;
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,6 @@ var AST2 = 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');
|
|
8
7
|
var types$1 = require('@eslint-react/types');
|
|
9
8
|
|
|
10
9
|
function _interopNamespace(e) {
|
|
@@ -183,77 +182,110 @@ function isUserDefinedElement(node) {
|
|
|
183
182
|
}
|
|
184
183
|
var JSXValueHint = {
|
|
185
184
|
None: 0n,
|
|
186
|
-
|
|
187
|
-
|
|
185
|
+
SkipUndefined: 1n << 0n,
|
|
186
|
+
SkipNullLiteral: 1n << 1n,
|
|
188
187
|
SkipBooleanLiteral: 1n << 2n,
|
|
189
188
|
SkipStringLiteral: 1n << 3n,
|
|
190
189
|
SkipNumberLiteral: 1n << 4n,
|
|
191
|
-
|
|
190
|
+
SkipBigIntLiteral: 1n << 5n,
|
|
192
191
|
SkipEmptyArray: 1n << 6n,
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
192
|
+
SkipCreateElement: 1n << 7n,
|
|
193
|
+
StrictArray: 1n << 8n,
|
|
194
|
+
StrictLogical: 1n << 9n,
|
|
195
|
+
StrictConditional: 1n << 10n
|
|
196
196
|
};
|
|
197
|
-
var DEFAULT_JSX_VALUE_HINT = 0n | JSXValueHint.
|
|
197
|
+
var DEFAULT_JSX_VALUE_HINT = 0n | JSXValueHint.SkipUndefined | JSXValueHint.SkipBooleanLiteral;
|
|
198
198
|
function isJSXValue(node, jsxCtx, hint = DEFAULT_JSX_VALUE_HINT) {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
if (hint & JSXValueHint.StrictArray) {
|
|
206
|
-
return node2.elements.every((n) => isJSXValue(n, jsxCtx, hint));
|
|
199
|
+
switch (node?.type) {
|
|
200
|
+
case types.AST_NODE_TYPES.JSXElement:
|
|
201
|
+
case types.AST_NODE_TYPES.JSXFragment:
|
|
202
|
+
case types.AST_NODE_TYPES.JSXMemberExpression:
|
|
203
|
+
case types.AST_NODE_TYPES.JSXNamespacedName: {
|
|
204
|
+
return true;
|
|
207
205
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
return !(hint & JSXValueHint.
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
206
|
+
case types.AST_NODE_TYPES.Literal: {
|
|
207
|
+
switch (typeof node.value) {
|
|
208
|
+
case "boolean":
|
|
209
|
+
return !(hint & JSXValueHint.SkipBooleanLiteral);
|
|
210
|
+
case "string":
|
|
211
|
+
return !(hint & JSXValueHint.SkipStringLiteral);
|
|
212
|
+
case "number":
|
|
213
|
+
return !(hint & JSXValueHint.SkipNumberLiteral);
|
|
214
|
+
case "bigint":
|
|
215
|
+
return !(hint & JSXValueHint.SkipBigIntLiteral);
|
|
216
|
+
}
|
|
217
|
+
if (node.value === null) {
|
|
218
|
+
return !(hint & JSXValueHint.SkipNullLiteral);
|
|
219
219
|
}
|
|
220
|
-
return
|
|
220
|
+
return false;
|
|
221
221
|
}
|
|
222
|
-
|
|
223
|
-
return
|
|
222
|
+
case types.AST_NODE_TYPES.TemplateLiteral: {
|
|
223
|
+
return !(hint & JSXValueHint.SkipStringLiteral);
|
|
224
224
|
}
|
|
225
|
-
|
|
226
|
-
|
|
225
|
+
case types.AST_NODE_TYPES.ArrayExpression: {
|
|
226
|
+
if (hint & JSXValueHint.StrictArray) {
|
|
227
|
+
return node.elements.every((n) => isJSXValue(n, jsxCtx, hint));
|
|
228
|
+
}
|
|
229
|
+
return node.elements.some((n) => isJSXValue(n, jsxCtx, hint));
|
|
227
230
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
231
|
+
case types.AST_NODE_TYPES.LogicalExpression: {
|
|
232
|
+
if (hint & JSXValueHint.StrictLogical) {
|
|
233
|
+
return isJSXValue(node.left, jsxCtx, hint) && isJSXValue(node.right, jsxCtx, hint);
|
|
234
|
+
}
|
|
235
|
+
return isJSXValue(node.left, jsxCtx, hint) || isJSXValue(node.right, jsxCtx, hint);
|
|
232
236
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
237
|
+
case types.AST_NODE_TYPES.ConditionalExpression: {
|
|
238
|
+
let leftHasJSX2 = function(node2) {
|
|
239
|
+
if (Array.isArray(node2.consequent)) {
|
|
240
|
+
if (node2.consequent.length === 0) {
|
|
241
|
+
return !(hint & JSXValueHint.SkipEmptyArray);
|
|
242
|
+
}
|
|
243
|
+
if (hint & JSXValueHint.StrictArray) {
|
|
244
|
+
return node2.consequent.every((n) => isJSXValue(n, jsxCtx, hint));
|
|
245
|
+
}
|
|
246
|
+
return node2.consequent.some((n) => isJSXValue(n, jsxCtx, hint));
|
|
247
|
+
}
|
|
248
|
+
return isJSXValue(node2.consequent, jsxCtx, hint);
|
|
249
|
+
}, rightHasJSX2 = function(node2) {
|
|
250
|
+
return isJSXValue(node2.alternate, jsxCtx, hint);
|
|
251
|
+
};
|
|
252
|
+
if (hint & JSXValueHint.StrictConditional) {
|
|
253
|
+
return leftHasJSX2(node) && rightHasJSX2(node);
|
|
254
|
+
}
|
|
255
|
+
return leftHasJSX2(node) || rightHasJSX2(node);
|
|
240
256
|
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
if (name === "undefined") {
|
|
245
|
-
return !(hint & JSXValueHint.SkipUndefinedLiteral);
|
|
257
|
+
case types.AST_NODE_TYPES.SequenceExpression: {
|
|
258
|
+
const exp = node.expressions.at(-1);
|
|
259
|
+
return isJSXValue(exp, jsxCtx, hint);
|
|
246
260
|
}
|
|
247
|
-
|
|
248
|
-
|
|
261
|
+
case types.AST_NODE_TYPES.CallExpression: {
|
|
262
|
+
if (hint & JSXValueHint.SkipCreateElement) {
|
|
263
|
+
return false;
|
|
264
|
+
}
|
|
265
|
+
switch (node.callee.type) {
|
|
266
|
+
case types.AST_NODE_TYPES.Identifier:
|
|
267
|
+
return node.callee.name === "createElement";
|
|
268
|
+
case types.AST_NODE_TYPES.MemberExpression:
|
|
269
|
+
return node.callee.property.type === types.AST_NODE_TYPES.Identifier && node.callee.property.name === "createElement";
|
|
270
|
+
}
|
|
271
|
+
return false;
|
|
249
272
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
273
|
+
case types.AST_NODE_TYPES.Identifier: {
|
|
274
|
+
const { name } = node;
|
|
275
|
+
if (name === "undefined") {
|
|
276
|
+
return !(hint & JSXValueHint.SkipUndefined);
|
|
277
|
+
}
|
|
278
|
+
if (AST2__namespace.isJSXTagNameExpression(node)) {
|
|
279
|
+
return true;
|
|
280
|
+
}
|
|
281
|
+
return eff.F.pipe(
|
|
282
|
+
VAR__namespace.findVariable(name, jsxCtx.getScope(node)),
|
|
283
|
+
eff.O.flatMap(VAR__namespace.getVariableNode(0)),
|
|
284
|
+
eff.O.exists((n) => isJSXValue(n, jsxCtx, hint))
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return false;
|
|
257
289
|
}
|
|
258
290
|
var isLiteral = AST2__namespace.isOneOf([types.AST_NODE_TYPES.Literal, types.AST_NODE_TYPES.JSXText]);
|
|
259
291
|
function isWhiteSpace(node) {
|
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,6 @@ import * as AST2 from '@eslint-react/ast';
|
|
|
2
2
|
import { F, O, isString } 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';
|
|
6
5
|
import { birecord } from '@eslint-react/types';
|
|
7
6
|
|
|
8
7
|
// src/find-parent-prop.ts
|
|
@@ -160,77 +159,110 @@ function isUserDefinedElement(node) {
|
|
|
160
159
|
}
|
|
161
160
|
var JSXValueHint = {
|
|
162
161
|
None: 0n,
|
|
163
|
-
|
|
164
|
-
|
|
162
|
+
SkipUndefined: 1n << 0n,
|
|
163
|
+
SkipNullLiteral: 1n << 1n,
|
|
165
164
|
SkipBooleanLiteral: 1n << 2n,
|
|
166
165
|
SkipStringLiteral: 1n << 3n,
|
|
167
166
|
SkipNumberLiteral: 1n << 4n,
|
|
168
|
-
|
|
167
|
+
SkipBigIntLiteral: 1n << 5n,
|
|
169
168
|
SkipEmptyArray: 1n << 6n,
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
169
|
+
SkipCreateElement: 1n << 7n,
|
|
170
|
+
StrictArray: 1n << 8n,
|
|
171
|
+
StrictLogical: 1n << 9n,
|
|
172
|
+
StrictConditional: 1n << 10n
|
|
173
173
|
};
|
|
174
|
-
var DEFAULT_JSX_VALUE_HINT = 0n | JSXValueHint.
|
|
174
|
+
var DEFAULT_JSX_VALUE_HINT = 0n | JSXValueHint.SkipUndefined | JSXValueHint.SkipBooleanLiteral;
|
|
175
175
|
function isJSXValue(node, jsxCtx, hint = DEFAULT_JSX_VALUE_HINT) {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
if (hint & JSXValueHint.StrictArray) {
|
|
183
|
-
return node2.elements.every((n) => isJSXValue(n, jsxCtx, hint));
|
|
176
|
+
switch (node?.type) {
|
|
177
|
+
case AST_NODE_TYPES.JSXElement:
|
|
178
|
+
case AST_NODE_TYPES.JSXFragment:
|
|
179
|
+
case AST_NODE_TYPES.JSXMemberExpression:
|
|
180
|
+
case AST_NODE_TYPES.JSXNamespacedName: {
|
|
181
|
+
return true;
|
|
184
182
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
return !(hint & JSXValueHint.
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
183
|
+
case AST_NODE_TYPES.Literal: {
|
|
184
|
+
switch (typeof node.value) {
|
|
185
|
+
case "boolean":
|
|
186
|
+
return !(hint & JSXValueHint.SkipBooleanLiteral);
|
|
187
|
+
case "string":
|
|
188
|
+
return !(hint & JSXValueHint.SkipStringLiteral);
|
|
189
|
+
case "number":
|
|
190
|
+
return !(hint & JSXValueHint.SkipNumberLiteral);
|
|
191
|
+
case "bigint":
|
|
192
|
+
return !(hint & JSXValueHint.SkipBigIntLiteral);
|
|
193
|
+
}
|
|
194
|
+
if (node.value === null) {
|
|
195
|
+
return !(hint & JSXValueHint.SkipNullLiteral);
|
|
196
196
|
}
|
|
197
|
-
return
|
|
197
|
+
return false;
|
|
198
198
|
}
|
|
199
|
-
|
|
200
|
-
return
|
|
199
|
+
case AST_NODE_TYPES.TemplateLiteral: {
|
|
200
|
+
return !(hint & JSXValueHint.SkipStringLiteral);
|
|
201
201
|
}
|
|
202
|
-
|
|
203
|
-
|
|
202
|
+
case AST_NODE_TYPES.ArrayExpression: {
|
|
203
|
+
if (hint & JSXValueHint.StrictArray) {
|
|
204
|
+
return node.elements.every((n) => isJSXValue(n, jsxCtx, hint));
|
|
205
|
+
}
|
|
206
|
+
return node.elements.some((n) => isJSXValue(n, jsxCtx, hint));
|
|
204
207
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
208
|
+
case AST_NODE_TYPES.LogicalExpression: {
|
|
209
|
+
if (hint & JSXValueHint.StrictLogical) {
|
|
210
|
+
return isJSXValue(node.left, jsxCtx, hint) && isJSXValue(node.right, jsxCtx, hint);
|
|
211
|
+
}
|
|
212
|
+
return isJSXValue(node.left, jsxCtx, hint) || isJSXValue(node.right, jsxCtx, hint);
|
|
209
213
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
214
|
+
case AST_NODE_TYPES.ConditionalExpression: {
|
|
215
|
+
let leftHasJSX2 = function(node2) {
|
|
216
|
+
if (Array.isArray(node2.consequent)) {
|
|
217
|
+
if (node2.consequent.length === 0) {
|
|
218
|
+
return !(hint & JSXValueHint.SkipEmptyArray);
|
|
219
|
+
}
|
|
220
|
+
if (hint & JSXValueHint.StrictArray) {
|
|
221
|
+
return node2.consequent.every((n) => isJSXValue(n, jsxCtx, hint));
|
|
222
|
+
}
|
|
223
|
+
return node2.consequent.some((n) => isJSXValue(n, jsxCtx, hint));
|
|
224
|
+
}
|
|
225
|
+
return isJSXValue(node2.consequent, jsxCtx, hint);
|
|
226
|
+
}, rightHasJSX2 = function(node2) {
|
|
227
|
+
return isJSXValue(node2.alternate, jsxCtx, hint);
|
|
228
|
+
};
|
|
229
|
+
if (hint & JSXValueHint.StrictConditional) {
|
|
230
|
+
return leftHasJSX2(node) && rightHasJSX2(node);
|
|
231
|
+
}
|
|
232
|
+
return leftHasJSX2(node) || rightHasJSX2(node);
|
|
217
233
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
if (name === "undefined") {
|
|
222
|
-
return !(hint & JSXValueHint.SkipUndefinedLiteral);
|
|
234
|
+
case AST_NODE_TYPES.SequenceExpression: {
|
|
235
|
+
const exp = node.expressions.at(-1);
|
|
236
|
+
return isJSXValue(exp, jsxCtx, hint);
|
|
223
237
|
}
|
|
224
|
-
|
|
225
|
-
|
|
238
|
+
case AST_NODE_TYPES.CallExpression: {
|
|
239
|
+
if (hint & JSXValueHint.SkipCreateElement) {
|
|
240
|
+
return false;
|
|
241
|
+
}
|
|
242
|
+
switch (node.callee.type) {
|
|
243
|
+
case AST_NODE_TYPES.Identifier:
|
|
244
|
+
return node.callee.name === "createElement";
|
|
245
|
+
case AST_NODE_TYPES.MemberExpression:
|
|
246
|
+
return node.callee.property.type === AST_NODE_TYPES.Identifier && node.callee.property.name === "createElement";
|
|
247
|
+
}
|
|
248
|
+
return false;
|
|
226
249
|
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
250
|
+
case AST_NODE_TYPES.Identifier: {
|
|
251
|
+
const { name } = node;
|
|
252
|
+
if (name === "undefined") {
|
|
253
|
+
return !(hint & JSXValueHint.SkipUndefined);
|
|
254
|
+
}
|
|
255
|
+
if (AST2.isJSXTagNameExpression(node)) {
|
|
256
|
+
return true;
|
|
257
|
+
}
|
|
258
|
+
return F.pipe(
|
|
259
|
+
VAR.findVariable(name, jsxCtx.getScope(node)),
|
|
260
|
+
O.flatMap(VAR.getVariableNode(0)),
|
|
261
|
+
O.exists((n) => isJSXValue(n, jsxCtx, hint))
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return false;
|
|
234
266
|
}
|
|
235
267
|
var isLiteral = AST2.isOneOf([AST_NODE_TYPES.Literal, AST_NODE_TYPES.JSXText]);
|
|
236
268
|
function isWhiteSpace(node) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/jsx",
|
|
3
|
-
"version": "1.23.3-next.
|
|
3
|
+
"version": "1.23.3-next.1",
|
|
4
4
|
"description": "ESLint React's TSESTree AST utility module for static analysis of JSX.",
|
|
5
5
|
"homepage": "https://github.com/rEl1cx/eslint-react",
|
|
6
6
|
"bugs": {
|
|
@@ -39,10 +39,10 @@
|
|
|
39
39
|
"@typescript-eslint/types": "^8.19.1",
|
|
40
40
|
"@typescript-eslint/utils": "^8.19.1",
|
|
41
41
|
"ts-pattern": "^5.6.0",
|
|
42
|
-
"@eslint-react/ast": "1.23.3-next.
|
|
43
|
-
"@eslint-react/eff": "1.23.3-next.
|
|
44
|
-
"@eslint-react/types": "1.23.3-next.
|
|
45
|
-
"@eslint-react/var": "1.23.3-next.
|
|
42
|
+
"@eslint-react/ast": "1.23.3-next.1",
|
|
43
|
+
"@eslint-react/eff": "1.23.3-next.1",
|
|
44
|
+
"@eslint-react/types": "1.23.3-next.1",
|
|
45
|
+
"@eslint-react/var": "1.23.3-next.1"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"tsup": "^8.3.5",
|