@eslint-react/ast 5.24.0-beta.2 → 5.24.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +401 -78
  2. 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,
@@ -61,7 +61,7 @@ const isReturnStatement = is(AST_NODE_TYPES.ReturnStatement);
61
61
  /** Check if a node is a class declaration or class expression. */
62
62
  const isClass = isOneOf([AST_NODE_TYPES.ClassDeclaration, AST_NODE_TYPES.ClassExpression]);
63
63
  /** Check if a node is a function declaration, function expression, or arrow function expression. */
64
- const isFunction = isOneOf([
64
+ const isFunction$1 = isOneOf([
65
65
  AST_NODE_TYPES.ArrowFunctionExpression,
66
66
  AST_NODE_TYPES.FunctionDeclaration,
67
67
  AST_NODE_TYPES.FunctionExpression
@@ -178,16 +178,6 @@ const isConditional = isOneOf([
178
178
  //#endregion
179
179
  //#region ../../.pkgs/eff/dist/index.js
180
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
181
  * Applies a `pipe` method's variadic arguments to an initial value from left
192
182
  * to right.
193
183
  *
@@ -219,7 +209,7 @@ function isString(data) {
219
209
  * (n) => n + 2,
220
210
  * (n) => n * 3
221
211
  * )
222
- * console.log(result) // 21
212
+ * result // => 21
223
213
  * ```
224
214
  *
225
215
  * @category combinators
@@ -276,16 +266,6 @@ const Class = (function() {
276
266
  return PipeableBase;
277
267
  })();
278
268
  /**
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
269
  * Creates a function that can be called in data-first style or data-last
290
270
  * (`pipe`-friendly) style.
291
271
  *
@@ -310,8 +290,8 @@ const Class = (function() {
310
290
  * (self: number, that: number) => number
311
291
  * >(2, (self, that) => self + that)
312
292
  *
313
- * console.log(sum(2, 3)) // 5
314
- * console.log(pipe(2, sum(3))) // 5
293
+ * sum(2, 3) // => 5
294
+ * pipe(2, sum(3)) // => 5
315
295
  * ```
316
296
  *
317
297
  * **Example** (Defining overloads with call signatures)
@@ -324,8 +304,8 @@ const Class = (function() {
324
304
  * (self: number, that: number): number
325
305
  * } = Function.dual(2, (self: number, that: number): number => self + that)
326
306
  *
327
- * console.log(sum(2, 3)) // 5
328
- * console.log(pipe(2, sum(3))) // 5
307
+ * sum(2, 3) // => 5
308
+ * pipe(2, sum(3)) // => 5
329
309
  * ```
330
310
  *
331
311
  * **Example** (Selecting data-first or data-last style with a predicate)
@@ -341,8 +321,8 @@ const Class = (function() {
341
321
  * (self, that) => self + that
342
322
  * )
343
323
  *
344
- * console.log(sum(2, 3)) // 5
345
- * console.log(pipe(2, sum(3))) // 5
324
+ * sum(2, 3) // => 5
325
+ * pipe(2, sum(3)) // => 5
346
326
  * ```
347
327
  *
348
328
  * @category combinators
@@ -387,9 +367,8 @@ const dual = function(arity, body) {
387
367
  *
388
368
  * ```ts
389
369
  * import { identity } from "effect"
390
- * import * as assert from "node:assert"
391
370
  *
392
- * assert.deepStrictEqual(identity(5), 5)
371
+ * identity(5) // => 5
393
372
  * ```
394
373
  *
395
374
  * @category combinators
@@ -427,12 +406,11 @@ const cast = identity;
427
406
  *
428
407
  * ```ts
429
408
  * import { Function } from "effect"
430
- * import * as assert from "node:assert"
431
409
  *
432
410
  * const constNull = Function.constant(null)
433
411
  *
434
- * assert.deepStrictEqual(constNull(), null)
435
- * assert.deepStrictEqual(constNull(), null)
412
+ * constNull() // => null
413
+ * constNull() // => null
436
414
  * ```
437
415
  *
438
416
  * @category constructors
@@ -450,9 +428,8 @@ const constant = (value) => () => value;
450
428
  *
451
429
  * ```ts
452
430
  * import { Function } from "effect"
453
- * import * as assert from "node:assert"
454
431
  *
455
- * assert.deepStrictEqual(Function.constTrue(), true)
432
+ * Function.constTrue() // => true
456
433
  * ```
457
434
  *
458
435
  * @category constants
@@ -470,9 +447,8 @@ const constTrue = constant(true);
470
447
  *
471
448
  * ```ts
472
449
  * import { Function } from "effect"
473
- * import * as assert from "node:assert"
474
450
  *
475
- * assert.deepStrictEqual(Function.constFalse(), false)
451
+ * Function.constFalse() // => false
476
452
  * ```
477
453
  *
478
454
  * @category constants
@@ -490,9 +466,8 @@ const constFalse = constant(false);
490
466
  *
491
467
  * ```ts
492
468
  * import { Function } from "effect"
493
- * import * as assert from "node:assert"
494
469
  *
495
- * assert.deepStrictEqual(Function.constNull(), null)
470
+ * Function.constNull() // => null
496
471
  * ```
497
472
  *
498
473
  * @category constants
@@ -510,9 +485,8 @@ const constNull = constant(null);
510
485
  *
511
486
  * ```ts
512
487
  * import { Function } from "effect"
513
- * import * as assert from "node:assert"
514
488
  *
515
- * assert.deepStrictEqual(Function.constUndefined(), undefined)
489
+ * Function.constUndefined() // => undefined
516
490
  * ```
517
491
  *
518
492
  * @category constants
@@ -531,12 +505,11 @@ const constUndefined = constant(void 0);
531
505
  *
532
506
  * ```ts
533
507
  * import { Function } from "effect"
534
- * import * as assert from "node:assert"
535
508
  *
536
509
  * const increment = (n: number) => n + 1
537
510
  * const square = (n: number) => n * n
538
511
  *
539
- * assert.strictEqual(Function.compose(increment, square)(2), 9)
512
+ * Function.compose(increment, square)(2) // => 9
540
513
  * ```
541
514
  *
542
515
  * @see {@link flow} for composing a left-to-right sequence of functions
@@ -599,7 +572,6 @@ const absurd = (_) => {
599
572
  * name: hole<string>()
600
573
  * })
601
574
  *
602
- * console.log(typeof buildUser) // "function"
603
575
  * ```
604
576
  *
605
577
  * @category utility types
@@ -607,56 +579,407 @@ const absurd = (_) => {
607
579
  */
608
580
  const hole = cast(absurd);
609
581
  /**
610
- * Drops the longest prefix of elements from an array that satisfy the given predicate.
582
+ * Creates a predicate that returns `true` only if both predicates are `true`.
583
+ *
584
+ * **When to use**
585
+ *
586
+ * Use when you want to combine `Predicate`s with AND, accepting values that
587
+ * satisfy multiple conditions, including refinements that narrow to an
588
+ * intersection.
589
+ *
590
+ * **Details**
591
+ *
592
+ * Evaluation short-circuits on the first `false`. For refinements, the output
593
+ * type is an intersection.
594
+ *
595
+ * **Example** (Checking both conditions)
596
+ *
597
+ * ```ts
598
+ * import { Predicate } from "effect"
599
+ *
600
+ * const hasAAndB = Predicate.and(
601
+ * Predicate.hasProperty("a"),
602
+ * Predicate.hasProperty("b")
603
+ * )
604
+ *
605
+ * const input: unknown = JSON.parse(`{"a":1,"b":"ok"}`)
606
+ * if (hasAAndB(input)) {
607
+ * // input has both properties at this point
608
+ * const a = input.a
609
+ * const b = input.b
610
+ *
611
+ * const values = [a, b] // => [1, "ok"]
612
+ * }
613
+ * ```
614
+ *
615
+ * @see {@link or}
616
+ * @see {@link not}
617
+ * @category combinators
618
+ * @since 2.0.0
619
+ */
620
+ const and = dual(2, (a, b) => (data) => a(data) && b(data));
621
+ /**
622
+ * Creates a predicate that returns `true` if either predicate is `true`.
623
+ *
624
+ * **When to use**
625
+ *
626
+ * Use when you want to combine `Predicate`s with OR, accepting values that
627
+ * satisfy at least one condition, including refinements that narrow to a union.
628
+ *
629
+ * **Details**
630
+ *
631
+ * Evaluation short-circuits on the first `true`. For refinements, the output
632
+ * type is a union.
633
+ *
634
+ * **Example** (Checking either condition)
635
+ *
636
+ * ```ts
637
+ * import { Predicate } from "effect"
638
+ *
639
+ * const isStringOrNumber = Predicate.or(Predicate.isString, Predicate.isNumber)
640
+ *
641
+ * isStringOrNumber("a") // => true
642
+ * ```
643
+ *
644
+ * @see {@link and}
645
+ * @see {@link xor}
646
+ * @category combinators
647
+ * @since 2.0.0
648
+ */
649
+ const or = dual(2, (a, b) => (data) => a(data) || b(data));
650
+ /**
651
+ * Creates a predicate that returns `true` if exactly one predicate is `true`.
652
+ *
653
+ * **When to use**
654
+ *
655
+ * Use when you want to combine two `Predicate`s with exclusive-or semantics.
656
+ *
657
+ * **Details**
658
+ *
659
+ * Returns `true` when results differ.
660
+ *
661
+ * **Example** (Checking exclusive-or conditions)
662
+ *
663
+ * ```ts
664
+ * import { Predicate } from "effect"
665
+ *
666
+ * const isEven = (n: number) => n % 2 === 0
667
+ * const isPositive = (n: number) => n > 0
668
+ * const either = Predicate.xor(isEven, isPositive)
669
+ *
670
+ * either(-2) // => true
671
+ * ```
672
+ *
673
+ * @see {@link or}
674
+ * @see {@link and}
675
+ * @category combinators
676
+ * @since 2.0.0
677
+ */
678
+ const xor = dual(2, (a, b) => (data) => a(data) !== b(data));
679
+ /**
680
+ * Creates a predicate that returns `true` when both predicates agree.
681
+ *
682
+ * **When to use**
683
+ *
684
+ * Use when you want to check equivalence of two `Predicate`s.
685
+ *
686
+ * **Details**
687
+ *
688
+ * Returns `true` when both results are equal.
689
+ *
690
+ * **Example** (Defining equivalence)
691
+ *
692
+ * ```ts
693
+ * import { Predicate } from "effect"
694
+ *
695
+ * const isEven = (n: number) => n % 2 === 0
696
+ * const same = Predicate.eqv(isEven, isEven)
697
+ *
698
+ * same(3) // => true
699
+ * ```
700
+ *
701
+ * @see {@link xor}
702
+ * @category combinators
703
+ * @since 2.0.0
704
+ */
705
+ const eqv = dual(2, (a, b) => (data) => a(data) === b(data));
706
+ /**
707
+ * Creates a predicate representing logical implication: if `antecedent`, then `consequent`.
708
+ *
709
+ * **When to use**
710
+ *
711
+ * Use when you need to encode logical implication between `Predicate` rules,
712
+ * where one rule only applies when a precondition holds.
713
+ *
714
+ * **Details**
715
+ *
716
+ * Models constraints like "if A then B" and returns `true` when the antecedent
717
+ * is `false`.
718
+ *
719
+ * **Example** (Checking implication)
720
+ *
721
+ * ```ts
722
+ * import { Predicate } from "effect"
723
+ *
724
+ * const isAdult = (age: number) => age >= 18
725
+ * const canVote = (age: number) => age >= 18
726
+ * const implies = Predicate.implies(isAdult, canVote)
727
+ *
728
+ * implies(16) // => true
729
+ * ```
730
+ *
731
+ * @see {@link and}
732
+ * @see {@link or}
733
+ * @category combinators
734
+ * @since 2.0.0
735
+ */
736
+ const implies = dual(2, (antecedent, consequent) => (data) => !antecedent(data) || consequent(data));
737
+ /**
738
+ * Creates a predicate that returns `true` when neither predicate is `true`.
611
739
  *
612
- * Supports both data-first and data-last (`pipe`-friendly) call styles.
740
+ * **When to use**
741
+ *
742
+ * Use when you want to combine two `Predicate`s with logical NOR semantics.
743
+ *
744
+ * **Details**
745
+ *
746
+ * Returns the negation of `or`.
747
+ *
748
+ * **Example** (Checking NOR conditions)
613
749
  *
614
- * @param pred - The predicate to test each element with.
615
- * @returns A new array without the matching prefix.
616
- * @example
617
750
  * ```ts
618
- * import * as assert from "node:assert"
619
- * import { dropWhile, pipe } from "@local/eff"
751
+ * import { Predicate } from "effect"
620
752
  *
621
- * // data-first
622
- * assert.deepStrictEqual(dropWhile([1, 2, 3, 2, 1], (n: number) => n < 3), [3, 2, 1])
753
+ * const neither = Predicate.nor(Predicate.isString, Predicate.isNumber)
623
754
  *
624
- * // data-last
625
- * assert.deepStrictEqual(pipe([1, 2, 3, 2, 1], dropWhile((n: number) => n < 3)), [3, 2, 1])
755
+ * neither(true) // => true
626
756
  * ```
627
- * @category array
757
+ *
758
+ * @see {@link or}
759
+ * @see {@link not}
760
+ * @category combinators
761
+ * @since 2.0.0
628
762
  */
629
- const dropWhile = dual(2, (xs, pred) => {
630
- const len = xs.length;
763
+ const nor = dual(2, (a, b) => (data) => !a(data) && !b(data));
764
+ /**
765
+ * Creates a predicate that returns `true` unless both predicates are `true`.
766
+ *
767
+ * **When to use**
768
+ *
769
+ * Use when you want to combine two `Predicate`s with logical NAND semantics.
770
+ *
771
+ * **Details**
772
+ *
773
+ * Returns the negation of `and`.
774
+ *
775
+ * **Example** (Checking NAND conditions)
776
+ *
777
+ * ```ts
778
+ * import { Predicate } from "effect"
779
+ *
780
+ * const notBoth = Predicate.nand(Predicate.isString, Predicate.isNumber)
781
+ *
782
+ * notBoth("a") // => true
783
+ * ```
784
+ *
785
+ * @see {@link and}
786
+ * @see {@link not}
787
+ * @category combinators
788
+ * @since 2.0.0
789
+ */
790
+ const nand = dual(2, (a, b) => (data) => !a(data) || !b(data));
791
+ /**
792
+ * Checks whether a value is a `string`.
793
+ *
794
+ * **When to use**
795
+ *
796
+ * Use when you need a `Predicate` guard to narrow an `unknown` value to a
797
+ * string.
798
+ *
799
+ * **Details**
800
+ *
801
+ * Uses `typeof input === "string"`.
802
+ *
803
+ * **Example** (Guarding strings)
804
+ *
805
+ * ```ts
806
+ * import { Predicate } from "effect"
807
+ *
808
+ * const data: unknown = "hi"
809
+ *
810
+ * if (Predicate.isString(data)) {
811
+ * data.toUpperCase() // => "HI"
812
+ * }
813
+ * ```
814
+ *
815
+ * @see {@link isNumber}
816
+ * @see {@link isBoolean}
817
+ * @see {@link Refinement}
818
+ * @category guards
819
+ * @since 2.0.0
820
+ */
821
+ function isString(input) {
822
+ return typeof input === "string";
823
+ }
824
+ /**
825
+ * Checks whether a value is a `function`.
826
+ *
827
+ * **When to use**
828
+ *
829
+ * Use when you need a `Predicate` guard to narrow an `unknown` value to a
830
+ * callable function.
831
+ *
832
+ * **Details**
833
+ *
834
+ * Uses `typeof input === "function"`.
835
+ *
836
+ * **Example** (Guarding functions)
837
+ *
838
+ * ```ts
839
+ * import { Predicate } from "effect"
840
+ *
841
+ * const data: unknown = () => 1
842
+ *
843
+ * if (Predicate.isFunction(data)) {
844
+ * data() // => 1
845
+ * }
846
+ * ```
847
+ *
848
+ * @see {@link isObjectKeyword}
849
+ * @category guards
850
+ * @since 2.0.0
851
+ */
852
+ function isFunction(input) {
853
+ return typeof input === "function";
854
+ }
855
+ /**
856
+ * Checks whether a value is an `object` in the JavaScript sense (objects, arrays, functions).
857
+ *
858
+ * **When to use**
859
+ *
860
+ * Use when you need a `Predicate` guard that accepts arrays and functions as
861
+ * well as objects.
862
+ *
863
+ * **Details**
864
+ *
865
+ * Returns `true` for arrays and functions, and `false` for `null`.
866
+ *
867
+ * **Example** (Checking object keywords)
868
+ *
869
+ * ```ts
870
+ * import { Predicate } from "effect"
871
+ *
872
+ * Predicate.isObjectKeyword(() => 1) // => true
873
+ * Predicate.isObjectKeyword(null) // => false
874
+ * ```
875
+ *
876
+ * @see {@link isObject}
877
+ * @see {@link isObjectOrArray}
878
+ * @category guards
879
+ * @since 4.0.0
880
+ */
881
+ function isObjectKeyword(input) {
882
+ return typeof input === "object" && input !== null || isFunction(input);
883
+ }
884
+ /**
885
+ * Checks whether a value has a given property key.
886
+ *
887
+ * **When to use**
888
+ *
889
+ * Use when you need a `Predicate` guard for property access on `unknown`
890
+ * values with a simple structural object check.
891
+ *
892
+ * **Details**
893
+ *
894
+ * Uses the `in` operator and `isObjectKeyword`. This does not check property
895
+ * value types.
896
+ *
897
+ * **Example** (Guarding object properties)
898
+ *
899
+ * ```ts
900
+ * import { Predicate } from "effect"
901
+ *
902
+ * const hasName = Predicate.hasProperty("name")
903
+ * const data: unknown = { name: "Ada" }
904
+ *
905
+ * if (hasName(data)) {
906
+ * data.name // => "Ada"
907
+ * }
908
+ * ```
909
+ *
910
+ * @see {@link isTagged}
911
+ * @see {@link isObjectKeyword}
912
+ * @category guards
913
+ * @since 2.0.0
914
+ */
915
+ const hasProperty = dual(2, (data, property) => isObjectKeyword(data) && property in data);
916
+ /**
917
+ * Drops elements from the start while the predicate holds, returning the rest.
918
+ *
919
+ * **When to use**
920
+ *
921
+ * Use to remove a leading prefix of elements that satisfy a predicate.
922
+ *
923
+ * **Details**
924
+ *
925
+ * The predicate receives `(element, index)`.
926
+ *
927
+ * **Example** (Dropping while condition holds)
928
+ *
929
+ * ```ts
930
+ * import { Array } from "effect"
931
+ *
932
+ * Array.dropWhile([1, 2, 3, 4, 5], (x) => x < 4) // => [4, 5]
933
+ * ```
934
+ *
935
+ * @see {@link takeWhile} — keep the matching prefix instead
936
+ * @see {@link drop} — drop a fixed count
937
+ *
938
+ * @category getters
939
+ * @since 2.0.0
940
+ */
941
+ const dropWhile = dual(2, (self, predicate) => {
942
+ const input = Array.isArray(self) ? self : Array.from(self);
943
+ const len = input.length;
631
944
  let idx = 0;
632
- while (idx < len && pred(xs[idx])) idx++;
633
- return xs.slice(idx);
945
+ while (idx < len && predicate(input[idx], idx)) idx++;
946
+ return input.slice(idx);
634
947
  });
635
948
  /**
636
- * Takes the longest prefix of elements from an array that satisfy the given predicate.
949
+ * Takes elements from the start while the predicate holds, stopping at the
950
+ * first element that fails.
637
951
  *
638
- * Supports both data-first and data-last (`pipe`-friendly) call styles.
952
+ * **When to use**
639
953
  *
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"
954
+ * Use to keep the leading elements of an iterable while each element satisfies
955
+ * a predicate, returning the retained prefix as an array.
956
+ *
957
+ * **Details**
646
958
  *
647
- * // data-first
648
- * assert.deepStrictEqual(takeWhile([1, 2, 3, 2, 1], (n: number) => n < 3), [1, 2])
959
+ * Supports refinements for type narrowing. The predicate receives
960
+ * `(element, index)`.
649
961
  *
650
- * // data-last
651
- * assert.deepStrictEqual(pipe([1, 2, 3, 2, 1], takeWhile((n: number) => n < 3)), [1, 2])
962
+ * **Example** (Taking while condition holds)
963
+ *
964
+ * ```ts
965
+ * import { Array } from "effect"
966
+ *
967
+ * Array.takeWhile([1, 3, 2, 4, 1, 2], (x) => x < 4) // => [1, 3, 2]
652
968
  * ```
653
- * @category array
969
+ *
970
+ * @see {@link take} for keeping a fixed number of leading elements
971
+ * @see {@link dropWhile} for removing the matching prefix and keeping the rest
972
+ * @see {@link span} for splitting the matching prefix from the remaining elements
973
+ *
974
+ * @category getters
975
+ * @since 2.0.0
654
976
  */
655
- const takeWhile = dual(2, (xs, pred) => {
656
- const len = xs.length;
977
+ const takeWhile = dual(2, (self, predicate) => {
978
+ const input = Array.isArray(self) ? self : Array.from(self);
979
+ const len = input.length;
657
980
  let idx = 0;
658
- while (idx < len && pred(xs[idx])) idx++;
659
- return xs.slice(0, idx);
981
+ while (idx < len && predicate(input[idx], idx)) idx++;
982
+ return input.slice(0, idx);
660
983
  });
661
984
 
662
985
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/ast",
3
- "version": "5.24.0-beta.2",
3
+ "version": "5.24.1",
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.11.0",
40
+ "eslint": "^10.12.0",
41
41
  "tsdown": "^0.23.0",
42
42
  "typescript": "6.0.3",
43
43
  "vitest": "^5.0.3"