@eslint-react/ast 5.24.0 → 5.24.2
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.js +29 -499
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -10,7 +10,7 @@ var check_exports = /* @__PURE__ */ __exportAll({
|
|
|
10
10
|
isConditional: () => isConditional,
|
|
11
11
|
isDirective: () => isDirective,
|
|
12
12
|
isExpression: () => isExpression,
|
|
13
|
-
isFunction: () => isFunction,
|
|
13
|
+
isFunction: () => isFunction$1,
|
|
14
14
|
isIdentifier: () => isIdentifier,
|
|
15
15
|
isJSX: () => isJSX,
|
|
16
16
|
isJSXElement: () => isJSXElement,
|
|
@@ -28,70 +28,41 @@ var check_exports = /* @__PURE__ */ __exportAll({
|
|
|
28
28
|
isTypeAssertionExpression: () => isTypeAssertionExpression,
|
|
29
29
|
isTypeExpression: () => isTypeExpression
|
|
30
30
|
});
|
|
31
|
-
/** Check if a node is of the given type. */
|
|
32
31
|
const is = ASTUtils.isNodeOfType;
|
|
33
|
-
/** Check if a node is one of the given types. */
|
|
34
32
|
const isOneOf = ASTUtils.isNodeOfTypes;
|
|
35
|
-
/**
|
|
36
|
-
* Check if a node is a directive statement (ex: `"use client"`), optionally matching a specific directive name.
|
|
37
|
-
* @param node The node to check.
|
|
38
|
-
* @param name The directive name to match. When omitted, any directive matches.
|
|
39
|
-
* @returns `true` if the node is a matching directive statement.
|
|
40
|
-
*/
|
|
41
33
|
function isDirective(node, name) {
|
|
42
34
|
return node.type === AST_NODE_TYPES.ExpressionStatement && (name == null || node.directive === name);
|
|
43
35
|
}
|
|
44
|
-
/**
|
|
45
|
-
* Check if a node is an identifier, optionally matching a specific name.
|
|
46
|
-
* @param node The node to check.
|
|
47
|
-
* @param name The identifier name to match. When omitted, any identifier matches.
|
|
48
|
-
* @returns `true` if the node is a matching identifier.
|
|
49
|
-
*/
|
|
50
36
|
function isIdentifier(node, name) {
|
|
51
37
|
return node.type === AST_NODE_TYPES.Identifier && (name == null || node.name === name);
|
|
52
38
|
}
|
|
53
|
-
/** Check if a node is a call expression. */
|
|
54
39
|
const isCallExpression = is(AST_NODE_TYPES.CallExpression);
|
|
55
|
-
/** Check if a node is a member expression. */
|
|
56
40
|
const isMemberExpression = is(AST_NODE_TYPES.MemberExpression);
|
|
57
|
-
/** Check if a node is an object expression. */
|
|
58
41
|
const isObjectExpression = is(AST_NODE_TYPES.ObjectExpression);
|
|
59
|
-
/** Check if a node is a return statement. */
|
|
60
42
|
const isReturnStatement = is(AST_NODE_TYPES.ReturnStatement);
|
|
61
|
-
/** Check if a node is a class declaration or class expression. */
|
|
62
43
|
const isClass = isOneOf([AST_NODE_TYPES.ClassDeclaration, AST_NODE_TYPES.ClassExpression]);
|
|
63
|
-
|
|
64
|
-
const isFunction = isOneOf([
|
|
44
|
+
const isFunction$1 = isOneOf([
|
|
65
45
|
AST_NODE_TYPES.ArrowFunctionExpression,
|
|
66
46
|
AST_NODE_TYPES.FunctionDeclaration,
|
|
67
47
|
AST_NODE_TYPES.FunctionExpression
|
|
68
48
|
]);
|
|
69
|
-
/** Check if a node is a property-like node (property definition, index signature, parameter property, or property signature). */
|
|
70
49
|
const isProperty = isOneOf([
|
|
71
50
|
AST_NODE_TYPES.PropertyDefinition,
|
|
72
51
|
AST_NODE_TYPES.TSIndexSignature,
|
|
73
52
|
AST_NODE_TYPES.TSParameterProperty,
|
|
74
53
|
AST_NODE_TYPES.TSPropertySignature
|
|
75
54
|
]);
|
|
76
|
-
/** Check if a node is a property or method definition. */
|
|
77
55
|
const isPropertyOrMethod = isOneOf([AST_NODE_TYPES.PropertyDefinition, AST_NODE_TYPES.MethodDefinition]);
|
|
78
|
-
/** Check if a node is a JSX element. */
|
|
79
56
|
const isJSXElement = is(AST_NODE_TYPES.JSXElement);
|
|
80
|
-
/** Check if a node is a JSX expression container. */
|
|
81
57
|
const isJSXExpressionContainer = is(AST_NODE_TYPES.JSXExpressionContainer);
|
|
82
|
-
/** Check if a node is a JSX spread attribute. */
|
|
83
58
|
const isJSXSpreadAttribute = is(AST_NODE_TYPES.JSXSpreadAttribute);
|
|
84
|
-
/** Check if a node is a JSX fragment. */
|
|
85
59
|
const isJSXFragment = is(AST_NODE_TYPES.JSXFragment);
|
|
86
|
-
/** Check if a node is a JSX element or JSX fragment. */
|
|
87
60
|
const isJSXElementOrFragment = isOneOf([AST_NODE_TYPES.JSXElement, AST_NODE_TYPES.JSXFragment]);
|
|
88
|
-
/** Check if a node can appear as a JSX tag name. */
|
|
89
61
|
const isJSXTagNameExpression = isOneOf([
|
|
90
62
|
AST_NODE_TYPES.JSXIdentifier,
|
|
91
63
|
AST_NODE_TYPES.JSXMemberExpression,
|
|
92
64
|
AST_NODE_TYPES.JSXNamespacedName
|
|
93
65
|
]);
|
|
94
|
-
/** Check if a node is any JSX-related node. */
|
|
95
66
|
const isJSX = isOneOf([
|
|
96
67
|
AST_NODE_TYPES.JSXAttribute,
|
|
97
68
|
AST_NODE_TYPES.JSXClosingElement,
|
|
@@ -109,7 +80,6 @@ const isJSX = isOneOf([
|
|
|
109
80
|
AST_NODE_TYPES.JSXSpreadChild,
|
|
110
81
|
AST_NODE_TYPES.JSXText
|
|
111
82
|
]);
|
|
112
|
-
/** Check if a node is a TypeScript type expression (assertion, non-null, satisfies, or instantiation). */
|
|
113
83
|
const isTypeExpression = isOneOf([
|
|
114
84
|
AST_NODE_TYPES.TSAsExpression,
|
|
115
85
|
AST_NODE_TYPES.TSTypeAssertion,
|
|
@@ -117,14 +87,12 @@ const isTypeExpression = isOneOf([
|
|
|
117
87
|
AST_NODE_TYPES.TSSatisfiesExpression,
|
|
118
88
|
AST_NODE_TYPES.TSInstantiationExpression
|
|
119
89
|
]);
|
|
120
|
-
/** Check if a node is a TypeScript type assertion-like expression (as, assertion, non-null, or satisfies). */
|
|
121
90
|
const isTypeAssertionExpression = isOneOf([
|
|
122
91
|
AST_NODE_TYPES.TSAsExpression,
|
|
123
92
|
AST_NODE_TYPES.TSTypeAssertion,
|
|
124
93
|
AST_NODE_TYPES.TSNonNullExpression,
|
|
125
94
|
AST_NODE_TYPES.TSSatisfiesExpression
|
|
126
95
|
]);
|
|
127
|
-
/** Check if a node is an expression node. */
|
|
128
96
|
const isExpression = isOneOf([
|
|
129
97
|
AST_NODE_TYPES.ArrayExpression,
|
|
130
98
|
AST_NODE_TYPES.ArrayPattern,
|
|
@@ -162,7 +130,6 @@ const isExpression = isOneOf([
|
|
|
162
130
|
AST_NODE_TYPES.UpdateExpression,
|
|
163
131
|
AST_NODE_TYPES.YieldExpression
|
|
164
132
|
]);
|
|
165
|
-
/** Check if a node is a conditional expression or a control flow statement. */
|
|
166
133
|
const isConditional = isOneOf([
|
|
167
134
|
AST_NODE_TYPES.DoWhileStatement,
|
|
168
135
|
AST_NODE_TYPES.ForInStatement,
|
|
@@ -177,54 +144,6 @@ const isConditional = isOneOf([
|
|
|
177
144
|
|
|
178
145
|
//#endregion
|
|
179
146
|
//#region ../../.pkgs/eff/dist/index.js
|
|
180
|
-
/**
|
|
181
|
-
* A function that checks if the passed parameter is a string and narrows its type accordingly.
|
|
182
|
-
*
|
|
183
|
-
* @param data - The variable to check.
|
|
184
|
-
* @returns True if the passed input is a string, false otherwise.
|
|
185
|
-
* @category guards
|
|
186
|
-
*/
|
|
187
|
-
function isString(data) {
|
|
188
|
-
return typeof data === "string";
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* Applies a `pipe` method's variadic arguments to an initial value from left
|
|
192
|
-
* to right.
|
|
193
|
-
*
|
|
194
|
-
* **When to use**
|
|
195
|
-
*
|
|
196
|
-
* Use to implement a custom `.pipe(...)` method from JavaScript's `arguments`
|
|
197
|
-
* object.
|
|
198
|
-
*
|
|
199
|
-
* **Details**
|
|
200
|
-
*
|
|
201
|
-
* This helper is intended for implementing `Pipeable.pipe` methods that
|
|
202
|
-
* receive JavaScript's `arguments` object. With no functions it returns the
|
|
203
|
-
* original value; otherwise it feeds each result into the next function.
|
|
204
|
-
*
|
|
205
|
-
* **Example** (Implementing a pipe method)
|
|
206
|
-
*
|
|
207
|
-
* ```ts
|
|
208
|
-
* import { Pipeable } from "effect"
|
|
209
|
-
*
|
|
210
|
-
* class NumberBox {
|
|
211
|
-
* constructor(readonly value: number) {}
|
|
212
|
-
*
|
|
213
|
-
* pipe(..._fns: ReadonlyArray<(value: number) => number>): number {
|
|
214
|
-
* return Pipeable.pipeArguments(this.value, arguments) as number
|
|
215
|
-
* }
|
|
216
|
-
* }
|
|
217
|
-
*
|
|
218
|
-
* const result = new NumberBox(5).pipe(
|
|
219
|
-
* (n) => n + 2,
|
|
220
|
-
* (n) => n * 3
|
|
221
|
-
* )
|
|
222
|
-
* console.log(result) // 21
|
|
223
|
-
* ```
|
|
224
|
-
*
|
|
225
|
-
* @category combinators
|
|
226
|
-
* @since 2.0.0
|
|
227
|
-
*/
|
|
228
147
|
const pipeArguments = (self, args) => {
|
|
229
148
|
switch (args.length) {
|
|
230
149
|
case 0: return self;
|
|
@@ -244,110 +163,14 @@ const pipeArguments = (self, args) => {
|
|
|
244
163
|
}
|
|
245
164
|
}
|
|
246
165
|
};
|
|
247
|
-
/**
|
|
248
|
-
* Reusable prototype that implements `Pipeable.pipe`.
|
|
249
|
-
*
|
|
250
|
-
* **When to use**
|
|
251
|
-
*
|
|
252
|
-
* Use when classes or object prototypes can reuse this value when they need the
|
|
253
|
-
* standard pipe implementation backed by `pipeArguments`.
|
|
254
|
-
*
|
|
255
|
-
* @category prototypes
|
|
256
|
-
* @since 3.15.0
|
|
257
|
-
*/
|
|
258
166
|
const Prototype = { pipe() {
|
|
259
167
|
return pipeArguments(this, arguments);
|
|
260
168
|
} };
|
|
261
|
-
/**
|
|
262
|
-
* Provides a base constructor whose instances implement the standard `Pipeable.pipe`
|
|
263
|
-
* method.
|
|
264
|
-
*
|
|
265
|
-
* **When to use**
|
|
266
|
-
*
|
|
267
|
-
* Use when you need to define a class that supports Effect-style method
|
|
268
|
-
* chaining through `.pipe(...)`.
|
|
269
|
-
*
|
|
270
|
-
* @category constructors
|
|
271
|
-
* @since 3.15.0
|
|
272
|
-
*/
|
|
273
169
|
const Class = (function() {
|
|
274
170
|
function PipeableBase() {}
|
|
275
171
|
PipeableBase.prototype = Prototype;
|
|
276
172
|
return PipeableBase;
|
|
277
173
|
})();
|
|
278
|
-
/**
|
|
279
|
-
* Provides small helpers for defining and reusing TypeScript functions.
|
|
280
|
-
*
|
|
281
|
-
* The main helpers are `pipe` and `flow` for left-to-right composition and
|
|
282
|
-
* `dual` for APIs that support both direct and pipe-friendly call styles. The
|
|
283
|
-
* module also contains small identity, constant, tuple, type-level, and
|
|
284
|
-
* memoization helpers used across the library.
|
|
285
|
-
*
|
|
286
|
-
* @since 2.0.0
|
|
287
|
-
*/
|
|
288
|
-
/**
|
|
289
|
-
* Creates a function that can be called in data-first style or data-last
|
|
290
|
-
* (`pipe`-friendly) style.
|
|
291
|
-
*
|
|
292
|
-
* **When to use**
|
|
293
|
-
*
|
|
294
|
-
* Use to expose one implementation through both direct and `pipe`-friendly
|
|
295
|
-
* call styles.
|
|
296
|
-
*
|
|
297
|
-
* **Details**
|
|
298
|
-
*
|
|
299
|
-
* Pass either the arity of the uncurried function or a predicate that decides
|
|
300
|
-
* whether the current call is data-first. Arity is the common case. Use a
|
|
301
|
-
* predicate when optional arguments make arity ambiguous.
|
|
302
|
-
*
|
|
303
|
-
* **Example** (Selecting data-first or data-last style by arity)
|
|
304
|
-
*
|
|
305
|
-
* ```ts
|
|
306
|
-
* import { Function, pipe } from "effect"
|
|
307
|
-
*
|
|
308
|
-
* const sum = Function.dual<
|
|
309
|
-
* (that: number) => (self: number) => number,
|
|
310
|
-
* (self: number, that: number) => number
|
|
311
|
-
* >(2, (self, that) => self + that)
|
|
312
|
-
*
|
|
313
|
-
* console.log(sum(2, 3)) // 5
|
|
314
|
-
* console.log(pipe(2, sum(3))) // 5
|
|
315
|
-
* ```
|
|
316
|
-
*
|
|
317
|
-
* **Example** (Defining overloads with call signatures)
|
|
318
|
-
*
|
|
319
|
-
* ```ts
|
|
320
|
-
* import { Function, pipe } from "effect"
|
|
321
|
-
*
|
|
322
|
-
* const sum: {
|
|
323
|
-
* (that: number): (self: number) => number
|
|
324
|
-
* (self: number, that: number): number
|
|
325
|
-
* } = Function.dual(2, (self: number, that: number): number => self + that)
|
|
326
|
-
*
|
|
327
|
-
* console.log(sum(2, 3)) // 5
|
|
328
|
-
* console.log(pipe(2, sum(3))) // 5
|
|
329
|
-
* ```
|
|
330
|
-
*
|
|
331
|
-
* **Example** (Selecting data-first or data-last style with a predicate)
|
|
332
|
-
*
|
|
333
|
-
* ```ts
|
|
334
|
-
* import { Function, pipe } from "effect"
|
|
335
|
-
*
|
|
336
|
-
* const sum = Function.dual<
|
|
337
|
-
* (that: number) => (self: number) => number,
|
|
338
|
-
* (self: number, that: number) => number
|
|
339
|
-
* >(
|
|
340
|
-
* (args) => args.length === 2,
|
|
341
|
-
* (self, that) => self + that
|
|
342
|
-
* )
|
|
343
|
-
*
|
|
344
|
-
* console.log(sum(2, 3)) // 5
|
|
345
|
-
* console.log(pipe(2, sum(3))) // 5
|
|
346
|
-
* ```
|
|
347
|
-
*
|
|
348
|
-
* @category combinators
|
|
349
|
-
* @since 2.0.0
|
|
350
|
-
*/
|
|
351
174
|
const dual = function(arity, body) {
|
|
352
175
|
if (typeof arity === "function") return function() {
|
|
353
176
|
return arity(arguments) ? body.apply(this, arguments) : ((self) => body(self, ...arguments));
|
|
@@ -376,287 +199,48 @@ const dual = function(arity, body) {
|
|
|
376
199
|
};
|
|
377
200
|
}
|
|
378
201
|
};
|
|
379
|
-
/**
|
|
380
|
-
* Returns its input argument unchanged.
|
|
381
|
-
*
|
|
382
|
-
* **When to use**
|
|
383
|
-
*
|
|
384
|
-
* Use to return a value unchanged where a function is required.
|
|
385
|
-
*
|
|
386
|
-
* **Example** (Returning the same value)
|
|
387
|
-
*
|
|
388
|
-
* ```ts
|
|
389
|
-
* import { identity } from "effect"
|
|
390
|
-
* import * as assert from "node:assert"
|
|
391
|
-
*
|
|
392
|
-
* assert.deepStrictEqual(identity(5), 5)
|
|
393
|
-
* ```
|
|
394
|
-
*
|
|
395
|
-
* @category combinators
|
|
396
|
-
* @since 2.0.0
|
|
397
|
-
*/
|
|
398
202
|
const identity = (a) => a;
|
|
399
|
-
/**
|
|
400
|
-
* Returns the input value with a different static type.
|
|
401
|
-
*
|
|
402
|
-
* **When to use**
|
|
403
|
-
*
|
|
404
|
-
* Use when you need an explicit type-level cast and accept that the value is
|
|
405
|
-
* returned unchanged at runtime.
|
|
406
|
-
*
|
|
407
|
-
* **Gotchas**
|
|
408
|
-
*
|
|
409
|
-
* This is a type-level cast only; it performs no runtime validation or
|
|
410
|
-
* conversion.
|
|
411
|
-
*
|
|
412
|
-
* @see {@link satisfies} for checking assignability without changing the resulting type
|
|
413
|
-
*
|
|
414
|
-
* @category utility types
|
|
415
|
-
* @since 4.0.0
|
|
416
|
-
*/
|
|
417
203
|
const cast = identity;
|
|
418
|
-
/**
|
|
419
|
-
* Creates a zero-argument function that always returns the provided value.
|
|
420
|
-
*
|
|
421
|
-
* **When to use**
|
|
422
|
-
*
|
|
423
|
-
* Use when you need a thunk or callback that returns the same value on every
|
|
424
|
-
* invocation.
|
|
425
|
-
*
|
|
426
|
-
* **Example** (Creating a constant thunk)
|
|
427
|
-
*
|
|
428
|
-
* ```ts
|
|
429
|
-
* import { Function } from "effect"
|
|
430
|
-
* import * as assert from "node:assert"
|
|
431
|
-
*
|
|
432
|
-
* const constNull = Function.constant(null)
|
|
433
|
-
*
|
|
434
|
-
* assert.deepStrictEqual(constNull(), null)
|
|
435
|
-
* assert.deepStrictEqual(constNull(), null)
|
|
436
|
-
* ```
|
|
437
|
-
*
|
|
438
|
-
* @category constructors
|
|
439
|
-
* @since 2.0.0
|
|
440
|
-
*/
|
|
441
204
|
const constant = (value) => () => value;
|
|
442
|
-
/**
|
|
443
|
-
* Returns `true` when called.
|
|
444
|
-
*
|
|
445
|
-
* **When to use**
|
|
446
|
-
*
|
|
447
|
-
* Use when you need a thunk that returns `true` on every invocation.
|
|
448
|
-
*
|
|
449
|
-
* **Example** (Returning true from a thunk)
|
|
450
|
-
*
|
|
451
|
-
* ```ts
|
|
452
|
-
* import { Function } from "effect"
|
|
453
|
-
* import * as assert from "node:assert"
|
|
454
|
-
*
|
|
455
|
-
* assert.deepStrictEqual(Function.constTrue(), true)
|
|
456
|
-
* ```
|
|
457
|
-
*
|
|
458
|
-
* @category constants
|
|
459
|
-
* @since 2.0.0
|
|
460
|
-
*/
|
|
461
205
|
const constTrue = constant(true);
|
|
462
|
-
/**
|
|
463
|
-
* Returns `false` when called.
|
|
464
|
-
*
|
|
465
|
-
* **When to use**
|
|
466
|
-
*
|
|
467
|
-
* Use when you need a thunk that returns `false` on every invocation.
|
|
468
|
-
*
|
|
469
|
-
* **Example** (Returning false from a thunk)
|
|
470
|
-
*
|
|
471
|
-
* ```ts
|
|
472
|
-
* import { Function } from "effect"
|
|
473
|
-
* import * as assert from "node:assert"
|
|
474
|
-
*
|
|
475
|
-
* assert.deepStrictEqual(Function.constFalse(), false)
|
|
476
|
-
* ```
|
|
477
|
-
*
|
|
478
|
-
* @category constants
|
|
479
|
-
* @since 2.0.0
|
|
480
|
-
*/
|
|
481
206
|
const constFalse = constant(false);
|
|
482
|
-
/**
|
|
483
|
-
* Returns `null` when called.
|
|
484
|
-
*
|
|
485
|
-
* **When to use**
|
|
486
|
-
*
|
|
487
|
-
* Use when you need a thunk that returns `null` on every invocation.
|
|
488
|
-
*
|
|
489
|
-
* **Example** (Returning null from a thunk)
|
|
490
|
-
*
|
|
491
|
-
* ```ts
|
|
492
|
-
* import { Function } from "effect"
|
|
493
|
-
* import * as assert from "node:assert"
|
|
494
|
-
*
|
|
495
|
-
* assert.deepStrictEqual(Function.constNull(), null)
|
|
496
|
-
* ```
|
|
497
|
-
*
|
|
498
|
-
* @category constants
|
|
499
|
-
* @since 2.0.0
|
|
500
|
-
*/
|
|
501
207
|
const constNull = constant(null);
|
|
502
|
-
/**
|
|
503
|
-
* Returns `undefined` when called.
|
|
504
|
-
*
|
|
505
|
-
* **When to use**
|
|
506
|
-
*
|
|
507
|
-
* Use when you need a thunk that returns `undefined` on every invocation.
|
|
508
|
-
*
|
|
509
|
-
* **Example** (Returning undefined from a thunk)
|
|
510
|
-
*
|
|
511
|
-
* ```ts
|
|
512
|
-
* import { Function } from "effect"
|
|
513
|
-
* import * as assert from "node:assert"
|
|
514
|
-
*
|
|
515
|
-
* assert.deepStrictEqual(Function.constUndefined(), undefined)
|
|
516
|
-
* ```
|
|
517
|
-
*
|
|
518
|
-
* @category constants
|
|
519
|
-
* @since 2.0.0
|
|
520
|
-
*/
|
|
521
208
|
const constUndefined = constant(void 0);
|
|
522
|
-
/**
|
|
523
|
-
* Composes two functions, `ab` and `bc` into a single function that takes in an argument `a` of type `A` and returns a result of type `C`.
|
|
524
|
-
* The result is obtained by first applying the `ab` function to `a` and then applying the `bc` function to the result of `ab`.
|
|
525
|
-
*
|
|
526
|
-
* **When to use**
|
|
527
|
-
*
|
|
528
|
-
* Use to compose exactly two unary functions into a reusable unary function.
|
|
529
|
-
*
|
|
530
|
-
* **Example** (Composing two functions)
|
|
531
|
-
*
|
|
532
|
-
* ```ts
|
|
533
|
-
* import { Function } from "effect"
|
|
534
|
-
* import * as assert from "node:assert"
|
|
535
|
-
*
|
|
536
|
-
* const increment = (n: number) => n + 1
|
|
537
|
-
* const square = (n: number) => n * n
|
|
538
|
-
*
|
|
539
|
-
* assert.strictEqual(Function.compose(increment, square)(2), 9)
|
|
540
|
-
* ```
|
|
541
|
-
*
|
|
542
|
-
* @see {@link flow} for composing a left-to-right sequence of functions
|
|
543
|
-
* @see {@link pipe} for applying a value through a left-to-right sequence immediately
|
|
544
|
-
*
|
|
545
|
-
* @category combinators
|
|
546
|
-
* @since 2.0.0
|
|
547
|
-
*/
|
|
548
209
|
const compose = dual(2, (ab, bc) => (a) => bc(ab(a)));
|
|
549
|
-
/**
|
|
550
|
-
* Marks an impossible branch by accepting a `never` value and returning any
|
|
551
|
-
* type.
|
|
552
|
-
*
|
|
553
|
-
* **When to use**
|
|
554
|
-
*
|
|
555
|
-
* Use when you need a return value in a branch that exhaustive checks prove
|
|
556
|
-
* cannot be reached.
|
|
557
|
-
*
|
|
558
|
-
* **Gotchas**
|
|
559
|
-
*
|
|
560
|
-
* Calling `absurd` throws, because a value of type `never` should be
|
|
561
|
-
* impossible at runtime.
|
|
562
|
-
*
|
|
563
|
-
* **Example** (Handling impossible values)
|
|
564
|
-
*
|
|
565
|
-
* ```ts
|
|
566
|
-
* import { absurd } from "effect"
|
|
567
|
-
*
|
|
568
|
-
* const handleNever = (value: never) => {
|
|
569
|
-
* return absurd(value) // This will throw an error if called
|
|
570
|
-
* }
|
|
571
|
-
* ```
|
|
572
|
-
*
|
|
573
|
-
* @category utility types
|
|
574
|
-
* @since 2.0.0
|
|
575
|
-
*/
|
|
576
210
|
const absurd = (_) => {
|
|
577
211
|
throw new Error("Called `absurd` function which should be uncallable");
|
|
578
212
|
};
|
|
579
|
-
/**
|
|
580
|
-
* Creates a compile-time placeholder for a value of any type.
|
|
581
|
-
*
|
|
582
|
-
* **When to use**
|
|
583
|
-
*
|
|
584
|
-
* Use as a temporary typed placeholder while developing incomplete code.
|
|
585
|
-
*
|
|
586
|
-
* **Gotchas**
|
|
587
|
-
*
|
|
588
|
-
* `hole` is intended for temporary development use. If the placeholder is
|
|
589
|
-
* evaluated at runtime, it throws.
|
|
590
|
-
*
|
|
591
|
-
* **Example** (Creating a development placeholder)
|
|
592
|
-
*
|
|
593
|
-
* ```ts
|
|
594
|
-
* import { hole } from "effect"
|
|
595
|
-
*
|
|
596
|
-
* // Intentionally not called: `hole` throws if the placeholder is evaluated.
|
|
597
|
-
* const buildUser = (id: number): { readonly id: number; readonly name: string } => ({
|
|
598
|
-
* id,
|
|
599
|
-
* name: hole<string>()
|
|
600
|
-
* })
|
|
601
|
-
*
|
|
602
|
-
* console.log(typeof buildUser) // "function"
|
|
603
|
-
* ```
|
|
604
|
-
*
|
|
605
|
-
* @category utility types
|
|
606
|
-
* @since 2.0.0
|
|
607
|
-
*/
|
|
608
213
|
const hole = cast(absurd);
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
const dropWhile = dual(2, (xs, pred) => {
|
|
630
|
-
const len = xs.length;
|
|
214
|
+
const and = dual(2, (a, b) => (data) => a(data) && b(data));
|
|
215
|
+
const or = dual(2, (a, b) => (data) => a(data) || b(data));
|
|
216
|
+
const xor = dual(2, (a, b) => (data) => a(data) !== b(data));
|
|
217
|
+
const eqv = dual(2, (a, b) => (data) => a(data) === b(data));
|
|
218
|
+
const implies = dual(2, (antecedent, consequent) => (data) => !antecedent(data) || consequent(data));
|
|
219
|
+
const nor = dual(2, (a, b) => (data) => !a(data) && !b(data));
|
|
220
|
+
const nand = dual(2, (a, b) => (data) => !a(data) || !b(data));
|
|
221
|
+
function isString(input) {
|
|
222
|
+
return typeof input === "string";
|
|
223
|
+
}
|
|
224
|
+
function isFunction(input) {
|
|
225
|
+
return typeof input === "function";
|
|
226
|
+
}
|
|
227
|
+
function isObjectKeyword(input) {
|
|
228
|
+
return typeof input === "object" && input !== null || isFunction(input);
|
|
229
|
+
}
|
|
230
|
+
const hasProperty = dual(2, (data, property) => isObjectKeyword(data) && property in data);
|
|
231
|
+
const dropWhile = dual(2, (self, predicate) => {
|
|
232
|
+
const input = Array.isArray(self) ? self : Array.from(self);
|
|
233
|
+
const len = input.length;
|
|
631
234
|
let idx = 0;
|
|
632
|
-
while (idx < len &&
|
|
633
|
-
return
|
|
235
|
+
while (idx < len && predicate(input[idx], idx)) idx++;
|
|
236
|
+
return input.slice(idx);
|
|
634
237
|
});
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
* Supports both data-first and data-last (`pipe`-friendly) call styles.
|
|
639
|
-
*
|
|
640
|
-
* @param pred - The predicate to test each element with.
|
|
641
|
-
* @returns A new array containing only the matching prefix.
|
|
642
|
-
* @example
|
|
643
|
-
* ```ts
|
|
644
|
-
* import * as assert from "node:assert"
|
|
645
|
-
* import { pipe, takeWhile } from "@local/eff"
|
|
646
|
-
*
|
|
647
|
-
* // data-first
|
|
648
|
-
* assert.deepStrictEqual(takeWhile([1, 2, 3, 2, 1], (n: number) => n < 3), [1, 2])
|
|
649
|
-
*
|
|
650
|
-
* // data-last
|
|
651
|
-
* assert.deepStrictEqual(pipe([1, 2, 3, 2, 1], takeWhile((n: number) => n < 3)), [1, 2])
|
|
652
|
-
* ```
|
|
653
|
-
* @category array
|
|
654
|
-
*/
|
|
655
|
-
const takeWhile = dual(2, (xs, pred) => {
|
|
656
|
-
const len = xs.length;
|
|
238
|
+
const takeWhile = dual(2, (self, predicate) => {
|
|
239
|
+
const input = Array.isArray(self) ? self : Array.from(self);
|
|
240
|
+
const len = input.length;
|
|
657
241
|
let idx = 0;
|
|
658
|
-
while (idx < len &&
|
|
659
|
-
return
|
|
242
|
+
while (idx < len && predicate(input[idx], idx)) idx++;
|
|
243
|
+
return input.slice(0, idx);
|
|
660
244
|
});
|
|
661
245
|
|
|
662
246
|
//#endregion
|
|
@@ -670,21 +254,10 @@ var extract_exports = /* @__PURE__ */ __exportAll({
|
|
|
670
254
|
getPropertyName: () => getPropertyName,
|
|
671
255
|
unwrap: () => unwrap
|
|
672
256
|
});
|
|
673
|
-
/**
|
|
674
|
-
* Recursively unwrap TypeScript type expressions and chain expressions to get the underlying expression.
|
|
675
|
-
* @param node The node to unwrap.
|
|
676
|
-
* @returns The innermost non-type-expression node.
|
|
677
|
-
*/
|
|
678
257
|
function unwrap(node) {
|
|
679
258
|
if (isTypeExpression(node) || node.type === AST_NODE_TYPES.ChainExpression) return unwrap(node.expression);
|
|
680
259
|
return node;
|
|
681
260
|
}
|
|
682
|
-
/**
|
|
683
|
-
* Find a property by name in a list of object literal properties, recursing into spread object expressions.
|
|
684
|
-
* @param properties The object literal properties to search.
|
|
685
|
-
* @param name The property name to look for.
|
|
686
|
-
* @returns The matching `Property` node, or `null` when not found.
|
|
687
|
-
*/
|
|
688
261
|
function findProperty(properties, name) {
|
|
689
262
|
for (const property of properties) {
|
|
690
263
|
if (property.type === AST_NODE_TYPES.Property && getPropertyName(property) === name) return property;
|
|
@@ -695,23 +268,12 @@ function findProperty(properties, name) {
|
|
|
695
268
|
}
|
|
696
269
|
return null;
|
|
697
270
|
}
|
|
698
|
-
/**
|
|
699
|
-
* Get the name of the callee of a call expression.
|
|
700
|
-
* @param node The call expression to inspect.
|
|
701
|
-
* @returns The callee name (ex: `"useState"`), or `null` when it cannot be statically determined.
|
|
702
|
-
*/
|
|
703
271
|
function getCalleeName(node) {
|
|
704
272
|
const callee = unwrap(node.callee);
|
|
705
273
|
if (isIdentifier(callee)) return callee.name;
|
|
706
274
|
if (callee.type === AST_NODE_TYPES.MemberExpression && !callee.computed && isIdentifier(callee.property)) return callee.property.name;
|
|
707
275
|
return null;
|
|
708
276
|
}
|
|
709
|
-
/**
|
|
710
|
-
* Get the member chain of an expression (ex: `[a, b, c]` for `a.b.c`), starting from the base object.
|
|
711
|
-
* Type expressions and chain expressions are unwrapped along the way.
|
|
712
|
-
* @param node The expression to inspect.
|
|
713
|
-
* @returns The base node followed by each member property in access order.
|
|
714
|
-
*/
|
|
715
277
|
function getMemberChain(node) {
|
|
716
278
|
const members = [];
|
|
717
279
|
let current = unwrap(node);
|
|
@@ -723,14 +285,6 @@ function getMemberChain(node) {
|
|
|
723
285
|
members.unshift(current);
|
|
724
286
|
return members;
|
|
725
287
|
}
|
|
726
|
-
/**
|
|
727
|
-
* Collect every write target of an assignment or loop target, expanding
|
|
728
|
-
* destructuring patterns such as `[local, globalValue] = source` or
|
|
729
|
-
* `({ a: obj.x } = source)`. Defaults (`{ a = source }`) are not targets;
|
|
730
|
-
* their left side is.
|
|
731
|
-
* @param node The assignment left side or for-in/of loop target to inspect.
|
|
732
|
-
* @returns The identifier and member expression targets being written.
|
|
733
|
-
*/
|
|
734
288
|
function getAssignmentTargets(node) {
|
|
735
289
|
const target = unwrap(node);
|
|
736
290
|
switch (target.type) {
|
|
@@ -746,12 +300,6 @@ function getAssignmentTargets(node) {
|
|
|
746
300
|
default: return [];
|
|
747
301
|
}
|
|
748
302
|
}
|
|
749
|
-
/**
|
|
750
|
-
* Get the static name of an object property's key.
|
|
751
|
-
* @param property The property to inspect.
|
|
752
|
-
* @param effort `"min"` only matches plain identifiers; `"max"` also resolves string literals and simple template literals.
|
|
753
|
-
* @returns The property name, or `null` when it cannot be statically determined.
|
|
754
|
-
*/
|
|
755
303
|
function getPropertyName(property, effort = "min") {
|
|
756
304
|
const key = unwrap(property.key);
|
|
757
305
|
if (isIdentifier(key) && !property.computed) return key.name;
|
|
@@ -760,12 +308,6 @@ function getPropertyName(property, effort = "min") {
|
|
|
760
308
|
if (key.type === AST_NODE_TYPES.TemplateLiteral && key.expressions.length === 0) return key.quasis[0]?.value.cooked ?? key.quasis[0]?.value.raw ?? null;
|
|
761
309
|
return null;
|
|
762
310
|
}
|
|
763
|
-
/**
|
|
764
|
-
* Get the fully qualified name of a node (ex: `React.useState`), falling back to source text when needed.
|
|
765
|
-
* @param node The node to inspect.
|
|
766
|
-
* @param getText A function returning the source text of a node.
|
|
767
|
-
* @returns The fully qualified name.
|
|
768
|
-
*/
|
|
769
311
|
function getFullyQualifiedName(node, getText) {
|
|
770
312
|
const expr = unwrap(node);
|
|
771
313
|
switch (expr.type) {
|
|
@@ -786,13 +328,6 @@ function getFullyQualifiedName(node, getText) {
|
|
|
786
328
|
//#endregion
|
|
787
329
|
//#region src/compare.ts
|
|
788
330
|
var compare_exports = /* @__PURE__ */ __exportAll({ isEqual: () => isEqual });
|
|
789
|
-
/**
|
|
790
|
-
* Check if two nodes are structurally equal.
|
|
791
|
-
* @param a The first node to compare.
|
|
792
|
-
* @param b The second node to compare.
|
|
793
|
-
* @returns `true` if the nodes are equal.
|
|
794
|
-
* @see https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/util/isNodeEqual.ts
|
|
795
|
-
*/
|
|
796
331
|
const isEqual = dual(2, (a, b) => {
|
|
797
332
|
a = isTypeExpression(a) ? unwrap(a) : a;
|
|
798
333
|
b = isTypeExpression(b) ? unwrap(b) : b;
|
|
@@ -859,11 +394,6 @@ function findParent(node, test, stop) {
|
|
|
859
394
|
}
|
|
860
395
|
return null;
|
|
861
396
|
}
|
|
862
|
-
/**
|
|
863
|
-
* Find the nearest `TryStatement` whose `try` block (not `catch`/`finally`) encloses the given node.
|
|
864
|
-
* @param node The node to check.
|
|
865
|
-
* @returns The enclosing `TryStatement`, or `null` when none is found.
|
|
866
|
-
*/
|
|
867
397
|
function findEnclosingTryBlock(node) {
|
|
868
398
|
const parent = node.parent;
|
|
869
399
|
if (parent == null || parent.type === AST_NODE_TYPES.Program) return null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/ast",
|
|
3
|
-
"version": "5.24.
|
|
3
|
+
"version": "5.24.2",
|
|
4
4
|
"description": "ESLint React's TSESTree AST utility module.",
|
|
5
5
|
"homepage": "https://github.com/Rel1cx/eslint-react",
|
|
6
6
|
"bugs": {
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"@local/configs": "0.0.0",
|
|
38
38
|
"@local/eff": "0.0.0",
|
|
39
39
|
"@local/testkit": "0.0.0",
|
|
40
|
-
"eslint": "^10.
|
|
40
|
+
"eslint": "^10.12.0",
|
|
41
41
|
"tsdown": "^0.23.0",
|
|
42
42
|
"typescript": "6.0.3",
|
|
43
43
|
"vitest": "^5.0.3"
|