@eslint-react/jsx 1.5.31-next.3 → 1.5.31-next.4

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
@@ -110,7 +110,7 @@ declare const DEFAULT_JSX_VALUE_HINT: bigint;
110
110
  * @param hint The `JSXValueHint` to use
111
111
  * @returns boolean
112
112
  */
113
- declare function isJSXValue(node: null | TSESTree$1.Node | undefined, context: RuleContext, hint?: bigint): boolean;
113
+ declare function isJSXValue(node: TSESTree$1.Node | null | undefined, context: RuleContext, hint?: bigint): boolean;
114
114
 
115
115
  /**
116
116
  * Check if a node is a Literal or JSXText
package/dist/index.d.ts CHANGED
@@ -110,7 +110,7 @@ declare const DEFAULT_JSX_VALUE_HINT: bigint;
110
110
  * @param hint The `JSXValueHint` to use
111
111
  * @returns boolean
112
112
  */
113
- declare function isJSXValue(node: null | TSESTree$1.Node | undefined, context: RuleContext, hint?: bigint): boolean;
113
+ declare function isJSXValue(node: TSESTree$1.Node | null | undefined, context: RuleContext, hint?: bigint): boolean;
114
114
 
115
115
  /**
116
116
  * Check if a node is a Literal or JSXText
package/dist/index.js CHANGED
@@ -5,6 +5,7 @@ var tools = require('@eslint-react/tools');
5
5
  var ast = require('@eslint-react/ast');
6
6
  var _var = require('@eslint-react/var');
7
7
  var astUtils = require('@typescript-eslint/utils/ast-utils');
8
+ var tsPattern = require('ts-pattern');
8
9
 
9
10
  // src/element-type.ts
10
11
  function resolveMemberExpressions(object, property) {
@@ -41,264 +42,8 @@ function getJSXPragma(context) {
41
42
  tools.O.filter((pragma) => RE_JS_IDENTIFIER_REGEX.test(pragma))
42
43
  );
43
44
  }
44
-
45
- // ../../../node_modules/.pnpm/ts-pattern@5.2.0/node_modules/ts-pattern/dist/index.js
46
- var t = Symbol.for("@ts-pattern/matcher");
47
- var e = Symbol.for("@ts-pattern/isVariadic");
48
- var n = "@ts-pattern/anonymous-select-key";
49
- var r = (t2) => Boolean(t2 && "object" == typeof t2);
50
- var i = (e2) => e2 && !!e2[t];
51
- var o = (n2, s2, c2) => {
52
- if (i(n2)) {
53
- const e2 = n2[t](), { matched: r2, selections: i2 } = e2.match(s2);
54
- return r2 && i2 && Object.keys(i2).forEach((t2) => c2(t2, i2[t2])), r2;
55
- }
56
- if (r(n2)) {
57
- if (!r(s2)) return false;
58
- if (Array.isArray(n2)) {
59
- if (!Array.isArray(s2)) return false;
60
- let t2 = [], r2 = [], a2 = [];
61
- for (const o2 of n2.keys()) {
62
- const s3 = n2[o2];
63
- i(s3) && s3[e] ? a2.push(s3) : a2.length ? r2.push(s3) : t2.push(s3);
64
- }
65
- if (a2.length) {
66
- if (a2.length > 1) throw new Error("Pattern error: Using `...P.array(...)` several times in a single pattern is not allowed.");
67
- if (s2.length < t2.length + r2.length) return false;
68
- const e2 = s2.slice(0, t2.length), n3 = 0 === r2.length ? [] : s2.slice(-r2.length), i2 = s2.slice(t2.length, 0 === r2.length ? Infinity : -r2.length);
69
- return t2.every((t3, n4) => o(t3, e2[n4], c2)) && r2.every((t3, e3) => o(t3, n3[e3], c2)) && (0 === a2.length || o(a2[0], i2, c2));
70
- }
71
- return n2.length === s2.length && n2.every((t3, e2) => o(t3, s2[e2], c2));
72
- }
73
- return Object.keys(n2).every((e2) => {
74
- const r2 = n2[e2];
75
- return (e2 in s2 || i(a2 = r2) && "optional" === a2[t]().matcherType) && o(r2, s2[e2], c2);
76
- var a2;
77
- });
78
- }
79
- return Object.is(s2, n2);
80
- };
81
- var s = (e2) => {
82
- var n2, o2, a2;
83
- return r(e2) ? i(e2) ? null != (n2 = null == (o2 = (a2 = e2[t]()).getSelectionKeys) ? void 0 : o2.call(a2)) ? n2 : [] : Array.isArray(e2) ? c(e2, s) : c(Object.values(e2), s) : [];
84
- };
85
- var c = (t2, e2) => t2.reduce((t3, n2) => t3.concat(e2(n2)), []);
86
- function a(...t2) {
87
- if (1 === t2.length) {
88
- const [e2] = t2;
89
- return (t3) => o(e2, t3, () => {
90
- });
91
- }
92
- if (2 === t2.length) {
93
- const [e2, n2] = t2;
94
- return o(e2, n2, () => {
95
- });
96
- }
97
- throw new Error(`isMatching wasn't given the right number of arguments: expected 1 or 2, received ${t2.length}.`);
98
- }
99
- function u(t2) {
100
- return Object.assign(t2, { optional: () => l(t2), and: (e2) => m(t2, e2), or: (e2) => d(t2, e2), select: (e2) => void 0 === e2 ? p(t2) : p(e2, t2) });
101
- }
102
- function h(t2) {
103
- return Object.assign(((t3) => Object.assign(t3, { [Symbol.iterator]() {
104
- let n2 = 0;
105
- const r2 = [{ value: Object.assign(t3, { [e]: true }), done: false }, { done: true, value: void 0 }];
106
- return { next: () => {
107
- var t4;
108
- return null != (t4 = r2[n2++]) ? t4 : r2.at(-1);
109
- } };
110
- } }))(t2), { optional: () => h(l(t2)), select: (e2) => h(void 0 === e2 ? p(t2) : p(e2, t2)) });
111
- }
112
- function l(e2) {
113
- return u({ [t]: () => ({ match: (t2) => {
114
- let n2 = {};
115
- const r2 = (t3, e3) => {
116
- n2[t3] = e3;
117
- };
118
- return void 0 === t2 ? (s(e2).forEach((t3) => r2(t3, void 0)), { matched: true, selections: n2 }) : { matched: o(e2, t2, r2), selections: n2 };
119
- }, getSelectionKeys: () => s(e2), matcherType: "optional" }) });
120
- }
121
- var f = (t2, e2) => {
122
- for (const n2 of t2) if (!e2(n2)) return false;
123
- return true;
124
- };
125
- var g = (t2, e2) => {
126
- for (const [n2, r2] of t2.entries()) if (!e2(r2, n2)) return false;
127
- return true;
128
- };
129
- function m(...e2) {
130
- return u({ [t]: () => ({ match: (t2) => {
131
- let n2 = {};
132
- const r2 = (t3, e3) => {
133
- n2[t3] = e3;
134
- };
135
- return { matched: e2.every((e3) => o(e3, t2, r2)), selections: n2 };
136
- }, getSelectionKeys: () => c(e2, s), matcherType: "and" }) });
137
- }
138
- function d(...e2) {
139
- return u({ [t]: () => ({ match: (t2) => {
140
- let n2 = {};
141
- const r2 = (t3, e3) => {
142
- n2[t3] = e3;
143
- };
144
- return c(e2, s).forEach((t3) => r2(t3, void 0)), { matched: e2.some((e3) => o(e3, t2, r2)), selections: n2 };
145
- }, getSelectionKeys: () => c(e2, s), matcherType: "or" }) });
146
- }
147
- function y(e2) {
148
- return { [t]: () => ({ match: (t2) => ({ matched: Boolean(e2(t2)) }) }) };
149
- }
150
- function p(...e2) {
151
- const r2 = "string" == typeof e2[0] ? e2[0] : void 0, i2 = 2 === e2.length ? e2[1] : "string" == typeof e2[0] ? void 0 : e2[0];
152
- return u({ [t]: () => ({ match: (t2) => {
153
- let e3 = { [null != r2 ? r2 : n]: t2 };
154
- return { matched: void 0 === i2 || o(i2, t2, (t3, n2) => {
155
- e3[t3] = n2;
156
- }), selections: e3 };
157
- }, getSelectionKeys: () => [null != r2 ? r2 : n].concat(void 0 === i2 ? [] : s(i2)) }) });
158
- }
159
- function v(t2) {
160
- return "number" == typeof t2;
161
- }
162
- function b(t2) {
163
- return "string" == typeof t2;
164
- }
165
- function w(t2) {
166
- return "bigint" == typeof t2;
167
- }
168
- var S = u(y(function(t2) {
169
- return true;
170
- }));
171
- var O2 = S;
172
- var j = (t2) => Object.assign(u(t2), { startsWith: (e2) => {
173
- return j(m(t2, (n2 = e2, y((t3) => b(t3) && t3.startsWith(n2)))));
174
- var n2;
175
- }, endsWith: (e2) => {
176
- return j(m(t2, (n2 = e2, y((t3) => b(t3) && t3.endsWith(n2)))));
177
- var n2;
178
- }, minLength: (e2) => j(m(t2, ((t3) => y((e3) => b(e3) && e3.length >= t3))(e2))), length: (e2) => j(m(t2, ((t3) => y((e3) => b(e3) && e3.length === t3))(e2))), maxLength: (e2) => j(m(t2, ((t3) => y((e3) => b(e3) && e3.length <= t3))(e2))), includes: (e2) => {
179
- return j(m(t2, (n2 = e2, y((t3) => b(t3) && t3.includes(n2)))));
180
- var n2;
181
- }, regex: (e2) => {
182
- return j(m(t2, (n2 = e2, y((t3) => b(t3) && Boolean(t3.match(n2))))));
183
- var n2;
184
- } });
185
- var E = j(y(b));
186
- var K = (t2) => Object.assign(u(t2), { between: (e2, n2) => K(m(t2, ((t3, e3) => y((n3) => v(n3) && t3 <= n3 && e3 >= n3))(e2, n2))), lt: (e2) => K(m(t2, ((t3) => y((e3) => v(e3) && e3 < t3))(e2))), gt: (e2) => K(m(t2, ((t3) => y((e3) => v(e3) && e3 > t3))(e2))), lte: (e2) => K(m(t2, ((t3) => y((e3) => v(e3) && e3 <= t3))(e2))), gte: (e2) => K(m(t2, ((t3) => y((e3) => v(e3) && e3 >= t3))(e2))), int: () => K(m(t2, y((t3) => v(t3) && Number.isInteger(t3)))), finite: () => K(m(t2, y((t3) => v(t3) && Number.isFinite(t3)))), positive: () => K(m(t2, y((t3) => v(t3) && t3 > 0))), negative: () => K(m(t2, y((t3) => v(t3) && t3 < 0))) });
187
- var x = K(y(v));
188
- var A = (t2) => Object.assign(u(t2), { between: (e2, n2) => A(m(t2, ((t3, e3) => y((n3) => w(n3) && t3 <= n3 && e3 >= n3))(e2, n2))), lt: (e2) => A(m(t2, ((t3) => y((e3) => w(e3) && e3 < t3))(e2))), gt: (e2) => A(m(t2, ((t3) => y((e3) => w(e3) && e3 > t3))(e2))), lte: (e2) => A(m(t2, ((t3) => y((e3) => w(e3) && e3 <= t3))(e2))), gte: (e2) => A(m(t2, ((t3) => y((e3) => w(e3) && e3 >= t3))(e2))), positive: () => A(m(t2, y((t3) => w(t3) && t3 > 0))), negative: () => A(m(t2, y((t3) => w(t3) && t3 < 0))) });
189
- var P = A(y(w));
190
- var T = u(y(function(t2) {
191
- return "boolean" == typeof t2;
192
- }));
193
- var k = u(y(function(t2) {
194
- return "symbol" == typeof t2;
195
- }));
196
- var B = u(y(function(t2) {
197
- return null == t2;
198
- }));
199
- var _ = u(y(function(t2) {
200
- return null != t2;
201
- }));
202
- var N = { __proto__: null, matcher: t, optional: l, array: function(...e2) {
203
- return h({ [t]: () => ({ match: (t2) => {
204
- if (!Array.isArray(t2)) return { matched: false };
205
- if (0 === e2.length) return { matched: true };
206
- const n2 = e2[0];
207
- let r2 = {};
208
- if (0 === t2.length) return s(n2).forEach((t3) => {
209
- r2[t3] = [];
210
- }), { matched: true, selections: r2 };
211
- const i2 = (t3, e3) => {
212
- r2[t3] = (r2[t3] || []).concat([e3]);
213
- };
214
- return { matched: t2.every((t3) => o(n2, t3, i2)), selections: r2 };
215
- }, getSelectionKeys: () => 0 === e2.length ? [] : s(e2[0]) }) });
216
- }, set: function(...e2) {
217
- return u({ [t]: () => ({ match: (t2) => {
218
- if (!(t2 instanceof Set)) return { matched: false };
219
- let n2 = {};
220
- if (0 === t2.size) return { matched: true, selections: n2 };
221
- if (0 === e2.length) return { matched: true };
222
- const r2 = (t3, e3) => {
223
- n2[t3] = (n2[t3] || []).concat([e3]);
224
- }, i2 = e2[0];
225
- return { matched: f(t2, (t3) => o(i2, t3, r2)), selections: n2 };
226
- }, getSelectionKeys: () => 0 === e2.length ? [] : s(e2[0]) }) });
227
- }, map: function(...e2) {
228
- return u({ [t]: () => ({ match: (t2) => {
229
- if (!(t2 instanceof Map)) return { matched: false };
230
- let n2 = {};
231
- if (0 === t2.size) return { matched: true, selections: n2 };
232
- const r2 = (t3, e3) => {
233
- n2[t3] = (n2[t3] || []).concat([e3]);
234
- };
235
- if (0 === e2.length) return { matched: true };
236
- var i2;
237
- if (1 === e2.length) throw new Error(`\`P.map\` wasn't given enough arguments. Expected (key, value), received ${null == (i2 = e2[0]) ? void 0 : i2.toString()}`);
238
- const [s2, c2] = e2;
239
- return { matched: g(t2, (t3, e3) => {
240
- const n3 = o(s2, e3, r2), i3 = o(c2, t3, r2);
241
- return n3 && i3;
242
- }), selections: n2 };
243
- }, getSelectionKeys: () => 0 === e2.length ? [] : [...s(e2[0]), ...s(e2[1])] }) });
244
- }, intersection: m, union: d, not: function(e2) {
245
- return u({ [t]: () => ({ match: (t2) => ({ matched: !o(e2, t2, () => {
246
- }) }), getSelectionKeys: () => [], matcherType: "not" }) });
247
- }, when: y, select: p, any: S, _: O2, string: E, number: x, bigint: P, boolean: T, symbol: k, nullish: B, nonNullable: _, instanceOf: function(t2) {
248
- return u(y(/* @__PURE__ */ function(t3) {
249
- return (e2) => e2 instanceof t3;
250
- }(t2)));
251
- }, shape: function(t2) {
252
- return u(y(a(t2)));
253
- } };
254
- var W = { matched: false, value: void 0 };
255
- function $(t2) {
256
- return new z(t2, W);
257
- }
258
- var z = class _z {
259
- constructor(t2, e2) {
260
- this.input = void 0, this.state = void 0, this.input = t2, this.state = e2;
261
- }
262
- with(...t2) {
263
- if (this.state.matched) return this;
264
- const e2 = t2[t2.length - 1], r2 = [t2[0]];
265
- let i2;
266
- 3 === t2.length && "function" == typeof t2[1] ? i2 = t2[1] : t2.length > 2 && r2.push(...t2.slice(1, t2.length - 1));
267
- let s2 = false, c2 = {};
268
- const a2 = (t3, e3) => {
269
- s2 = true, c2[t3] = e3;
270
- }, u2 = !r2.some((t3) => o(t3, this.input, a2)) || i2 && !Boolean(i2(this.input)) ? W : { matched: true, value: e2(s2 ? n in c2 ? c2[n] : c2 : this.input, this.input) };
271
- return new _z(this.input, u2);
272
- }
273
- when(t2, e2) {
274
- if (this.state.matched) return this;
275
- const n2 = Boolean(t2(this.input));
276
- return new _z(this.input, n2 ? { matched: true, value: e2(this.input, this.input) } : W);
277
- }
278
- otherwise(t2) {
279
- return this.state.matched ? this.state.value : t2(this.input);
280
- }
281
- exhaustive() {
282
- if (this.state.matched) return this.state.value;
283
- let t2;
284
- try {
285
- t2 = JSON.stringify(this.input);
286
- } catch (e2) {
287
- t2 = this.input;
288
- }
289
- throw new Error(`Pattern matching error: no pattern matches value ${t2}`);
290
- }
291
- run() {
292
- return this.exhaustive();
293
- }
294
- returnType() {
295
- return this;
296
- }
297
- };
298
-
299
- // src/get-prop.ts
300
45
  function getPropName(node) {
301
- return $(node.name).when(ast.is(ast.NodeType.JSXIdentifier), (n2) => n2.name).when(ast.is(ast.NodeType.JSXNamespacedName), (n2) => `${n2.namespace.name}:${n2.name.name}`).exhaustive();
46
+ return tsPattern.match(node.name).when(ast.is(ast.NodeType.JSXIdentifier), (n) => n.name).when(ast.is(ast.NodeType.JSXNamespacedName), (n) => `${n.namespace.name}:${n.name.name}`).exhaustive();
302
47
  }
