tsl-react 0.0.9 → 0.0.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.
Files changed (2) hide show
  1. package/dist/index.js +8 -411
  2. package/package.json +9 -8
package/dist/index.js CHANGED
@@ -1,413 +1,10 @@
1
- import { unit } from "@let/eff";
2
1
  import { isLogicalNegationExpression } from "@react-analyzer/ast";
3
2
  import { getAnalyzerOptions, report } from "@react-analyzer/shared";
4
3
  import { compare } from "compare-versions";
5
4
  import { defineRule } from "tsl";
6
5
  import ts, { SyntaxKind } from "typescript";
6
+ import { P, isMatching, match } from "ts-pattern";
7
7
 
8
- //#region ../../../node_modules/.pnpm/ts-pattern@5.9.0/node_modules/ts-pattern/dist/index.js
9
- const t = Symbol.for("@ts-pattern/matcher"), e = Symbol.for("@ts-pattern/isVariadic"), n = "@ts-pattern/anonymous-select-key", r = (t) => Boolean(t && "object" == typeof t), i = (e) => e && !!e[t], o = (n, s, c) => {
10
- if (i(n)) {
11
- const { matched: r, selections: i } = n[t]().match(s);
12
- return r && i && Object.keys(i).forEach((t) => c(t, i[t])), r;
13
- }
14
- if (r(n)) {
15
- if (!r(s)) return !1;
16
- if (Array.isArray(n)) {
17
- if (!Array.isArray(s)) return !1;
18
- let t = [], r = [], u = [];
19
- for (const o of n.keys()) {
20
- const s = n[o];
21
- i(s) && s[e] ? u.push(s) : u.length ? r.push(s) : t.push(s);
22
- }
23
- if (u.length) {
24
- if (u.length > 1) throw new Error("Pattern error: Using `...P.array(...)` several times in a single pattern is not allowed.");
25
- if (s.length < t.length + r.length) return !1;
26
- const e = s.slice(0, t.length), n = 0 === r.length ? [] : s.slice(-r.length), i = s.slice(t.length, 0 === r.length ? Infinity : -r.length);
27
- return t.every((t, n) => o(t, e[n], c)) && r.every((t, e) => o(t, n[e], c)) && (0 === u.length || o(u[0], i, c));
28
- }
29
- return n.length === s.length && n.every((t, e) => o(t, s[e], c));
30
- }
31
- return Reflect.ownKeys(n).every((e) => {
32
- const r = n[e];
33
- return (e in s || i(u = r) && "optional" === u[t]().matcherType) && o(r, s[e], c);
34
- var u;
35
- });
36
- }
37
- return Object.is(s, n);
38
- }, s = (e) => {
39
- var n, o, u;
40
- return r(e) ? i(e) ? null != (n = null == (o = (u = e[t]()).getSelectionKeys) ? void 0 : o.call(u)) ? n : [] : Array.isArray(e) ? c(e, s) : c(Object.values(e), s) : [];
41
- }, c = (t, e) => t.reduce((t, n) => t.concat(e(n)), []);
42
- function u(...t) {
43
- if (1 === t.length) {
44
- const [e] = t;
45
- return (t) => o(e, t, () => {});
46
- }
47
- if (2 === t.length) {
48
- const [e, n] = t;
49
- return o(e, n, () => {});
50
- }
51
- throw new Error(`isMatching wasn't given the right number of arguments: expected 1 or 2, received ${t.length}.`);
52
- }
53
- function a(t) {
54
- return Object.assign(t, {
55
- optional: () => h(t),
56
- and: (e) => d(t, e),
57
- or: (e) => y(t, e),
58
- select: (e) => void 0 === e ? v(t) : v(e, t)
59
- });
60
- }
61
- function l(t) {
62
- return Object.assign(((t) => Object.assign(t, { [Symbol.iterator]() {
63
- let n = 0;
64
- const r = [{
65
- value: Object.assign(t, { [e]: !0 }),
66
- done: !1
67
- }, {
68
- done: !0,
69
- value: void 0
70
- }];
71
- return { next: () => {
72
- var t;
73
- return null != (t = r[n++]) ? t : r.at(-1);
74
- } };
75
- } }))(t), {
76
- optional: () => l(h(t)),
77
- select: (e) => l(void 0 === e ? v(t) : v(e, t))
78
- });
79
- }
80
- function h(e) {
81
- return a({ [t]: () => ({
82
- match: (t) => {
83
- let n = {};
84
- const r = (t, e) => {
85
- n[t] = e;
86
- };
87
- return void 0 === t ? (s(e).forEach((t) => r(t, void 0)), {
88
- matched: !0,
89
- selections: n
90
- }) : {
91
- matched: o(e, t, r),
92
- selections: n
93
- };
94
- },
95
- getSelectionKeys: () => s(e),
96
- matcherType: "optional"
97
- }) });
98
- }
99
- const f = (t, e) => {
100
- for (const n of t) if (!e(n)) return !1;
101
- return !0;
102
- }, g = (t, e) => {
103
- for (const [n, r] of t.entries()) if (!e(r, n)) return !1;
104
- return !0;
105
- }, m = (t, e) => {
106
- const n = Reflect.ownKeys(t);
107
- for (const r of n) if (!e(r, t[r])) return !1;
108
- return !0;
109
- };
110
- function d(...e) {
111
- return a({ [t]: () => ({
112
- match: (t) => {
113
- let n = {};
114
- const r = (t, e) => {
115
- n[t] = e;
116
- };
117
- return {
118
- matched: e.every((e) => o(e, t, r)),
119
- selections: n
120
- };
121
- },
122
- getSelectionKeys: () => c(e, s),
123
- matcherType: "and"
124
- }) });
125
- }
126
- function y(...e) {
127
- return a({ [t]: () => ({
128
- match: (t) => {
129
- let n = {};
130
- const r = (t, e) => {
131
- n[t] = e;
132
- };
133
- return c(e, s).forEach((t) => r(t, void 0)), {
134
- matched: e.some((e) => o(e, t, r)),
135
- selections: n
136
- };
137
- },
138
- getSelectionKeys: () => c(e, s),
139
- matcherType: "or"
140
- }) });
141
- }
142
- function p(e) {
143
- return { [t]: () => ({ match: (t) => ({ matched: Boolean(e(t)) }) }) };
144
- }
145
- function v(...e) {
146
- const r = "string" == typeof e[0] ? e[0] : void 0, i = 2 === e.length ? e[1] : "string" == typeof e[0] ? void 0 : e[0];
147
- return a({ [t]: () => ({
148
- match: (t) => {
149
- let e = { [null != r ? r : n]: t };
150
- return {
151
- matched: void 0 === i || o(i, t, (t, n) => {
152
- e[t] = n;
153
- }),
154
- selections: e
155
- };
156
- },
157
- getSelectionKeys: () => [null != r ? r : n].concat(void 0 === i ? [] : s(i))
158
- }) });
159
- }
160
- function b(t) {
161
- return !0;
162
- }
163
- function w(t) {
164
- return "number" == typeof t;
165
- }
166
- function S(t) {
167
- return "string" == typeof t;
168
- }
169
- function j(t) {
170
- return "bigint" == typeof t;
171
- }
172
- const K = a(p(b)), O = a(p(b)), E = K, x = (t) => Object.assign(a(t), {
173
- startsWith: (e) => {
174
- return x(d(t, (n = e, p((t) => S(t) && t.startsWith(n)))));
175
- var n;
176
- },
177
- endsWith: (e) => {
178
- return x(d(t, (n = e, p((t) => S(t) && t.endsWith(n)))));
179
- var n;
180
- },
181
- minLength: (e) => x(d(t, ((t) => p((e) => S(e) && e.length >= t))(e))),
182
- length: (e) => x(d(t, ((t) => p((e) => S(e) && e.length === t))(e))),
183
- maxLength: (e) => x(d(t, ((t) => p((e) => S(e) && e.length <= t))(e))),
184
- includes: (e) => {
185
- return x(d(t, (n = e, p((t) => S(t) && t.includes(n)))));
186
- var n;
187
- },
188
- regex: (e) => {
189
- return x(d(t, (n = e, p((t) => S(t) && Boolean(t.match(n))))));
190
- var n;
191
- }
192
- }), A = x(p(S)), N = (t) => Object.assign(a(t), {
193
- between: (e, n) => N(d(t, ((t, e) => p((n) => w(n) && t <= n && e >= n))(e, n))),
194
- lt: (e) => N(d(t, ((t) => p((e) => w(e) && e < t))(e))),
195
- gt: (e) => N(d(t, ((t) => p((e) => w(e) && e > t))(e))),
196
- lte: (e) => N(d(t, ((t) => p((e) => w(e) && e <= t))(e))),
197
- gte: (e) => N(d(t, ((t) => p((e) => w(e) && e >= t))(e))),
198
- int: () => N(d(t, p((t) => w(t) && Number.isInteger(t)))),
199
- finite: () => N(d(t, p((t) => w(t) && Number.isFinite(t)))),
200
- positive: () => N(d(t, p((t) => w(t) && t > 0))),
201
- negative: () => N(d(t, p((t) => w(t) && t < 0)))
202
- }), P = N(p(w)), k = (t) => Object.assign(a(t), {
203
- between: (e, n) => k(d(t, ((t, e) => p((n) => j(n) && t <= n && e >= n))(e, n))),
204
- lt: (e) => k(d(t, ((t) => p((e) => j(e) && e < t))(e))),
205
- gt: (e) => k(d(t, ((t) => p((e) => j(e) && e > t))(e))),
206
- lte: (e) => k(d(t, ((t) => p((e) => j(e) && e <= t))(e))),
207
- gte: (e) => k(d(t, ((t) => p((e) => j(e) && e >= t))(e))),
208
- positive: () => k(d(t, p((t) => j(t) && t > 0))),
209
- negative: () => k(d(t, p((t) => j(t) && t < 0)))
210
- });
211
- var z = {
212
- __proto__: null,
213
- matcher: t,
214
- optional: h,
215
- array: function(...e) {
216
- return l({ [t]: () => ({
217
- match: (t) => {
218
- if (!Array.isArray(t)) return { matched: !1 };
219
- if (0 === e.length) return { matched: !0 };
220
- const n = e[0];
221
- let r = {};
222
- if (0 === t.length) return s(n).forEach((t) => {
223
- r[t] = [];
224
- }), {
225
- matched: !0,
226
- selections: r
227
- };
228
- const i = (t, e) => {
229
- r[t] = (r[t] || []).concat([e]);
230
- };
231
- return {
232
- matched: t.every((t) => o(n, t, i)),
233
- selections: r
234
- };
235
- },
236
- getSelectionKeys: () => 0 === e.length ? [] : s(e[0])
237
- }) });
238
- },
239
- set: function(...e) {
240
- return a({ [t]: () => ({
241
- match: (t) => {
242
- if (!(t instanceof Set)) return { matched: !1 };
243
- let n = {};
244
- if (0 === t.size) return {
245
- matched: !0,
246
- selections: n
247
- };
248
- if (0 === e.length) return { matched: !0 };
249
- const r = (t, e) => {
250
- n[t] = (n[t] || []).concat([e]);
251
- }, i = e[0];
252
- return {
253
- matched: f(t, (t) => o(i, t, r)),
254
- selections: n
255
- };
256
- },
257
- getSelectionKeys: () => 0 === e.length ? [] : s(e[0])
258
- }) });
259
- },
260
- map: function(...e) {
261
- return a({ [t]: () => ({
262
- match: (t) => {
263
- if (!(t instanceof Map)) return { matched: !1 };
264
- let n = {};
265
- if (0 === t.size) return {
266
- matched: !0,
267
- selections: n
268
- };
269
- const r = (t, e) => {
270
- n[t] = (n[t] || []).concat([e]);
271
- };
272
- if (0 === e.length) return { matched: !0 };
273
- var i;
274
- if (1 === e.length) throw new Error(`\`P.map\` wasn't given enough arguments. Expected (key, value), received ${null == (i = e[0]) ? void 0 : i.toString()}`);
275
- const [s, c] = e;
276
- return {
277
- matched: g(t, (t, e) => {
278
- const n = o(s, e, r), i = o(c, t, r);
279
- return n && i;
280
- }),
281
- selections: n
282
- };
283
- },
284
- getSelectionKeys: () => 0 === e.length ? [] : [...s(e[0]), ...s(e[1])]
285
- }) });
286
- },
287
- record: function(...e) {
288
- return a({ [t]: () => ({
289
- match: (t) => {
290
- if (null === t || "object" != typeof t || Array.isArray(t)) return { matched: !1 };
291
- var n;
292
- if (0 === e.length) throw new Error(`\`P.record\` wasn't given enough arguments. Expected (value) or (key, value), received ${null == (n = e[0]) ? void 0 : n.toString()}`);
293
- let r = {};
294
- const i = (t, e) => {
295
- r[t] = (r[t] || []).concat([e]);
296
- }, [s, c] = 1 === e.length ? [A, e[0]] : e;
297
- return {
298
- matched: m(t, (t, e) => {
299
- const n = "string" != typeof t || Number.isNaN(Number(t)) ? null : Number(t), r = null !== n && o(s, n, i), u = o(s, t, i), a = o(c, e, i);
300
- return (u || r) && a;
301
- }),
302
- selections: r
303
- };
304
- },
305
- getSelectionKeys: () => 0 === e.length ? [] : [...s(e[0]), ...s(e[1])]
306
- }) });
307
- },
308
- intersection: d,
309
- union: y,
310
- not: function(e) {
311
- return a({ [t]: () => ({
312
- match: (t) => ({ matched: !o(e, t, () => {}) }),
313
- getSelectionKeys: () => [],
314
- matcherType: "not"
315
- }) });
316
- },
317
- when: p,
318
- select: v,
319
- any: K,
320
- unknown: O,
321
- _: E,
322
- string: A,
323
- number: P,
324
- bigint: k(p(j)),
325
- boolean: a(p(function(t) {
326
- return "boolean" == typeof t;
327
- })),
328
- symbol: a(p(function(t) {
329
- return "symbol" == typeof t;
330
- })),
331
- nullish: a(p(function(t) {
332
- return null == t;
333
- })),
334
- nonNullable: a(p(function(t) {
335
- return null != t;
336
- })),
337
- instanceOf: function(t) {
338
- return a(p(function(t) {
339
- return (e) => e instanceof t;
340
- }(t)));
341
- },
342
- shape: function(t) {
343
- return a(p(u(t)));
344
- }
345
- };
346
- var I = class extends Error {
347
- constructor(t) {
348
- let e;
349
- try {
350
- e = JSON.stringify(t);
351
- } catch (n) {
352
- e = t;
353
- }
354
- super(`Pattern matching error: no pattern matches value ${e}`), this.input = void 0, this.input = t;
355
- }
356
- };
357
- const L = {
358
- matched: !1,
359
- value: void 0
360
- };
361
- function M(t) {
362
- return new R(t, L);
363
- }
364
- var R = class R {
365
- constructor(t, e) {
366
- this.input = void 0, this.state = void 0, this.input = t, this.state = e;
367
- }
368
- with(...t) {
369
- if (this.state.matched) return this;
370
- const e = t[t.length - 1], r = [t[0]];
371
- let i;
372
- 3 === t.length && "function" == typeof t[1] ? i = t[1] : t.length > 2 && r.push(...t.slice(1, t.length - 1));
373
- let s = !1, c = {};
374
- const u = (t, e) => {
375
- s = !0, c[t] = e;
376
- }, a = !r.some((t) => o(t, this.input, u)) || i && !Boolean(i(this.input)) ? L : {
377
- matched: !0,
378
- value: e(s ? n in c ? c[n] : c : this.input, this.input)
379
- };
380
- return new R(this.input, a);
381
- }
382
- when(t, e) {
383
- if (this.state.matched) return this;
384
- const n = Boolean(t(this.input));
385
- return new R(this.input, n ? {
386
- matched: !0,
387
- value: e(this.input, this.input)
388
- } : L);
389
- }
390
- otherwise(t) {
391
- return this.state.matched ? this.state.value : t(this.input);
392
- }
393
- exhaustive(t = F) {
394
- return this.state.matched ? this.state.value : t(this.input);
395
- }
396
- run() {
397
- return this.exhaustive();
398
- }
399
- returnType() {
400
- return this;
401
- }
402
- narrow() {
403
- return this;
404
- }
405
- };
406
- function F(t) {
407
- throw new I(t);
408
- }
409
-
410
- //#endregion
411
8
  //#region src/utils/type-is.ts
