@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 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 SkipCreateElement: bigint;
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 SkipCreateElement: bigint;
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
- SkipNullLiteral: 1n << 0n,
187
- SkipUndefinedLiteral: 1n << 1n,
185
+ SkipUndefined: 1n << 0n,
186
+ SkipNullLiteral: 1n << 1n,
188
187
  SkipBooleanLiteral: 1n << 2n,
189
188
  SkipStringLiteral: 1n << 3n,
190
189
  SkipNumberLiteral: 1n << 4n,
191
- SkipCreateElement: 1n << 5n,
190
+ SkipBigIntLiteral: 1n << 5n,
192
191
  SkipEmptyArray: 1n << 6n,
193
- StrictArray: 1n << 7n,
194
- StrictLogical: 1n << 8n,
195
- StrictConditional: 1n << 9n
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.SkipUndefinedLiteral | JSXValueHint.SkipBooleanLiteral;
197
+ var DEFAULT_JSX_VALUE_HINT = 0n | JSXValueHint.SkipUndefined | JSXValueHint.SkipBooleanLiteral;
198
198
  function isJSXValue(node, jsxCtx, hint = DEFAULT_JSX_VALUE_HINT) {
199
- if (!node) {
200
- return false;
201
- }
202
- return tsPattern.match(node).with({ type: types.AST_NODE_TYPES.JSXElement }, eff.F.constTrue).with({ type: types.AST_NODE_TYPES.JSXFragment }, eff.F.constTrue).with({ type: types.AST_NODE_TYPES.JSXMemberExpression }, eff.F.constTrue).with({ type: types.AST_NODE_TYPES.JSXNamespacedName }, eff.F.constTrue).with({ type: types.AST_NODE_TYPES.Literal }, (node2) => {
203
- return tsPattern.match(node2.value).with(null, () => !(hint & JSXValueHint.SkipNullLiteral)).with(tsPattern.P.boolean, () => !(hint & JSXValueHint.SkipBooleanLiteral)).with(tsPattern.P.string, () => !(hint & JSXValueHint.SkipStringLiteral)).with(tsPattern.P.number, () => !(hint & JSXValueHint.SkipNumberLiteral)).otherwise(eff.F.constFalse);
204
- }).with({ type: types.AST_NODE_TYPES.TemplateLiteral }, () => !(hint & JSXValueHint.SkipStringLiteral)).with({ type: types.AST_NODE_TYPES.ArrayExpression }, (node2) => {
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
- return node2.elements.some((n) => isJSXValue(n, jsxCtx, hint));
209
- }).with({ type: types.AST_NODE_TYPES.ConditionalExpression }, (node2) => {
210
- function leftHasJSX(node3) {
211
- if (Array.isArray(node3.consequent)) {
212
- if (node3.consequent.length === 0) {
213
- return !(hint & JSXValueHint.SkipEmptyArray);
214
- }
215
- if (hint & JSXValueHint.StrictArray) {
216
- return node3.consequent.every((n) => isJSXValue(n, jsxCtx, hint));
217
- }
218
- return node3.consequent.some((n) => isJSXValue(n, jsxCtx, hint));
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 isJSXValue(node3.consequent, jsxCtx, hint);
220
+ return false;
221
221
  }
222
- function rightHasJSX(node3) {
223
- return isJSXValue(node3.alternate, jsxCtx, hint);
222
+ case types.AST_NODE_TYPES.TemplateLiteral: {
223
+ return !(hint & JSXValueHint.SkipStringLiteral);
224
224
  }
225
- if (hint & JSXValueHint.StrictConditional) {
226
- return leftHasJSX(node2) && rightHasJSX(node2);
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
- return leftHasJSX(node2) || rightHasJSX(node2);
229
- }).with({ type: types.AST_NODE_TYPES.LogicalExpression }, (node2) => {
230
- if (hint & JSXValueHint.StrictLogical) {
231
- return isJSXValue(node2.left, jsxCtx, hint) && isJSXValue(node2.right, jsxCtx, hint);
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
- return isJSXValue(node2.left, jsxCtx, hint) || isJSXValue(node2.right, jsxCtx, hint);
234
- }).with({ type: types.AST_NODE_TYPES.SequenceExpression }, (node2) => {
235
- const exp = node2.expressions.at(-1);
236
- return isJSXValue(exp, jsxCtx, hint);
237
- }).with({ type: types.AST_NODE_TYPES.CallExpression }, (node2) => {
238
- if (hint & JSXValueHint.SkipCreateElement) {
239
- return false;
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
- return tsPattern.match(node2.callee).with({ type: types.AST_NODE_TYPES.Identifier, name: "createElement" }, eff.F.constTrue).with({ type: types.AST_NODE_TYPES.MemberExpression, property: { name: "createElement" } }, eff.F.constTrue).otherwise(eff.F.constFalse);
242
- }).with({ type: types.AST_NODE_TYPES.Identifier }, (node2) => {
243
- const { name } = node2;
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
- if (AST2__namespace.isJSXTagNameExpression(node2)) {
248
- return true;
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
- const initialScope = jsxCtx.getScope(node2);
251
- return eff.F.pipe(
252
- VAR__namespace.findVariable(name, initialScope),
253
- eff.O.flatMap(VAR__namespace.getVariableNode(0)),
254
- eff.O.exists((n) => isJSXValue(n, jsxCtx, hint))
255
- );
256
- }).otherwise(eff.F.constFalse);
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
- SkipNullLiteral: 1n << 0n,
164
- SkipUndefinedLiteral: 1n << 1n,
162
+ SkipUndefined: 1n << 0n,
163
+ SkipNullLiteral: 1n << 1n,
165
164
  SkipBooleanLiteral: 1n << 2n,
166
165
  SkipStringLiteral: 1n << 3n,
167
166
  SkipNumberLiteral: 1n << 4n,
168
- SkipCreateElement: 1n << 5n,
167
+ SkipBigIntLiteral: 1n << 5n,
169
168
  SkipEmptyArray: 1n << 6n,
170
- StrictArray: 1n << 7n,
171
- StrictLogical: 1n << 8n,
172
- StrictConditional: 1n << 9n
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.SkipUndefinedLiteral | JSXValueHint.SkipBooleanLiteral;
174
+ var DEFAULT_JSX_VALUE_HINT = 0n | JSXValueHint.SkipUndefined | JSXValueHint.SkipBooleanLiteral;
175
175
  function isJSXValue(node, jsxCtx, hint = DEFAULT_JSX_VALUE_HINT) {
176
- if (!node) {
177
- return false;
178
- }
179
- return match(node).with({ type: AST_NODE_TYPES.JSXElement }, F.constTrue).with({ type: AST_NODE_TYPES.JSXFragment }, F.constTrue).with({ type: AST_NODE_TYPES.JSXMemberExpression }, F.constTrue).with({ type: AST_NODE_TYPES.JSXNamespacedName }, F.constTrue).with({ type: AST_NODE_TYPES.Literal }, (node2) => {
180
- return match(node2.value).with(null, () => !(hint & JSXValueHint.SkipNullLiteral)).with(P.boolean, () => !(hint & JSXValueHint.SkipBooleanLiteral)).with(P.string, () => !(hint & JSXValueHint.SkipStringLiteral)).with(P.number, () => !(hint & JSXValueHint.SkipNumberLiteral)).otherwise(F.constFalse);
181
- }).with({ type: AST_NODE_TYPES.TemplateLiteral }, () => !(hint & JSXValueHint.SkipStringLiteral)).with({ type: AST_NODE_TYPES.ArrayExpression }, (node2) => {
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
- return node2.elements.some((n) => isJSXValue(n, jsxCtx, hint));
186
- }).with({ type: AST_NODE_TYPES.ConditionalExpression }, (node2) => {
187
- function leftHasJSX(node3) {
188
- if (Array.isArray(node3.consequent)) {
189
- if (node3.consequent.length === 0) {
190
- return !(hint & JSXValueHint.SkipEmptyArray);
191
- }
192
- if (hint & JSXValueHint.StrictArray) {
193
- return node3.consequent.every((n) => isJSXValue(n, jsxCtx, hint));
194
- }
195
- return node3.consequent.some((n) => isJSXValue(n, jsxCtx, hint));
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 isJSXValue(node3.consequent, jsxCtx, hint);
197
+ return false;
198
198
  }
199
- function rightHasJSX(node3) {
200
- return isJSXValue(node3.alternate, jsxCtx, hint);
199
+ case AST_NODE_TYPES.TemplateLiteral: {
200
+ return !(hint & JSXValueHint.SkipStringLiteral);
201
201
  }
202
- if (hint & JSXValueHint.StrictConditional) {
203
- return leftHasJSX(node2) && rightHasJSX(node2);
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
- return leftHasJSX(node2) || rightHasJSX(node2);
206
- }).with({ type: AST_NODE_TYPES.LogicalExpression }, (node2) => {
207
- if (hint & JSXValueHint.StrictLogical) {
208
- return isJSXValue(node2.left, jsxCtx, hint) && isJSXValue(node2.right, jsxCtx, hint);
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
- return isJSXValue(node2.left, jsxCtx, hint) || isJSXValue(node2.right, jsxCtx, hint);
211
- }).with({ type: AST_NODE_TYPES.SequenceExpression }, (node2) => {
212
- const exp = node2.expressions.at(-1);
213
- return isJSXValue(exp, jsxCtx, hint);
214
- }).with({ type: AST_NODE_TYPES.CallExpression }, (node2) => {
215
- if (hint & JSXValueHint.SkipCreateElement) {
216
- return false;
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
- return match(node2.callee).with({ type: AST_NODE_TYPES.Identifier, name: "createElement" }, F.constTrue).with({ type: AST_NODE_TYPES.MemberExpression, property: { name: "createElement" } }, F.constTrue).otherwise(F.constFalse);
219
- }).with({ type: AST_NODE_TYPES.Identifier }, (node2) => {
220
- const { name } = node2;
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
- if (AST2.isJSXTagNameExpression(node2)) {
225
- return true;
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
- const initialScope = jsxCtx.getScope(node2);
228
- return F.pipe(
229
- VAR.findVariable(name, initialScope),
230
- O.flatMap(VAR.getVariableNode(0)),
231
- O.exists((n) => isJSXValue(n, jsxCtx, hint))
232
- );
233
- }).otherwise(F.constFalse);
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.0",
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.0",
43
- "@eslint-react/eff": "1.23.3-next.0",
44
- "@eslint-react/types": "1.23.3-next.0",
45
- "@eslint-react/var": "1.23.3-next.0"
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",