tsl-react 0.0.6 → 0.0.8
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.ts +2 -3
- package/dist/index.js +502 -6
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as tsl0 from "tsl";
|
|
2
2
|
|
|
3
3
|
//#region src/rules/no-leaked-conditional-rendering.d.ts
|
|
4
|
-
|
|
5
4
|
/**
|
|
6
5
|
* Prevents problematic leaked values from being rendered.
|
|
7
6
|
*
|
|
@@ -53,6 +52,6 @@ import { Rule } from "tsl";
|
|
|
53
52
|
*
|
|
54
53
|
* @since 0.0.0
|
|
55
54
|
*/
|
|
56
|
-
declare const noLeakedConditionalRendering: (options?: "off" | undefined) => Rule<unknown>;
|
|
55
|
+
declare const noLeakedConditionalRendering: (options?: "off" | undefined) => tsl0.Rule<unknown>;
|
|
57
56
|
//#endregion
|
|
58
57
|
export { noLeakedConditionalRendering };
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,509 @@
|
|
|
1
|
-
import { compare } from "compare-versions";
|
|
2
|
-
import { defineRule } from "tsl";
|
|
3
|
-
import { SyntaxKind } from "typescript";
|
|
4
1
|
import { unit } from "@let/eff";
|
|
5
2
|
import { isLogicalNegationExpression } from "@react-analyzer/ast";
|
|
6
|
-
import { getVariantsOfTypes } from "@react-analyzer/core";
|
|
7
3
|
import { getAnalyzerOptions, report } from "@react-analyzer/shared";
|
|
4
|
+
import { compare } from "compare-versions";
|
|
5
|
+
import { defineRule } from "tsl";
|
|
6
|
+
import ts, { SyntaxKind } from "typescript";
|
|
8
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$1 = n[o];
|
|
21
|
+
i(s$1) && s$1[e] ? u.push(s$1) : u.length ? r.push(s$1) : t.push(s$1);
|
|
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$1 = 0 === r.length ? [] : s.slice(-r.length), i = s.slice(t.length, 0 === r.length ? Infinity : -r.length);
|
|
27
|
+
return t.every((t$1, n$2) => o(t$1, e[n$2], c)) && r.every((t$1, e$1) => o(t$1, n$1[e$1], c)) && (0 === u.length || o(u[0], i, c));
|
|
28
|
+
}
|
|
29
|
+
return n.length === s.length && n.every((t$1, e) => o(t$1, 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$1, n) => t$1.concat(e(n)), []);
|
|
42
|
+
function u(...t) {
|
|
43
|
+
if (1 === t.length) {
|
|
44
|
+
const [e] = t;
|
|
45
|
+
return (t$1) => o(e, t$1, () => {});
|
|
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$1) => Object.assign(t$1, { [Symbol.iterator]() {
|
|
63
|
+
let n = 0;
|
|
64
|
+
const r = [{
|
|
65
|
+
value: Object.assign(t$1, { [e]: !0 }),
|
|
66
|
+
done: !1
|
|
67
|
+
}, {
|
|
68
|
+
done: !0,
|
|
69
|
+
value: void 0
|
|
70
|
+
}];
|
|
71
|
+
return { next: () => {
|
|
72
|
+
var t$2;
|
|
73
|
+
return null != (t$2 = r[n++]) ? t$2 : 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$1, e$1) => {
|
|
85
|
+
n[t$1] = e$1;
|
|
86
|
+
};
|
|
87
|
+
return void 0 === t ? (s(e).forEach((t$1) => r(t$1, 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$1, e$1) => {
|
|
115
|
+
n[t$1] = e$1;
|
|
116
|
+
};
|
|
117
|
+
return {
|
|
118
|
+
matched: e.every((e$1) => o(e$1, 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$1, e$1) => {
|
|
131
|
+
n[t$1] = e$1;
|
|
132
|
+
};
|
|
133
|
+
return c(e, s).forEach((t$1) => r(t$1, void 0)), {
|
|
134
|
+
matched: e.some((e$1) => o(e$1, 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$1 = { [null != r ? r : n]: t };
|
|
150
|
+
return {
|
|
151
|
+
matched: void 0 === i || o(i, t, (t$1, n) => {
|
|
152
|
+
e$1[t$1] = n;
|
|
153
|
+
}),
|
|
154
|
+
selections: e$1
|
|
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$1) => S(t$1) && t$1.startsWith(n)))));
|
|
175
|
+
var n;
|
|
176
|
+
},
|
|
177
|
+
endsWith: (e) => {
|
|
178
|
+
return x(d(t, (n = e, p((t$1) => S(t$1) && t$1.endsWith(n)))));
|
|
179
|
+
var n;
|
|
180
|
+
},
|
|
181
|
+
minLength: (e) => x(d(t, ((t$1) => p((e$1) => S(e$1) && e$1.length >= t$1))(e))),
|
|
182
|
+
length: (e) => x(d(t, ((t$1) => p((e$1) => S(e$1) && e$1.length === t$1))(e))),
|
|
183
|
+
maxLength: (e) => x(d(t, ((t$1) => p((e$1) => S(e$1) && e$1.length <= t$1))(e))),
|
|
184
|
+
includes: (e) => {
|
|
185
|
+
return x(d(t, (n = e, p((t$1) => S(t$1) && t$1.includes(n)))));
|
|
186
|
+
var n;
|
|
187
|
+
},
|
|
188
|
+
regex: (e) => {
|
|
189
|
+
return x(d(t, (n = e, p((t$1) => S(t$1) && Boolean(t$1.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$1, e$1) => p((n$1) => w(n$1) && t$1 <= n$1 && e$1 >= n$1))(e, n))),
|
|
194
|
+
lt: (e) => N(d(t, ((t$1) => p((e$1) => w(e$1) && e$1 < t$1))(e))),
|
|
195
|
+
gt: (e) => N(d(t, ((t$1) => p((e$1) => w(e$1) && e$1 > t$1))(e))),
|
|
196
|
+
lte: (e) => N(d(t, ((t$1) => p((e$1) => w(e$1) && e$1 <= t$1))(e))),
|
|
197
|
+
gte: (e) => N(d(t, ((t$1) => p((e$1) => w(e$1) && e$1 >= t$1))(e))),
|
|
198
|
+
int: () => N(d(t, p((t$1) => w(t$1) && Number.isInteger(t$1)))),
|
|
199
|
+
finite: () => N(d(t, p((t$1) => w(t$1) && Number.isFinite(t$1)))),
|
|
200
|
+
positive: () => N(d(t, p((t$1) => w(t$1) && t$1 > 0))),
|
|
201
|
+
negative: () => N(d(t, p((t$1) => w(t$1) && t$1 < 0)))
|
|
202
|
+
}), P = N(p(w)), k = (t) => Object.assign(a(t), {
|
|
203
|
+
between: (e, n) => k(d(t, ((t$1, e$1) => p((n$1) => j(n$1) && t$1 <= n$1 && e$1 >= n$1))(e, n))),
|
|
204
|
+
lt: (e) => k(d(t, ((t$1) => p((e$1) => j(e$1) && e$1 < t$1))(e))),
|
|
205
|
+
gt: (e) => k(d(t, ((t$1) => p((e$1) => j(e$1) && e$1 > t$1))(e))),
|
|
206
|
+
lte: (e) => k(d(t, ((t$1) => p((e$1) => j(e$1) && e$1 <= t$1))(e))),
|
|
207
|
+
gte: (e) => k(d(t, ((t$1) => p((e$1) => j(e$1) && e$1 >= t$1))(e))),
|
|
208
|
+
positive: () => k(d(t, p((t$1) => j(t$1) && t$1 > 0))),
|
|
209
|
+
negative: () => k(d(t, p((t$1) => j(t$1) && t$1 < 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$1) => {
|
|
223
|
+
r[t$1] = [];
|
|
224
|
+
}), {
|
|
225
|
+
matched: !0,
|
|
226
|
+
selections: r
|
|
227
|
+
};
|
|
228
|
+
const i = (t$1, e$1) => {
|
|
229
|
+
r[t$1] = (r[t$1] || []).concat([e$1]);
|
|
230
|
+
};
|
|
231
|
+
return {
|
|
232
|
+
matched: t.every((t$1) => o(n, t$1, 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$1, e$1) => {
|
|
250
|
+
n[t$1] = (n[t$1] || []).concat([e$1]);
|
|
251
|
+
}, i = e[0];
|
|
252
|
+
return {
|
|
253
|
+
matched: f(t, (t$1) => o(i, t$1, 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$1, e$1) => {
|
|
270
|
+
n[t$1] = (n[t$1] || []).concat([e$1]);
|
|
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$1, e$1) => {
|
|
278
|
+
const n$1 = o(s, e$1, r), i$1 = o(c, t$1, r);
|
|
279
|
+
return n$1 && i$1;
|
|
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$1, e$1) => {
|
|
295
|
+
r[t$1] = (r[t$1] || []).concat([e$1]);
|
|
296
|
+
}, [s, c] = 1 === e.length ? [A, e[0]] : e;
|
|
297
|
+
return {
|
|
298
|
+
matched: m(t, (t$1, e$1) => {
|
|
299
|
+
const n$1 = "string" != typeof t$1 || Number.isNaN(Number(t$1)) ? null : Number(t$1), r$1 = null !== n$1 && o(s, n$1, i), u = o(s, t$1, i), a = o(c, e$1, i);
|
|
300
|
+
return (u || r$1) && 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$1) {
|
|
339
|
+
return (e) => e instanceof t$1;
|
|
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$1, e$1) => {
|
|
375
|
+
s = !0, c[t$1] = e$1;
|
|
376
|
+
}, a = !r.some((t$1) => o(t$1, 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
|
+
//#region src/utils/type-is.ts
|
|
412
|
+
function isFlagSet(allFlags, flag) {
|
|
413
|
+
return (allFlags & flag) !== 0;
|
|
414
|
+
}
|
|
415
|
+
function isFlagSetOnObject(obj, flag) {
|
|
416
|
+
return isFlagSet(obj.flags, flag);
|
|
417
|
+
}
|
|
418
|
+
const isTypeFlagSet = isFlagSetOnObject;
|
|
419
|
+
function isBooleanLiteralType(type) {
|
|
420
|
+
return isTypeFlagSet(type, ts.TypeFlags.BooleanLiteral);
|
|
421
|
+
}
|
|
422
|
+
/** @internal */
|
|
423
|
+
const isFalseLiteralType = (type) => isBooleanLiteralType(type) && type.intrinsicName === "false";
|
|
424
|
+
/** @internal */
|
|
425
|
+
const isTrueLiteralType = (type) => isBooleanLiteralType(type) && type.intrinsicName === "true";
|
|
426
|
+
/** @internal */
|
|
427
|
+
const isAnyType = (type) => isTypeFlagSet(type, ts.TypeFlags.TypeParameter | ts.TypeFlags.Any);
|
|
428
|
+
/** @internal */
|
|
429
|
+
const isBigIntType = (type) => isTypeFlagSet(type, ts.TypeFlags.BigIntLike);
|
|
430
|
+
/** @internal */
|
|
431
|
+
const isBooleanType = (type) => isTypeFlagSet(type, ts.TypeFlags.BooleanLike);
|
|
432
|
+
/** @internal */
|
|
433
|
+
const isEnumType = (type) => isTypeFlagSet(type, ts.TypeFlags.EnumLike);
|
|
434
|
+
/** @internal */
|
|
435
|
+
const isFalsyBigIntType = (type) => type.isLiteral() && u({ value: { base10Value: "0" } }, type);
|
|
436
|
+
/** @internal */
|
|
437
|
+
const isFalsyNumberType = (type) => type.isNumberLiteral() && type.value === 0;
|
|
438
|
+
/** @internal */
|
|
439
|
+
const isFalsyStringType = (type) => type.isStringLiteral() && type.value === "";
|
|
440
|
+
/** @internal */
|
|
441
|
+
const isNeverType = (type) => isTypeFlagSet(type, ts.TypeFlags.Never);
|
|
442
|
+
/** @internal */
|
|
443
|
+
const isNullishType = (type) => isTypeFlagSet(type, ts.TypeFlags.Null | ts.TypeFlags.Undefined | ts.TypeFlags.VoidLike);
|
|
444
|
+
/** @internal */
|
|
445
|
+
const isNumberType = (type) => isTypeFlagSet(type, ts.TypeFlags.NumberLike);
|
|
446
|
+
/** @internal */
|
|
447
|
+
const isObjectType = (type) => !isTypeFlagSet(type, ts.TypeFlags.Null | ts.TypeFlags.Undefined | ts.TypeFlags.VoidLike | ts.TypeFlags.BooleanLike | ts.TypeFlags.StringLike | ts.TypeFlags.NumberLike | ts.TypeFlags.BigIntLike | ts.TypeFlags.TypeParameter | ts.TypeFlags.Any | ts.TypeFlags.Unknown | ts.TypeFlags.Never);
|
|
448
|
+
/** @internal */
|
|
449
|
+
const isStringType = (type) => isTypeFlagSet(type, ts.TypeFlags.StringLike);
|
|
450
|
+
/** @internal */
|
|
451
|
+
const isTruthyBigIntType = (type) => type.isLiteral() && u({ value: { base10Value: z.not("0") } }, type);
|
|
452
|
+
/** @internal */
|
|
453
|
+
const isTruthyNumberType = (type) => type.isNumberLiteral() && type.value !== 0;
|
|
454
|
+
/** @internal */
|
|
455
|
+
const isTruthyStringType = (type) => type.isStringLiteral() && type.value !== "";
|
|
456
|
+
/** @internal */
|
|
457
|
+
const isUnknownType = (type) => isTypeFlagSet(type, ts.TypeFlags.Unknown);
|
|
458
|
+
|
|
459
|
+
//#endregion
|
|
460
|
+
//#region src/utils/type-variant.ts
|
|
461
|
+
/**
|
|
462
|
+
* Ported from https://github.com/typescript-eslint/typescript-eslint/blob/eb736bbfc22554694400e6a4f97051d845d32e0b/packages/eslint-plugin/src/rules/strict-boolean-expressions.ts#L826 with some enhancements
|
|
463
|
+
* Get the variants of an array of types.
|
|
464
|
+
* @param types The types to get the variants of
|
|
465
|
+
* @returns The variants of the types
|
|
466
|
+
* @internal
|
|
467
|
+
*/
|
|
468
|
+
function getTypeVariants(types) {
|
|
469
|
+
const variants = /* @__PURE__ */ new Set();
|
|
470
|
+
if (types.some(isUnknownType)) {
|
|
471
|
+
variants.add("unknown");
|
|
472
|
+
return variants;
|
|
473
|
+
}
|
|
474
|
+
if (types.some(isNullishType)) variants.add("nullish");
|
|
475
|
+
const booleans = types.filter(isBooleanType);
|
|
476
|
+
const boolean0 = booleans[0];
|
|
477
|
+
if (booleans.length === 1 && boolean0 != null) {
|
|
478
|
+
if (isFalseLiteralType(boolean0)) variants.add("falsy boolean");
|
|
479
|
+
else if (isTrueLiteralType(boolean0)) variants.add("truthy boolean");
|
|
480
|
+
} else if (booleans.length === 2) variants.add("boolean");
|
|
481
|
+
const strings = types.filter(isStringType);
|
|
482
|
+
if (strings.length > 0) {
|
|
483
|
+
const evaluated = M(strings).when((types$1) => types$1.every(isTruthyStringType), () => "truthy string").when((types$1) => types$1.every(isFalsyStringType), () => "falsy string").otherwise(() => "string");
|
|
484
|
+
variants.add(evaluated);
|
|
485
|
+
}
|
|
486
|
+
const bigints = types.filter(isBigIntType);
|
|
487
|
+
if (bigints.length > 0) {
|
|
488
|
+
const evaluated = M(bigints).when((types$1) => types$1.every(isTruthyBigIntType), () => "truthy bigint").when((types$1) => types$1.every(isFalsyBigIntType), () => "falsy bigint").otherwise(() => "bigint");
|
|
489
|
+
variants.add(evaluated);
|
|
490
|
+
}
|
|
491
|
+
const numbers = types.filter(isNumberType);
|
|
492
|
+
if (numbers.length > 0) {
|
|
493
|
+
const evaluated = M(numbers).when((types$1) => types$1.every(isTruthyNumberType), () => "truthy number").when((types$1) => types$1.every(isFalsyNumberType), () => "falsy number").otherwise(() => "number");
|
|
494
|
+
variants.add(evaluated);
|
|
495
|
+
}
|
|
496
|
+
if (types.some(isEnumType)) variants.add("enum");
|
|
497
|
+
if (types.some(isObjectType)) variants.add("object");
|
|
498
|
+
if (types.some(isAnyType)) variants.add("any");
|
|
499
|
+
if (types.some(isNeverType)) variants.add("never");
|
|
500
|
+
return variants;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
//#endregion
|
|
9
504
|
//#region src/rules/no-leaked-conditional-rendering.ts
|
|
10
505
|
/** @internal */
|
|
11
|
-
const messages = { noLeakedConditionalRendering: (p) => `Potential leaked value ${p.value} that might cause unintentionally rendered values or rendering crashes.` };
|
|
506
|
+
const messages = { noLeakedConditionalRendering: (p$1) => `Potential leaked value ${p$1.value} that might cause unintentionally rendered values or rendering crashes.` };
|
|
12
507
|
/**
|
|
13
508
|
* Prevents problematic leaked values from being rendered.
|
|
14
509
|
*
|
|
@@ -68,6 +563,7 @@ const noLeakedConditionalRendering = defineRule(() => {
|
|
|
68
563
|
const state = { isWithinJsxExpression: false };
|
|
69
564
|
const allowedVariants = [
|
|
70
565
|
"any",
|
|
566
|
+
"enum",
|
|
71
567
|
"boolean",
|
|
72
568
|
"nullish",
|
|
73
569
|
"object",
|
|
@@ -81,7 +577,7 @@ const noLeakedConditionalRendering = defineRule(() => {
|
|
|
81
577
|
function getReportDescriptor(node) {
|
|
82
578
|
if (isLogicalNegationExpression(node.left)) return unit;
|
|
83
579
|
const leftType = ctx.utils.getConstrainedTypeAtLocation(node.left);
|
|
84
|
-
const leftTypeVariants =
|
|
580
|
+
const leftTypeVariants = getTypeVariants(ctx.utils.unionConstituents(leftType));
|
|
85
581
|
if (!Array.from(leftTypeVariants.values()).every((type) => allowedVariants.some((allowed) => allowed === type))) return {
|
|
86
582
|
node: node.left,
|
|
87
583
|
message: messages.noLeakedConditionalRendering({ value: node.left.getText() })
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tsl-react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "A unified plugin that combines all individual plugins from the react-analyzer monorepo into one.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -29,16 +29,16 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@let/eff": "npm:@jsr/let__eff@^0.1.2",
|
|
31
31
|
"compare-versions": "^6.1.1",
|
|
32
|
-
"@react-analyzer/ast": "0.0.
|
|
33
|
-
"@react-analyzer/
|
|
34
|
-
"@react-analyzer/
|
|
32
|
+
"@react-analyzer/ast": "0.0.8",
|
|
33
|
+
"@react-analyzer/shared": "0.0.8",
|
|
34
|
+
"@react-analyzer/core": "0.0.8"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"tsdown": "^0.
|
|
37
|
+
"tsdown": "^0.20.0-beta.4",
|
|
38
38
|
"@local/configs": "0.0.0"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"tsl": "^1.0.
|
|
41
|
+
"tsl": "^1.0.28",
|
|
42
42
|
"typescript": "^4.9.5 || ^5.4.5"
|
|
43
43
|
},
|
|
44
44
|
"engines": {
|