412
9
  function isFlagSet(allFlags, flag) {
413
10
  return (allFlags & flag) !== 0;
@@ -432,7 +29,7 @@ const isBooleanType = (type) => isTypeFlagSet(type, ts.TypeFlags.BooleanLike);
432
29
  /** @internal */
433
30
  const isEnumType = (type) => isTypeFlagSet(type, ts.TypeFlags.EnumLike);
434
31
  /** @internal */
435
- const isFalsyBigIntType = (type) => type.isLiteral() && u({ value: { base10Value: "0" } }, type);
32
+ const isFalsyBigIntType = (type) => type.isLiteral() && isMatching({ value: { base10Value: "0" } }, type);
436
33
  /** @internal */
437
34
  const isFalsyNumberType = (type) => type.isNumberLiteral() && type.value === 0;
438
35
  /** @internal */
@@ -448,7 +45,7 @@ const isObjectType = (type) => !isTypeFlagSet(type, ts.TypeFlags.Null | ts.TypeF
448
45
  /** @internal */
449
46
  const isStringType = (type) => isTypeFlagSet(type, ts.TypeFlags.StringLike);
450
47
  /** @internal */
451
- const isTruthyBigIntType = (type) => type.isLiteral() && u({ value: { base10Value: z.not("0") } }, type);
48
+ const isTruthyBigIntType = (type) => type.isLiteral() && isMatching({ value: { base10Value: P.not("0") } }, type);
452
49
  /** @internal */
453
50
  const isTruthyNumberType = (type) => type.isNumberLiteral() && type.value !== 0;
454
51
  /** @internal */
@@ -480,17 +77,17 @@ function getTypeVariants(types) {
480
77
  } else if (booleans.length === 2) variants.add("boolean");
481
78
  const strings = types.filter(isStringType);
482
79
  if (strings.length > 0) {
483
- const evaluated = M(strings).when((types) => types.every(isTruthyStringType), () => "truthy string").when((types) => types.every(isFalsyStringType), () => "falsy string").otherwise(() => "string");
80
+ const evaluated = match(strings).when((types) => types.every(isTruthyStringType), () => "truthy string").when((types) => types.every(isFalsyStringType), () => "falsy string").otherwise(() => "string");
484
81
  variants.add(evaluated);
485
82
  }
486
83
  const bigints = types.filter(isBigIntType);
487
84
  if (bigints.length > 0) {
488
- const evaluated = M(bigints).when((types) => types.every(isTruthyBigIntType), () => "truthy bigint").when((types) => types.every(isFalsyBigIntType), () => "falsy bigint").otherwise(() => "bigint");
85
+ const evaluated = match(bigints).when((types) => types.every(isTruthyBigIntType), () => "truthy bigint").when((types) => types.every(isFalsyBigIntType), () => "falsy bigint").otherwise(() => "bigint");
489
86
  variants.add(evaluated);
490
87
  }
491
88
  const numbers = types.filter(isNumberType);
492
89
  if (numbers.length > 0) {
493
- const evaluated = M(numbers).when((types) => types.every(isTruthyNumberType), () => "truthy number").when((types) => types.every(isFalsyNumberType), () => "falsy number").otherwise(() => "number");
90
+ const evaluated = match(numbers).when((types) => types.every(isTruthyNumberType), () => "truthy number").when((types) => types.every(isFalsyNumberType), () => "falsy number").otherwise(() => "number");
494
91
  variants.add(evaluated);
495
92
  }
496
93
  if (types.some(isEnumType)) variants.add("enum");
@@ -575,14 +172,14 @@ const noLeakedConditionalRendering = defineRule(() => {
575
172
  ...compare(version, "18.0.0", "<") ? [] : ["string", "falsy string"]
576
173
  ];
577
174
  function getReportDescriptor(node) {
578
- if (isLogicalNegationExpression(node.left)) return unit;
175
+ if (isLogicalNegationExpression(node.left)) return null;
579
176
  const leftType = ctx.utils.getConstrainedTypeAtLocation(node.left);
580
177
  const leftTypeVariants = getTypeVariants(ctx.utils.unionConstituents(leftType));
581
178
  if (!Array.from(leftTypeVariants.values()).every((type) => allowedVariants.some((allowed) => allowed === type))) return {
582
179
  node: node.left,
583
180
  message: messages.noLeakedConditionalRendering({ value: node.left.getText() })
584
181
  };
585
- return unit;
182
+ return null;
586
183
  }
587
184
  return {
588
185
  state,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsl-react",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "description": "A unified plugin that combines all individual plugins from the react-analyzer monorepo into one.",
5
5
  "keywords": [
6
6
  "react",
@@ -27,18 +27,19 @@
27
27
  "./package.json"
28
28
  ],
29
29
  "dependencies": {
30
- "@let/eff": "npm:@jsr/let__eff@^0.1.2",
31
30
  "compare-versions": "^6.1.1",
32
- "@react-analyzer/core": "0.0.9",
33
- "@react-analyzer/ast": "0.0.9",
34
- "@react-analyzer/shared": "0.0.9"
31
+ "ts-pattern": "^5.9.0",
32
+ "@local/eff": "0.0.11",
33
+ "@react-analyzer/core": "0.0.11",
34
+ "@react-analyzer/ast": "0.0.11",
35
+ "@react-analyzer/shared": "0.0.11"
35
36
  },
36
37
  "devDependencies": {
37
- "tsdown": "^0.20.3",
38
- "@local/configs": "0.0.0"
38
+ "tsdown": "^0.21.0-beta.2",
39
+ "@local/configs": "0.0.11"
39
40
  },
40
41
  "peerDependencies": {
41
- "tsl": "^1.0.28",
42
+ "tsl": "^1.0.29",
42
43
  "typescript": "^4.9.5 || ^5.4.5"
43
44
  },
44
45
  "engines": {