303
48
  function getProp(props, propName, context, initialScope) {
304
49
  return findPropInAttributes(props, context, initialScope)(propName);
@@ -319,10 +64,10 @@ function findPropInProperties(properties, context, initialScope, seenProps = [])
319
64
  return (propName) => {
320
65
  return tools.O.fromNullable(
321
66
  properties.find((prop) => {
322
- return $(prop).when(ast.is(ast.NodeType.Property), (prop2) => {
67
+ return tsPattern.match(prop).when(ast.is(ast.NodeType.Property), (prop2) => {
323
68
  return "name" in prop2.key && prop2.key.name === propName;
324
69
  }).when(ast.is(ast.NodeType.SpreadElement), (prop2) => {
325
- return $(prop2.argument).when(ast.is(ast.NodeType.Identifier), (argument) => {
70
+ return tsPattern.match(prop2.argument).when(ast.is(ast.NodeType.Identifier), (argument) => {
326
71
  const { name } = argument;
327
72
  const maybeInit = tools.O.flatMap(
328
73
  _var.findVariable(name, initialScope),
@@ -351,8 +96,8 @@ function findPropInAttributes(attributes, context, initialScope) {
351
96
  return (propName) => {
352
97
  return tools.O.fromNullable(
353
98
  attributes.find((attr) => {
354
- return $(attr).when(ast.is(ast.NodeType.JSXAttribute), (attr2) => getPropName(attr2) === propName).when(ast.is(ast.NodeType.JSXSpreadAttribute), (attr2) => {
355
- return $(attr2.argument).with({ type: ast.NodeType.Identifier }, (argument) => {
99
+ return tsPattern.match(attr).when(ast.is(ast.NodeType.JSXAttribute), (attr2) => getPropName(attr2) === propName).when(ast.is(ast.NodeType.JSXSpreadAttribute), (attr2) => {
100
+ return tsPattern.match(attr2.argument).with({ type: ast.NodeType.Identifier }, (argument) => {
356
101
  const { name } = argument;
357
102
  const maybeInit = tools.O.flatMap(
358
103
  _var.findVariable(name, initialScope),
@@ -411,19 +156,19 @@ var JSXValueHint = {
411
156
  var DEFAULT_JSX_VALUE_HINT = 0n | JSXValueHint.SkipUndefinedLiteral | JSXValueHint.SkipBooleanLiteral;
412
157
  function isJSXValue(node, context, hint = DEFAULT_JSX_VALUE_HINT) {
413
158
  if (!node) return false;
414
- return $(node).with({ type: ast.NodeType.JSXElement }, tools.F.constTrue).with({ type: ast.NodeType.JSXFragment }, tools.F.constTrue).with({ type: ast.NodeType.JSXMemberExpression }, tools.F.constTrue).with({ type: ast.NodeType.JSXNamespacedName }, tools.F.constTrue).with({ type: ast.NodeType.Literal }, (node2) => {
415
- return $(node2.value).with(null, () => !(hint & JSXValueHint.SkipNullLiteral)).with(N.boolean, () => !(hint & JSXValueHint.SkipBooleanLiteral)).with(N.string, () => !(hint & JSXValueHint.SkipStringLiteral)).with(N.number, () => !(hint & JSXValueHint.SkipNumberLiteral)).otherwise(tools.F.constFalse);
159
+ return tsPattern.match(node).with({ type: ast.NodeType.JSXElement }, tools.F.constTrue).with({ type: ast.NodeType.JSXFragment }, tools.F.constTrue).with({ type: ast.NodeType.JSXMemberExpression }, tools.F.constTrue).with({ type: ast.NodeType.JSXNamespacedName }, tools.F.constTrue).with({ type: ast.NodeType.Literal }, (node2) => {
160
+ 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(tools.F.constFalse);
416
161
  }).with({ type: ast.NodeType.TemplateLiteral }, () => !(hint & JSXValueHint.SkipStringLiteral)).with({ type: ast.NodeType.ArrayExpression }, (node2) => {
417
- if (hint & JSXValueHint.StrictArray) return node2.elements.every((n2) => isJSXValue(n2, context, hint));
418
- return node2.elements.some((n2) => isJSXValue(n2, context, hint));
162
+ if (hint & JSXValueHint.StrictArray) return node2.elements.every((n) => isJSXValue(n, context, hint));
163
+ return node2.elements.some((n) => isJSXValue(n, context, hint));
419
164
  }).with({ type: ast.NodeType.ConditionalExpression }, (node2) => {
420
165
  function leftHasJSX(node3) {
421
166
  if (Array.isArray(node3.consequent)) {
422
167
  if (node3.consequent.length === 0) return !(hint & JSXValueHint.SkipEmptyArray);
423
168
  if (hint & JSXValueHint.StrictArray) {
424
- return node3.consequent.every((n2) => isJSXValue(n2, context, hint));
169
+ return node3.consequent.every((n) => isJSXValue(n, context, hint));
425
170
  }
426
- return node3.consequent.some((n2) => isJSXValue(n2, context, hint));
171
+ return node3.consequent.some((n) => isJSXValue(n, context, hint));
427
172
  }
428
173
  return isJSXValue(node3.consequent, context, hint);
429
174
  }
@@ -444,7 +189,7 @@ function isJSXValue(node, context, hint = DEFAULT_JSX_VALUE_HINT) {
444
189
  return isJSXValue(exp, context, hint);
445
190
  }).with({ type: ast.NodeType.CallExpression }, (node2) => {
446
191
  if (hint & JSXValueHint.SkipCreateElement) return false;
447
- return $(node2.callee).with({ type: ast.NodeType.Identifier, name: "createElement" }, tools.F.constTrue).with({ type: ast.NodeType.MemberExpression, property: { name: "createElement" } }, tools.F.constTrue).otherwise(tools.F.constFalse);
192
+ return tsPattern.match(node2.callee).with({ type: ast.NodeType.Identifier, name: "createElement" }, tools.F.constTrue).with({ type: ast.NodeType.MemberExpression, property: { name: "createElement" } }, tools.F.constTrue).otherwise(tools.F.constFalse);
448
193
  }).with({ type: ast.NodeType.Identifier }, (node2) => {
449
194
  const { name } = node2;
450
195
  if (name === "undefined") return !(hint & JSXValueHint.SkipUndefinedLiteral);
@@ -454,7 +199,7 @@ function isJSXValue(node, context, hint = DEFAULT_JSX_VALUE_HINT) {
454
199
  return tools.F.pipe(
455
200
  maybeVariable,
456
201
  tools.O.flatMap(_var.getVariableNode(0)),
457
- tools.O.exists((n2) => isJSXValue(n2, context, hint))
202
+ tools.O.exists((n) => isJSXValue(n, context, hint))
458
203
  );
459
204
  }).otherwise(tools.F.constFalse);
460
205
  }
package/dist/index.mjs CHANGED
@@ -3,6 +3,7 @@ import { F, O, Pred } from '@eslint-react/tools';
3
3
  import { isOneOf, NodeType, is, isJSXTagNameExpression, isMultiLine, traverseUpGuard } from '@eslint-react/ast';
4
4
  import { findVariable, getVariableNode } from '@eslint-react/var';
5
5
  import { getStaticValue } from '@typescript-eslint/utils/ast-utils';
6
+ import { match, P } from 'ts-pattern';
6
7
 
7
8
  // src/element-type.ts
8
9
  function resolveMemberExpressions(object, property) {
@@ -39,264 +40,8 @@ function getJSXPragma(context) {
39
40
  O.filter((pragma) => RE_JS_IDENTIFIER_REGEX.test(pragma))
40
41
  );
41
42
  }
42
-
43
- // ../../../node_modules/.pnpm/ts-pattern@5.2.0/node_modules/ts-pattern/dist/index.js
44
- var t = Symbol.for("@ts-pattern/matcher");
45
- var e = Symbol.for("@ts-pattern/isVariadic");
46
- var n = "@ts-pattern/anonymous-select-key";
47
- var r = (t2) => Boolean(t2 && "object" == typeof t2);
48
- var i = (e2) => e2 && !!e2[t];
49
- var o = (n2, s2, c2) => {
50
- if (i(n2)) {
51
- const e2 = n2[t](), { matched: r2, selections: i2 } = e2.match(s2);
52
- return r2 && i2 && Object.keys(i2).forEach((t2) => c2(t2, i2[t2])), r2;
53
- }
54
- if (r(n2)) {
55
- if (!r(s2)) return false;
56
- if (Array.isArray(n2)) {
57
- if (!Array.isArray(s2)) return false;
58
- let t2 = [], r2 = [], a2 = [];
59
- for (const o2 of n2.keys()) {
60
- const s3 = n2[o2];
61
- i(s3) && s3[e] ? a2.push(s3) : a2.length ? r2.push(s3) : t2.push(s3);
62
- }
63
- if (a2.length) {
64
- if (a2.length > 1) throw new Error("Pattern error: Using `...P.array(...)` several times in a single pattern is not allowed.");
65
- if (s2.length < t2.length + r2.length) return false;
66
- const e2 = s2.slice(0, t2.length), n3 = 0 === r2.length ? [] : s2.slice(-r2.length), i2 = s2.slice(t2.length, 0 === r2.length ? Infinity : -r2.length);
67
- return t2.every((t3, n4) => o(t3, e2[n4], c2)) && r2.every((t3, e3) => o(t3, n3[e3], c2)) && (0 === a2.length || o(a2[0], i2, c2));
68
- }
69
- return n2.length === s2.length && n2.every((t3, e2) => o(t3, s2[e2], c2));
70
- }
71
- return Object.keys(n2).every((e2) => {
72
- const r2 = n2[e2];
73
- return (e2 in s2 || i(a2 = r2) && "optional" === a2[t]().matcherType) && o(r2, s2[e2], c2);
74
- var a2;
75
- });
76
- }
77
- return Object.is(s2, n2);
78
- };
79
- var s = (e2) => {
80
- var n2, o2, a2;
81
- return r(e2) ? i(e2) ? null != (n2 = null == (o2 = (a2 = e2[t]()).getSelectionKeys) ? void 0 : o2.call(a2)) ? n2 : [] : Array.isArray(e2) ? c(e2, s) : c(Object.values(e2), s) : [];
82
- };
83
- var c = (t2, e2) => t2.reduce((t3, n2) => t3.concat(e2(n2)), []);
84
- function a(...t2) {
85
- if (1 === t2.length) {
86
- const [e2] = t2;
87
- return (t3) => o(e2, t3, () => {
88
- });
89
- }
90
- if (2 === t2.length) {
91
- const [e2, n2] = t2;
92
- return o(e2, n2, () => {
93
- });
94
- }
95
- throw new Error(`isMatching wasn't given the right number of arguments: expected 1 or 2, received ${t2.length}.`);
96
- }
97
- function u(t2) {
98
- return Object.assign(t2, { optional: () => l(t2), and: (e2) => m(t2, e2), or: (e2) => d(t2, e2), select: (e2) => void 0 === e2 ? p(t2) : p(e2, t2) });
99
- }
100
- function h(t2) {
101
- return Object.assign(((t3) => Object.assign(t3, { [Symbol.iterator]() {
102
- let n2 = 0;
103
- const r2 = [{ value: Object.assign(t3, { [e]: true }), done: false }, { done: true, value: void 0 }];
104
- return { next: () => {
105
- var t4;
106
- return null != (t4 = r2[n2++]) ? t4 : r2.at(-1);
107
- } };
108
- } }))(t2), { optional: () => h(l(t2)), select: (e2) => h(void 0 === e2 ? p(t2) : p(e2, t2)) });
109
- }
110
- function l(e2) {
111
- return u({ [t]: () => ({ match: (t2) => {
112
- let n2 = {};
113
- const r2 = (t3, e3) => {
114
- n2[t3] = e3;
115
- };
116
- return void 0 === t2 ? (s(e2).forEach((t3) => r2(t3, void 0)), { matched: true, selections: n2 }) : { matched: o(e2, t2, r2), selections: n2 };
117
- }, getSelectionKeys: () => s(e2), matcherType: "optional" }) });
118
- }
119
- var f = (t2, e2) => {
120
- for (const n2 of t2) if (!e2(n2)) return false;
121
- return true;
122
- };
123
- var g = (t2, e2) => {
124
- for (const [n2, r2] of t2.entries()) if (!e2(r2, n2)) return false;
125
- return true;
126
- };
127
- function m(...e2) {
128
- return u({ [t]: () => ({ match: (t2) => {
129
- let n2 = {};
130
- const r2 = (t3, e3) => {
131
- n2[t3] = e3;
132
- };
133
- return { matched: e2.every((e3) => o(e3, t2, r2)), selections: n2 };
134
- }, getSelectionKeys: () => c(e2, s), matcherType: "and" }) });
135
- }
136
- function d(...e2) {
137
- return u({ [t]: () => ({ match: (t2) => {
138
- let n2 = {};
139
- const r2 = (t3, e3) => {
140
- n2[t3] = e3;
141
- };
142
- return c(e2, s).forEach((t3) => r2(t3, void 0)), { matched: e2.some((e3) => o(e3, t2, r2)), selections: n2 };
143
- }, getSelectionKeys: () => c(e2, s), matcherType: "or" }) });
144
- }
145
- function y(e2) {
146
- return { [t]: () => ({ match: (t2) => ({ matched: Boolean(e2(t2)) }) }) };
147
- }
148
- function p(...e2) {
149
- const r2 = "string" == typeof e2[0] ? e2[0] : void 0, i2 = 2 === e2.length ? e2[1] : "string" == typeof e2[0] ? void 0 : e2[0];
150
- return u({ [t]: () => ({ match: (t2) => {
151
- let e3 = { [null != r2 ? r2 : n]: t2 };
152
- return { matched: void 0 === i2 || o(i2, t2, (t3, n2) => {
153
- e3[t3] = n2;
154
- }), selections: e3 };
155
- }, getSelectionKeys: () => [null != r2 ? r2 : n].concat(void 0 === i2 ? [] : s(i2)) }) });
156
- }
157
- function v(t2) {
158
- return "number" == typeof t2;
159
- }
160
- function b(t2) {
161
- return "string" == typeof t2;
162
- }
163
- function w(t2) {
164
- return "bigint" == typeof t2;
165
- }
166
- var S = u(y(function(t2) {
167
- return true;
168
- }));
169
- var O2 = S;
170
- var j = (t2) => Object.assign(u(t2), { startsWith: (e2) => {
171
- return j(m(t2, (n2 = e2, y((t3) => b(t3) && t3.startsWith(n2)))));
172
- var n2;
173
- }, endsWith: (e2) => {
174
- return j(m(t2, (n2 = e2, y((t3) => b(t3) && t3.endsWith(n2)))));
175
- var n2;
176
- }, minLength: (e2) => j(m(t2, ((t3) => y((e3) => b(e3) && e3.length >= t3))(e2))), length: (e2) => j(m(t2, ((t3) => y((e3) => b(e3) && e3.length === t3))(e2))), maxLength: (e2) => j(m(t2, ((t3) => y((e3) => b(e3) && e3.length <= t3))(e2))), includes: (e2) => {
177
- return j(m(t2, (n2 = e2, y((t3) => b(t3) && t3.includes(n2)))));
178
- var n2;
179
- }, regex: (e2) => {
180
- return j(m(t2, (n2 = e2, y((t3) => b(t3) && Boolean(t3.match(n2))))));
181
- var n2;
182
- } });
183
- var E = j(y(b));
184
- var K = (t2) => Object.assign(u(t2), { between: (e2, n2) => K(m(t2, ((t3, e3) => y((n3) => v(n3) && t3 <= n3 && e3 >= n3))(e2, n2))), lt: (e2) => K(m(t2, ((t3) => y((e3) => v(e3) && e3 < t3))(e2))), gt: (e2) => K(m(t2, ((t3) => y((e3) => v(e3) && e3 > t3))(e2))), lte: (e2) => K(m(t2, ((t3) => y((e3) => v(e3) && e3 <= t3))(e2))), gte: (e2) => K(m(t2, ((t3) => y((e3) => v(e3) && e3 >= t3))(e2))), int: () => K(m(t2, y((t3) => v(t3) && Number.isInteger(t3)))), finite: () => K(m(t2, y((t3) => v(t3) && Number.isFinite(t3)))), positive: () => K(m(t2, y((t3) => v(t3) && t3 > 0))), negative: () => K(m(t2, y((t3) => v(t3) && t3 < 0))) });
185
- var x = K(y(v));
186
- var A = (t2) => Object.assign(u(t2), { between: (e2, n2) => A(m(t2, ((t3, e3) => y((n3) => w(n3) && t3 <= n3 && e3 >= n3))(e2, n2))), lt: (e2) => A(m(t2, ((t3) => y((e3) => w(e3) && e3 < t3))(e2))), gt: (e2) => A(m(t2, ((t3) => y((e3) => w(e3) && e3 > t3))(e2))), lte: (e2) => A(m(t2, ((t3) => y((e3) => w(e3) && e3 <= t3))(e2))), gte: (e2) => A(m(t2, ((t3) => y((e3) => w(e3) && e3 >= t3))(e2))), positive: () => A(m(t2, y((t3) => w(t3) && t3 > 0))), negative: () => A(m(t2, y((t3) => w(t3) && t3 < 0))) });
187
- var P = A(y(w));
188
- var T = u(y(function(t2) {
189
- return "boolean" == typeof t2;
190
- }));
191
- var k = u(y(function(t2) {
192
- return "symbol" == typeof t2;
193
- }));
194
- var B = u(y(function(t2) {
195
- return null == t2;
196
- }));
197
- var _ = u(y(function(t2) {
198
- return null != t2;
199
- }));
200
- var N = { __proto__: null, matcher: t, optional: l, array: function(...e2) {
201
- return h({ [t]: () => ({ match: (t2) => {
202
- if (!Array.isArray(t2)) return { matched: false };
203
- if (0 === e2.length) return { matched: true };
204
- const n2 = e2[0];
205
- let r2 = {};
206
- if (0 === t2.length) return s(n2).forEach((t3) => {
207
- r2[t3] = [];
208
- }), { matched: true, selections: r2 };
209
- const i2 = (t3, e3) => {
210
- r2[t3] = (r2[t3] || []).concat([e3]);
211
- };
212
- return { matched: t2.every((t3) => o(n2, t3, i2)), selections: r2 };
213
- }, getSelectionKeys: () => 0 === e2.length ? [] : s(e2[0]) }) });
214
- }, set: function(...e2) {
215
- return u({ [t]: () => ({ match: (t2) => {
216
- if (!(t2 instanceof Set)) return { matched: false };
217
- let n2 = {};
218
- if (0 === t2.size) return { matched: true, selections: n2 };
219
- if (0 === e2.length) return { matched: true };
220
- const r2 = (t3, e3) => {
221
- n2[t3] = (n2[t3] || []).concat([e3]);
222
- }, i2 = e2[0];
223
- return { matched: f(t2, (t3) => o(i2, t3, r2)), selections: n2 };
224
- }, getSelectionKeys: () => 0 === e2.length ? [] : s(e2[0]) }) });
225
- }, map: function(...e2) {
226
- return u({ [t]: () => ({ match: (t2) => {
227
- if (!(t2 instanceof Map)) return { matched: false };
228
- let n2 = {};
229
- if (0 === t2.size) return { matched: true, selections: n2 };
230
- const r2 = (t3, e3) => {
231
- n2[t3] = (n2[t3] || []).concat([e3]);
232
- };
233
- if (0 === e2.length) return { matched: true };
234
- var i2;
235
- if (1 === e2.length) throw new Error(`\`P.map\` wasn't given enough arguments. Expected (key, value), received ${null == (i2 = e2[0]) ? void 0 : i2.toString()}`);
236
- const [s2, c2] = e2;
237
- return { matched: g(t2, (t3, e3) => {
238
- const n3 = o(s2, e3, r2), i3 = o(c2, t3, r2);
239
- return n3 && i3;
240
- }), selections: n2 };
241
- }, getSelectionKeys: () => 0 === e2.length ? [] : [...s(e2[0]), ...s(e2[1])] }) });
242
- }, intersection: m, union: d, not: function(e2) {
243
- return u({ [t]: () => ({ match: (t2) => ({ matched: !o(e2, t2, () => {
244
- }) }), getSelectionKeys: () => [], matcherType: "not" }) });
245
- }, when: y, select: p, any: S, _: O2, string: E, number: x, bigint: P, boolean: T, symbol: k, nullish: B, nonNullable: _, instanceOf: function(t2) {
246
- return u(y(/* @__PURE__ */ function(t3) {
247
- return (e2) => e2 instanceof t3;
248
- }(t2)));
249
- }, shape: function(t2) {
250
- return u(y(a(t2)));
251
- } };
252
- var W = { matched: false, value: void 0 };
253
- function $(t2) {
254
- return new z(t2, W);
255
- }
256
- var z = class _z {
257
- constructor(t2, e2) {
258
- this.input = void 0, this.state = void 0, this.input = t2, this.state = e2;
259
- }
260
- with(...t2) {
261
- if (this.state.matched) return this;
262
- const e2 = t2[t2.length - 1], r2 = [t2[0]];
263
- let i2;
264
- 3 === t2.length && "function" == typeof t2[1] ? i2 = t2[1] : t2.length > 2 && r2.push(...t2.slice(1, t2.length - 1));
265
- let s2 = false, c2 = {};
266
- const a2 = (t3, e3) => {
267
- s2 = true, c2[t3] = e3;
268
- }, u2 = !r2.some((t3) => o(t3, this.input, a2)) || i2 && !Boolean(i2(this.input)) ? W : { matched: true, value: e2(s2 ? n in c2 ? c2[n] : c2 : this.input, this.input) };
269
- return new _z(this.input, u2);
270
- }
271
- when(t2, e2) {
272
- if (this.state.matched) return this;
273
- const n2 = Boolean(t2(this.input));
274
- return new _z(this.input, n2 ? { matched: true, value: e2(this.input, this.input) } : W);
275
- }
276
- otherwise(t2) {
277
- return this.state.matched ? this.state.value : t2(this.input);
278
- }
279
- exhaustive() {
280
- if (this.state.matched) return this.state.value;
281
- let t2;
282
- try {
283
- t2 = JSON.stringify(this.input);
284
- } catch (e2) {
285
- t2 = this.input;
286
- }
287
- throw new Error(`Pattern matching error: no pattern matches value ${t2}`);
288
- }
289
- run() {
290
- return this.exhaustive();
291
- }
292
- returnType() {
293
- return this;
294
- }
295
- };
296
-
297
- // src/get-prop.ts
298
43
  function getPropName(node) {
299
- return $(node.name).when(is(NodeType.JSXIdentifier), (n2) => n2.name).when(is(NodeType.JSXNamespacedName), (n2) => `${n2.namespace.name}:${n2.name.name}`).exhaustive();
44
+ return match(node.name).when(is(NodeType.JSXIdentifier), (n) => n.name).when(is(NodeType.JSXNamespacedName), (n) => `${n.namespace.name}:${n.name.name}`).exhaustive();
300
45
  }
301
46
  function getProp(props, propName, context, initialScope) {
302
47
  return findPropInAttributes(props, context, initialScope)(propName);
@@ -317,10 +62,10 @@ function findPropInProperties(properties, context, initialScope, seenProps = [])
317
62
  return (propName) => {
318
63
  return O.fromNullable(
319
64
  properties.find((prop) => {
320
- return $(prop).when(is(NodeType.Property), (prop2) => {
65
+ return match(prop).when(is(NodeType.Property), (prop2) => {
321
66
  return "name" in prop2.key && prop2.key.name === propName;
322
67
  }).when(is(NodeType.SpreadElement), (prop2) => {
323
- return $(prop2.argument).when(is(NodeType.Identifier), (argument) => {
68
+ return match(prop2.argument).when(is(NodeType.Identifier), (argument) => {
324
69
  const { name } = argument;
325
70
  const maybeInit = O.flatMap(
326
71
  findVariable(name, initialScope),
@@ -349,8 +94,8 @@ function findPropInAttributes(attributes, context, initialScope) {
349
94
  return (propName) => {
350
95
  return O.fromNullable(
351
96
  attributes.find((attr) => {
352
- return $(attr).when(is(NodeType.JSXAttribute), (attr2) => getPropName(attr2) === propName).when(is(NodeType.JSXSpreadAttribute), (attr2) => {
353
- return $(attr2.argument).with({ type: NodeType.Identifier }, (argument) => {
97
+ return match(attr).when(is(NodeType.JSXAttribute), (attr2) => getPropName(attr2) === propName).when(is(NodeType.JSXSpreadAttribute), (attr2) => {
98
+ return match(attr2.argument).with({ type: NodeType.Identifier }, (argument) => {
354
99
  const { name } = argument;
355
100
  const maybeInit = O.flatMap(
356
101
  findVariable(name, initialScope),
@@ -409,19 +154,19 @@ var JSXValueHint = {
409
154
  var DEFAULT_JSX_VALUE_HINT = 0n | JSXValueHint.SkipUndefinedLiteral | JSXValueHint.SkipBooleanLiteral;
410
155
  function isJSXValue(node, context, hint = DEFAULT_JSX_VALUE_HINT) {
411
156
  if (!node) return false;
412
- return $(node).with({ type: NodeType.JSXElement }, F.constTrue).with({ type: NodeType.JSXFragment }, F.constTrue).with({ type: NodeType.JSXMemberExpression }, F.constTrue).with({ type: NodeType.JSXNamespacedName }, F.constTrue).with({ type: NodeType.Literal }, (node2) => {
413
- return $(node2.value).with(null, () => !(hint & JSXValueHint.SkipNullLiteral)).with(N.boolean, () => !(hint & JSXValueHint.SkipBooleanLiteral)).with(N.string, () => !(hint & JSXValueHint.SkipStringLiteral)).with(N.number, () => !(hint & JSXValueHint.SkipNumberLiteral)).otherwise(F.constFalse);
157
+ return match(node).with({ type: NodeType.JSXElement }, F.constTrue).with({ type: NodeType.JSXFragment }, F.constTrue).with({ type: NodeType.JSXMemberExpression }, F.constTrue).with({ type: NodeType.JSXNamespacedName }, F.constTrue).with({ type: NodeType.Literal }, (node2) => {
158
+ 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);
414
159
  }).with({ type: NodeType.TemplateLiteral }, () => !(hint & JSXValueHint.SkipStringLiteral)).with({ type: NodeType.ArrayExpression }, (node2) => {
415
- if (hint & JSXValueHint.StrictArray) return node2.elements.every((n2) => isJSXValue(n2, context, hint));
416
- return node2.elements.some((n2) => isJSXValue(n2, context, hint));
160
+ if (hint & JSXValueHint.StrictArray) return node2.elements.every((n) => isJSXValue(n, context, hint));
161
+ return node2.elements.some((n) => isJSXValue(n, context, hint));
417
162
  }).with({ type: NodeType.ConditionalExpression }, (node2) => {
418
163
  function leftHasJSX(node3) {
419
164
  if (Array.isArray(node3.consequent)) {
420
165
  if (node3.consequent.length === 0) return !(hint & JSXValueHint.SkipEmptyArray);
421
166
  if (hint & JSXValueHint.StrictArray) {
422
- return node3.consequent.every((n2) => isJSXValue(n2, context, hint));
167
+ return node3.consequent.every((n) => isJSXValue(n, context, hint));
423
168
  }
424
- return node3.consequent.some((n2) => isJSXValue(n2, context, hint));
169
+ return node3.consequent.some((n) => isJSXValue(n, context, hint));
425
170
  }
426
171
  return isJSXValue(node3.consequent, context, hint);
427
172
  }
@@ -442,7 +187,7 @@ function isJSXValue(node, context, hint = DEFAULT_JSX_VALUE_HINT) {
442
187
  return isJSXValue(exp, context, hint);
443
188
  }).with({ type: NodeType.CallExpression }, (node2) => {
444
189
  if (hint & JSXValueHint.SkipCreateElement) return false;
445
- return $(node2.callee).with({ type: NodeType.Identifier, name: "createElement" }, F.constTrue).with({ type: NodeType.MemberExpression, property: { name: "createElement" } }, F.constTrue).otherwise(F.constFalse);
190
+ return match(node2.callee).with({ type: NodeType.Identifier, name: "createElement" }, F.constTrue).with({ type: NodeType.MemberExpression, property: { name: "createElement" } }, F.constTrue).otherwise(F.constFalse);
446
191
  }).with({ type: NodeType.Identifier }, (node2) => {
447
192
  const { name } = node2;
448
193
  if (name === "undefined") return !(hint & JSXValueHint.SkipUndefinedLiteral);
@@ -452,7 +197,7 @@ function isJSXValue(node, context, hint = DEFAULT_JSX_VALUE_HINT) {
452
197
  return F.pipe(
453
198
  maybeVariable,
454
199
  O.flatMap(getVariableNode(0)),
455
- O.exists((n2) => isJSXValue(n2, context, hint))
200
+ O.exists((n) => isJSXValue(n, context, hint))
456
201
  );
457
202
  }).otherwise(F.constFalse);
458
203
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/jsx",
3
- "version": "1.5.31-next.3",
3
+ "version": "1.5.31-next.4",
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": {
@@ -38,13 +38,13 @@
38
38
  "@typescript-eslint/scope-manager": "^7.17.0",
39
39
  "@typescript-eslint/types": "^7.17.0",
40
40
  "@typescript-eslint/utils": "^7.17.0",
41
- "@eslint-react/ast": "1.5.31-next.3",
42
- "@eslint-react/types": "1.5.31-next.3",
43
- "@eslint-react/tools": "1.5.31-next.3",
44
- "@eslint-react/var": "1.5.31-next.3"
41
+ "ts-pattern": "^5.2.0",
42
+ "@eslint-react/ast": "1.5.31-next.4",
43
+ "@eslint-react/tools": "1.5.31-next.4",
44
+ "@eslint-react/types": "1.5.31-next.4",
45
+ "@eslint-react/var": "1.5.31-next.4"
45
46
  },
46
47
  "devDependencies": {
47
- "ts-pattern": "5.2.0",
48
48
  "tsup": "8.2.2"
49
49
  },
50
50
  "scripts": {