@eslint-react/jsx 0.5.7 → 0.5.9

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.cjs CHANGED
@@ -1,17 +1,9 @@
1
1
  'use strict';
2
2
 
3
- var memo = require('micro-memoize');
4
3
  require('@typescript-eslint/scope-manager');
5
4
  var types = require('@typescript-eslint/types');
6
5
  var utils = require('@typescript-eslint/utils');
7
-
8
- /**
9
- * Check if a JSXElement or JSXFragment has children
10
- * @param node The AST node to check
11
- * @returns `true` if the node has children
12
- */ function hasChildren(node) {
13
- return node.children.length > 0;
14
- }
6
+ var memo = require('micro-memoize');
15
7
 
16
8
  /**
17
9
  * @since 2.0.0
@@ -1287,7 +1279,6 @@ const LeftProto = /*#__PURE__*/ Object.assign(/*#__PURE__*/ Object.create(Common
1287
1279
  };
1288
1280
  /** @internal */ const getLeft$2 = (self)=>isRight$1(self) ? none$1 : some$4(self.left);
1289
1281
  /** @internal */ const getRight$2 = (self)=>isLeft$1(self) ? none$1 : some$4(self.right);
1290
- /** @internal */ const fromOption$1 = /*#__PURE__*/ dual(2, (self, onNone)=>isNone$1(self) ? left$1(onNone()) : right$1(self.value));
1291
1282
  /**
1292
1283
  * @since 2.0.0
1293
1284
  */ /**
@@ -2227,15 +2218,6 @@ var effectOption_esm = /*#__PURE__*/ Object.freeze({
2227
2218
  zipRight: zipRight,
2228
2219
  zipWith: zipWith$3
2229
2220
  });
2230
- /**
2231
- * @since 2.0.0
2232
- */ /**
2233
- * @category models
2234
- * @since 2.0.0
2235
- */ /**
2236
- * @category symbols
2237
- * @since 2.0.0
2238
- */ const TypeId$5 = TypeId$7;
2239
2221
  /**
2240
2222
  * @category symbols
2241
2223
  * @since 2.0.0
@@ -2268,366 +2250,6 @@ var effectOption_esm = /*#__PURE__*/ Object.freeze({
2268
2250
  * @category constructors
2269
2251
  * @since 2.0.0
2270
2252
  */ const left = left$1;
2271
- /**
2272
- * Takes a lazy default and a nullable value, if the value is not nully (`null` or `undefined`), turn it into a `Right`, if the value is nully use
2273
- * the provided default as a `Left`.
2274
- *
2275
- * @example
2276
- * import * as Either from 'effect/Either'
2277
- *
2278
- * assert.deepStrictEqual(Either.fromNullable(1, () => 'fallback'), Either.right(1))
2279
- * assert.deepStrictEqual(Either.fromNullable(null, () => 'fallback'), Either.left('fallback'))
2280
- *
2281
- * @category constructors
2282
- * @since 2.0.0
2283
- */ const fromNullable = /*#__PURE__*/ dual(2, (self, onNullable)=>self == null ? left(onNullable(self)) : right(self));
2284
- /**
2285
- * @example
2286
- * import * as Either from 'effect/Either'
2287
- * import * as Option from 'effect/Option'
2288
- *
2289
- * assert.deepStrictEqual(Either.fromOption(Option.some(1), () => 'error'), Either.right(1))
2290
- * assert.deepStrictEqual(Either.fromOption(Option.none(), () => 'error'), Either.left('error'))
2291
- *
2292
- * @category constructors
2293
- * @since 2.0.0
2294
- */ const fromOption = fromOption$1;
2295
- const try_ = (evaluate)=>{
2296
- if (isFunction(evaluate)) {
2297
- try {
2298
- return right(evaluate());
2299
- } catch (e) {
2300
- return left(e);
2301
- }
2302
- } else {
2303
- try {
2304
- return right(evaluate.try());
2305
- } catch (e) {
2306
- return left(evaluate.catch(e));
2307
- }
2308
- }
2309
- };
2310
- /**
2311
- * Tests if a value is a `Either`.
2312
- *
2313
- * @param input - The value to test.
2314
- *
2315
- * @example
2316
- * import { isEither, left, right } from 'effect/Either'
2317
- *
2318
- * assert.deepStrictEqual(isEither(right(1)), true)
2319
- * assert.deepStrictEqual(isEither(left("a")), true)
2320
- * assert.deepStrictEqual(isEither({ right: 1 }), false)
2321
- *
2322
- * @category guards
2323
- * @since 2.0.0
2324
- */ const isEither = isEither$1;
2325
- /**
2326
- * Determine if a `Either` is a `Left`.
2327
- *
2328
- * @param self - The `Either` to check.
2329
- *
2330
- * @example
2331
- * import { isLeft, left, right } from 'effect/Either'
2332
- *
2333
- * assert.deepStrictEqual(isLeft(right(1)), false)
2334
- * assert.deepStrictEqual(isLeft(left("a")), true)
2335
- *
2336
- * @category guards
2337
- * @since 2.0.0
2338
- */ const isLeft = isLeft$1;
2339
- /**
2340
- * Determine if a `Either` is a `Right`.
2341
- *
2342
- * @param self - The `Either` to check.
2343
- *
2344
- * @example
2345
- * import { isRight, left, right } from 'effect/Either'
2346
- *
2347
- * assert.deepStrictEqual(isRight(right(1)), true)
2348
- * assert.deepStrictEqual(isRight(left("a")), false)
2349
- *
2350
- * @category guards
2351
- * @since 2.0.0
2352
- */ const isRight = isRight$1;
2353
- /**
2354
- * Converts a `Either` to an `Option` discarding the `Left`.
2355
- *
2356
- * Alias of {@link toOption}.
2357
- *
2358
- * @example
2359
- * import * as O from 'effect/Option'
2360
- * import * as E from 'effect/Either'
2361
- *
2362
- * assert.deepStrictEqual(E.getRight(E.right('ok')), O.some('ok'))
2363
- * assert.deepStrictEqual(E.getRight(E.left('err')), O.none())
2364
- *
2365
- * @category getters
2366
- * @since 2.0.0
2367
- */ const getRight = getRight$2;
2368
- /**
2369
- * Converts a `Either` to an `Option` discarding the value.
2370
- *
2371
- * @example
2372
- * import * as O from 'effect/Option'
2373
- * import * as E from 'effect/Either'
2374
- *
2375
- * assert.deepStrictEqual(E.getLeft(E.right('ok')), O.none())
2376
- * assert.deepStrictEqual(E.getLeft(E.left('err')), O.some('err'))
2377
- *
2378
- * @category getters
2379
- * @since 2.0.0
2380
- */ const getLeft = getLeft$2;
2381
- /**
2382
- * @category equivalence
2383
- * @since 2.0.0
2384
- */ const getEquivalence$4 = (EE, EA)=>make$7((x, y)=>x === y || (isLeft(x) ? isLeft(y) && EE(x.left, y.left) : isRight(y) && EA(x.right, y.right)));
2385
- /**
2386
- * @category mapping
2387
- * @since 2.0.0
2388
- */ const mapBoth = /*#__PURE__*/ dual(2, (self, { onLeft, onRight })=>isLeft(self) ? left(onLeft(self.left)) : right(onRight(self.right)));
2389
- /**
2390
- * Maps the `Left` side of an `Either` value to a new `Either` value.
2391
- *
2392
- * @param self - The input `Either` value to map.
2393
- * @param f - A transformation function to apply to the `Left` value of the input `Either`.
2394
- *
2395
- * @category mapping
2396
- * @since 2.0.0
2397
- */ const mapLeft = /*#__PURE__*/ dual(2, (self, f)=>isLeft(self) ? left(f(self.left)) : right(self.right));
2398
- /**
2399
- * Maps the `Right` side of an `Either` value to a new `Either` value.
2400
- *
2401
- * @param self - An `Either` to map
2402
- * @param f - The function to map over the value of the `Either`
2403
- *
2404
- * @category mapping
2405
- * @since 2.0.0
2406
- */ const map$4 = /*#__PURE__*/ dual(2, (self, f)=>isRight(self) ? right(f(self.right)) : left(self.left));
2407
- /**
2408
- * Takes two functions and an `Either` value, if the value is a `Left` the inner value is applied to the `onLeft function,
2409
- * if the value is a `Right` the inner value is applied to the `onRight` function.
2410
- *
2411
- * @example
2412
- * import * as E from 'effect/Either'
2413
- * import { pipe } from 'effect/Function'
2414
- *
2415
- * const onLeft = (strings: ReadonlyArray<string>): string => `strings: ${strings.join(', ')}`
2416
- *
2417
- * const onRight = (value: number): string => `Ok: ${value}`
2418
- *
2419
- * assert.deepStrictEqual(pipe(E.right(1), E.match({ onLeft, onRight })), 'Ok: 1')
2420
- * assert.deepStrictEqual(
2421
- * pipe(E.left(['string 1', 'string 2']), E.match({ onLeft, onRight })),
2422
- * 'strings: string 1, string 2'
2423
- * )
2424
- *
2425
- * @category pattern matching
2426
- * @since 2.0.0
2427
- */ const match = /*#__PURE__*/ dual(2, (self, { onLeft, onRight })=>isLeft(self) ? onLeft(self.left) : onRight(self.right));
2428
- /**
2429
- * @category getters
2430
- * @since 2.0.0
2431
- */ const merge = /*#__PURE__*/ match({
2432
- onLeft: identity$1,
2433
- onRight: identity$1
2434
- });
2435
- /**
2436
- * Returns the wrapped value if it's a `Right` or a default value if is a `Left`.
2437
- *
2438
- * @example
2439
- * import * as Either from 'effect/Either'
2440
- *
2441
- * assert.deepStrictEqual(Either.getOrElse(Either.right(1), (error) => error + "!"), 1)
2442
- * assert.deepStrictEqual(Either.getOrElse(Either.left("not a number"), (error) => error + "!"), "not a number!")
2443
- *
2444
- * @category getters
2445
- * @since 2.0.0
2446
- */ const getOrElse = /*#__PURE__*/ dual(2, (self, onLeft)=>isLeft(self) ? onLeft(self.left) : self.right);
2447
- /**
2448
- * @example
2449
- * import * as Either from 'effect/Either'
2450
- *
2451
- * assert.deepStrictEqual(Either.getOrNull(Either.right(1)), 1)
2452
- * assert.deepStrictEqual(Either.getOrNull(Either.left("a")), null)
2453
- *
2454
- * @category getters
2455
- * @since 2.0.0
2456
- */ const getOrNull = /*#__PURE__*/ getOrElse(constNull);
2457
- /**
2458
- * @example
2459
- * import * as Either from 'effect/Either'
2460
- *
2461
- * assert.deepStrictEqual(Either.getOrUndefined(Either.right(1)), 1)
2462
- * assert.deepStrictEqual(Either.getOrUndefined(Either.left("a")), undefined)
2463
- *
2464
- * @category getters
2465
- * @since 2.0.0
2466
- */ const getOrUndefined = /*#__PURE__*/ getOrElse(constUndefined);
2467
- /**
2468
- * Extracts the value of an `Either` or throws if the `Either` is `Left`.
2469
- *
2470
- * If a default error is sufficient for your use case and you don't need to configure the thrown error, see {@link getOrThrow}.
2471
- *
2472
- * @param self - The `Either` to extract the value from.
2473
- * @param onLeft - A function that will be called if the `Either` is `Left`. It returns the error to be thrown.
2474
- *
2475
- * @example
2476
- * import * as E from "effect/Either"
2477
- *
2478
- * assert.deepStrictEqual(
2479
- * E.getOrThrowWith(E.right(1), () => new Error('Unexpected Left')),
2480
- * 1
2481
- * )
2482
- * assert.throws(() => E.getOrThrowWith(E.left("error"), () => new Error('Unexpected Left')))
2483
- *
2484
- * @category getters
2485
- * @since 2.0.0
2486
- */ const getOrThrowWith = /*#__PURE__*/ dual(2, (self, onLeft)=>{
2487
- if (isRight(self)) {
2488
- return self.right;
2489
- }
2490
- throw onLeft(self.left);
2491
- });
2492
- /**
2493
- * Extracts the value of an `Either` or throws if the `Either` is `Left`.
2494
- *
2495
- * The thrown error is a default error. To configure the error thrown, see {@link getOrThrowWith}.
2496
- *
2497
- * @param self - The `Either` to extract the value from.
2498
- * @throws `Error("getOrThrow called on a Left")`
2499
- *
2500
- * @example
2501
- * import * as E from "effect/Either"
2502
- *
2503
- * assert.deepStrictEqual(E.getOrThrow(E.right(1)), 1)
2504
- * assert.throws(() => E.getOrThrow(E.left("error")))
2505
- *
2506
- * @category getters
2507
- * @since 2.0.0
2508
- */ const getOrThrow = /*#__PURE__*/ getOrThrowWith(()=>new Error("getOrThrow called on a Left"));
2509
- /**
2510
- * Returns `self` if it is a `Right` or `that` otherwise.
2511
- *
2512
- * @param self - The input `Either` value to check and potentially return.
2513
- * @param that - A function that takes the error value from `self` (if it's a `Left`) and returns a new `Either` value.
2514
- *
2515
- * @category error handling
2516
- * @since 2.0.0
2517
- */ const orElse = /*#__PURE__*/ dual(2, (self, that)=>isLeft(self) ? that(self.left) : right(self.right));
2518
- /**
2519
- * @category combining
2520
- * @since 2.0.0
2521
- */ const flatMap$2 = /*#__PURE__*/ dual(2, (self, f)=>isLeft(self) ? left(self.left) : f(self.right));
2522
- /**
2523
- * @since 2.0.0
2524
- * @category combining
2525
- */ const zipWith$2 = /*#__PURE__*/ dual(3, (self, that, f)=>flatMap$2(self, (a)=>map$4(that, (b)=>f(a, b))));
2526
- /**
2527
- * @category combining
2528
- * @since 2.0.0
2529
- */ const ap = /*#__PURE__*/ dual(2, (self, that)=>zipWith$2(self, that, (f, a)=>f(a)));
2530
- /**
2531
- * Takes a structure of `Option`s and returns an `Option` of values with the same structure.
2532
- *
2533
- * - If a tuple is supplied, then the returned `Option` will contain a tuple with the same length.
2534
- * - If a struct is supplied, then the returned `Option` will contain a struct with the same keys.
2535
- * - If an iterable is supplied, then the returned `Option` will contain an array.
2536
- *
2537
- * @param fields - the struct of `Option`s to be sequenced.
2538
- *
2539
- * @example
2540
- * import * as Either from "effect/Either"
2541
- *
2542
- * assert.deepStrictEqual(Either.all([Either.right(1), Either.right(2)]), Either.right([1, 2]))
2543
- * assert.deepStrictEqual(Either.all({ a: Either.right(1), b: Either.right("hello") }), Either.right({ a: 1, b: "hello" }))
2544
- * assert.deepStrictEqual(Either.all({ a: Either.right(1), b: Either.left("error") }), Either.left("error"))
2545
- *
2546
- * @category combining
2547
- * @since 2.0.0
2548
- */ // @ts-expect-error
2549
- const all = (input)=>{
2550
- if (Symbol.iterator in input) {
2551
- const out = [];
2552
- for (const e of input){
2553
- if (isLeft(e)) {
2554
- return e;
2555
- }
2556
- out.push(e.right);
2557
- }
2558
- return right(out);
2559
- }
2560
- const out = {};
2561
- for (const key of Object.keys(input)){
2562
- const e = input[key];
2563
- if (isLeft(e)) {
2564
- return e;
2565
- }
2566
- out[key] = e.right;
2567
- }
2568
- return right(out);
2569
- };
2570
- /**
2571
- * @since 2.0.0
2572
- */ const reverse$3 = (self)=>isLeft(self) ? right(self.left) : left(self.right);
2573
- const adapter = /*#__PURE__*/ adapter$2();
2574
- /**
2575
- * @category generators
2576
- * @since 2.0.0
2577
- */ const gen = (f)=>{
2578
- const iterator = f(adapter);
2579
- let state = iterator.next();
2580
- if (state.done) {
2581
- return right(state.value);
2582
- } else {
2583
- let current = state.value.value;
2584
- if (isLeft(current)) {
2585
- return current;
2586
- }
2587
- while(!state.done){
2588
- state = iterator.next(current.right);
2589
- if (!state.done) {
2590
- current = state.value.value;
2591
- if (isLeft(current)) {
2592
- return current;
2593
- }
2594
- }
2595
- }
2596
- return right(state.value);
2597
- }
2598
- };
2599
- var effectEither_esm = /*#__PURE__*/ Object.freeze({
2600
- __proto__: null,
2601
- TypeId: TypeId$5,
2602
- all: all,
2603
- ap: ap,
2604
- flatMap: flatMap$2,
2605
- fromNullable: fromNullable,
2606
- fromOption: fromOption,
2607
- gen: gen,
2608
- getEquivalence: getEquivalence$4,
2609
- getLeft: getLeft,
2610
- getOrElse: getOrElse,
2611
- getOrNull: getOrNull,
2612
- getOrThrow: getOrThrow,
2613
- getOrThrowWith: getOrThrowWith,
2614
- getOrUndefined: getOrUndefined,
2615
- getRight: getRight,
2616
- isEither: isEither,
2617
- isLeft: isLeft,
2618
- isRight: isRight,
2619
- left: left,
2620
- map: map$4,
2621
- mapBoth: mapBoth,
2622
- mapLeft: mapLeft,
2623
- match: match,
2624
- merge: merge,
2625
- orElse: orElse,
2626
- reverse: reverse$3,
2627
- right: right,
2628
- try: try_,
2629
- zipWith: zipWith$2
2630
- });
2631
2253
  /**
2632
2254
  * @category conversions
2633
2255
  * @since 2.0.0
@@ -5130,30 +4752,6 @@ var effectData_esm = /*#__PURE__*/ Object.freeze({
5130
4752
  unsafeStruct: unsafeStruct
5131
4753
  });
5132
4754
 
5133
- const RE_JSX_ANNOTATION_REGEX = /@jsx\s+(\S+)/u;
5134
- // Does not check for reserved keywords or unicode characters
5135
- const RE_JS_IDENTIFIER_REGEX = /^[$A-Z_a-z][\w$]*$/u;
5136
- function getFragmentFromContext(context) {
5137
- // eslint-disable-next-line prefer-destructuring
5138
- const settings = context.settings;
5139
- const pragma = settings.react?.fragment ?? "Fragment";
5140
- if (!RE_JS_IDENTIFIER_REGEX.test(pragma)) {
5141
- return effectEither_esm.left(new Error(`Fragment pragma ${pragma} is not a valid identifier`));
5142
- }
5143
- return effectEither_esm.right(pragma);
5144
- }
5145
- const getPragmaFromContext = memo((context)=>{
5146
- // eslint-disable-next-line prefer-destructuring
5147
- const settings = context.settings;
5148
- const sourceCode = context.getSourceCode();
5149
- const pragmaNode = sourceCode.getAllComments().find((node)=>RE_JSX_ANNOTATION_REGEX.test(node.value));
5150
- const pragma = settings.react?.pragma ?? effectFunction_esm.pipe(effectOption_esm.fromNullable(pragmaNode), effectOption_esm.map((node)=>RE_JSX_ANNOTATION_REGEX.exec(node.value)), effectOption_esm.flatMap((matches)=>effectOption_esm.fromNullable(matches?.[1]?.split(".")[0])), effectOption_esm.getOrElse(()=>"React"));
5151
- if (!RE_JS_IDENTIFIER_REGEX.test(pragma)) {
5152
- return effectEither_esm.left(new Error(`React pragma ${pragma} is not a valid identifier`));
5153
- }
5154
- return effectEither_esm.right(pragma);
5155
- });
5156
-
5157
4755
  function isNil(x){
5158
4756
  return x === undefined || x === null
5159
4757
  }
@@ -5440,6 +5038,51 @@ isOneOf([
5440
5038
  NodeType.TSInterfaceDeclaration,
5441
5039
  NodeType.TSTypeAliasDeclaration
5442
5040
  ]);
5041
+ isOneOf([
5042
+ NodeType.ArrayExpression,
5043
+ NodeType.ArrayPattern,
5044
+ NodeType.ArrowFunctionExpression,
5045
+ NodeType.CallExpression,
5046
+ NodeType.ClassExpression,
5047
+ NodeType.FunctionExpression,
5048
+ NodeType.Identifier,
5049
+ NodeType.JSXElement,
5050
+ NodeType.JSXFragment,
5051
+ NodeType.Literal,
5052
+ NodeType.TemplateLiteral,
5053
+ NodeType.MemberExpression,
5054
+ NodeType.MetaProperty,
5055
+ NodeType.ObjectExpression,
5056
+ NodeType.ObjectPattern,
5057
+ NodeType.SequenceExpression,
5058
+ NodeType.Super,
5059
+ NodeType.TaggedTemplateExpression,
5060
+ NodeType.ThisExpression
5061
+ ]);
5062
+ isOneOf([
5063
+ NodeType.ArrayExpression,
5064
+ NodeType.ArrayPattern,
5065
+ NodeType.ArrowFunctionExpression,
5066
+ NodeType.CallExpression,
5067
+ NodeType.ClassExpression,
5068
+ NodeType.FunctionExpression,
5069
+ NodeType.Identifier,
5070
+ NodeType.JSXElement,
5071
+ NodeType.JSXFragment,
5072
+ NodeType.Literal,
5073
+ NodeType.TemplateLiteral,
5074
+ NodeType.MemberExpression,
5075
+ NodeType.MetaProperty,
5076
+ NodeType.ObjectExpression,
5077
+ NodeType.ObjectPattern,
5078
+ NodeType.SequenceExpression,
5079
+ NodeType.Super,
5080
+ NodeType.TaggedTemplateExpression,
5081
+ NodeType.ThisExpression,
5082
+ NodeType.TSAsExpression,
5083
+ NodeType.TSNonNullExpression,
5084
+ NodeType.TSTypeAssertion
5085
+ ]);
5443
5086
  const Construction = effectData_esm.taggedEnum();
5444
5087
  Construction.None();
5445
5088
  [
@@ -6864,16 +6507,82 @@ function isStringLiteral(node) {
6864
6507
  };
6865
6508
  }
6866
6509
 
6510
+ /**
6511
+ * Check if a `JSXElement` or `JSXFragment` has children
6512
+ * @param node The AST node to check
6513
+ * @param predicate A predicate to filter the children
6514
+ * @returns `true` if the node has children
6515
+ */ function hasChildren(node, predicate) {
6516
+ if (typeof predicate === "function") {
6517
+ return node.children.some(predicate);
6518
+ }
6519
+ return node.children.length > 0;
6520
+ }
6521
+ /**
6522
+ * Check if a node is a child of a `JSXElement`
6523
+ * @param node The AST node to check
6524
+ * @returns `true` if the node is a child of a `JSXElement`
6525
+ */ function isChildOfJSXElement(node) {
6526
+ return node.parent?.type === NodeType.JSXElement && node.parent.children.some((child)=>child === node);
6527
+ }
6528
+
6529
+ /**
6530
+ * Tests if a value is a `string`.
6531
+ *
6532
+ * @param input - The value to test.
6533
+ *
6534
+ * @example
6535
+ * import { isString } from "effect/Predicate"
6536
+ *
6537
+ * assert.deepStrictEqual(isString("a"), true)
6538
+ *
6539
+ * assert.deepStrictEqual(isString(1), false)
6540
+ *
6541
+ * @category guards
6542
+ * @since 2.0.0
6543
+ */
6544
+ const isString = input => typeof input === "string";
6545
+
6546
+ const RE_JSX_ANNOTATION_REGEX = /@jsx\s+(\S+)/u;
6547
+ // Does not check for reserved keywords or unicode characters
6548
+ const RE_JS_IDENTIFIER_REGEX = /^[$A-Z_a-z][\w$]*$/u;
6549
+ function getFragmentFromContext(context) {
6550
+ // eslint-disable-next-line prefer-destructuring
6551
+ const settings = context.settings;
6552
+ const fragment = settings.react?.fragment;
6553
+ if (isString(fragment) && RE_JS_IDENTIFIER_REGEX.test(fragment)) {
6554
+ return fragment;
6555
+ }
6556
+ return "Fragment";
6557
+ }
6558
+ const getPragmaFromContext = memo((context)=>{
6559
+ // eslint-disable-next-line prefer-destructuring
6560
+ const settings = context.settings;
6561
+ const sourceCode = context.getSourceCode();
6562
+ const pragmaNode = sourceCode.getAllComments().find((node)=>RE_JSX_ANNOTATION_REGEX.test(node.value));
6563
+ return effectFunction_esm.pipe(effectOption_esm.orElse(effectOption_esm.fromNullable(settings.react?.pragma), ()=>effectFunction_esm.pipe(effectOption_esm.fromNullable(pragmaNode), effectOption_esm.map(({ value })=>RE_JSX_ANNOTATION_REGEX.exec(value)), effectOption_esm.flatMapNullable((matches)=>matches?.[1]?.split(".")[0]))), effectOption_esm.flatMap(effectOption_esm.liftPredicate((x)=>RE_JS_IDENTIFIER_REGEX.test(x))), effectOption_esm.getOrElse(effectFunction_esm.constant("React")));
6564
+ });
6565
+
6867
6566
  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],s=(n,o,c)=>{if(i(n)){const e=n[t](),{matched:r,selections:i}=e.match(o);return r&&i&&Object.keys(i).forEach(t=>c(t,i[t])),r}if(r(n)){if(!r(o))return !1;if(Array.isArray(n)){if(!Array.isArray(o))return !1;let t=[],r=[],a=[];for(const s of n.keys()){const o=n[s];i(o)&&o[e]?a.push(o):a.length?r.push(o):t.push(o);}if(a.length){if(a.length>1)throw new Error("Pattern error: Using `...P.array(...)` several times in a single pattern is not allowed.");if(o.length<t.length+r.length)return !1;const e=o.slice(0,t.length),n=0===r.length?[]:o.slice(-r.length),i=o.slice(t.length,0===r.length?Infinity:-r.length);return t.every((t,n)=>s(t,e[n],c))&&r.every((t,e)=>s(t,n[e],c))&&(0===a.length||s(a[0],i,c))}return n.length===o.length&&n.every((t,e)=>s(t,o[e],c))}return Object.keys(n).every(e=>{const r=n[e];return (e in o||i(a=r)&&"optional"===a[t]().matcherType)&&s(r,o[e],c);var a;})}return Object.is(o,n)},o=e=>{var n,s,a;return r(e)?i(e)?null!=(n=null==(s=(a=e[t]()).getSelectionKeys)?void 0:s.call(a))?n:[]:Array.isArray(e)?c(e,o):c(Object.values(e),o):[]},c=(t,e)=>t.reduce((t,n)=>t.concat(e(n)),[]);function a(...t){if(1===t.length){const[e]=t;return t=>s(e,t,()=>{})}if(2===t.length){const[e,n]=t;return s(e,n,()=>{})}throw new Error(`isMatching wasn't given the right number of arguments: expected 1 or 2, received ${t.length}.`)}function u(t){return Object.assign(t,{optional:()=>l(t),and:e=>m(t,e),or:e=>y(t,e),select:e=>void 0===e?p(t):p(e,t)})}function h(t){return Object.assign((t=>Object.assign(t,{*[Symbol.iterator](){yield Object.assign(t,{[e]:!0});}}))(t),{optional:()=>h(l(t)),select:e=>h(void 0===e?p(t):p(e,t))})}function l(e){return u({[t]:()=>({match:t=>{let n={};const r=(t,e)=>{n[t]=e;};return void 0===t?(o(e).forEach(t=>r(t,void 0)),{matched:!0,selections:n}):{matched:s(e,t,r),selections:n}},getSelectionKeys:()=>o(e),matcherType:"optional"})})}const f=(t,e)=>{for(const n of t)if(!e(n))return !1;return !0},g=(t,e)=>{for(const[n,r]of t.entries())if(!e(r,n))return !1;return !0};function m(...e){return u({[t]:()=>({match:t=>{let n={};const r=(t,e)=>{n[t]=e;};return {matched:e.every(e=>s(e,t,r)),selections:n}},getSelectionKeys:()=>c(e,o),matcherType:"and"})})}function y(...e){return u({[t]:()=>({match:t=>{let n={};const r=(t,e)=>{n[t]=e;};return c(e,o).forEach(t=>r(t,void 0)),{matched:e.some(e=>s(e,t,r)),selections:n}},getSelectionKeys:()=>c(e,o),matcherType:"or"})})}function d(e){return {[t]:()=>({match:t=>({matched:Boolean(e(t))})})}}function p(...e){const r="string"==typeof e[0]?e[0]:void 0,i=2===e.length?e[1]:"string"==typeof e[0]?void 0:e[0];return u({[t]:()=>({match:t=>{let e={[null!=r?r:n]:t};return {matched:void 0===i||s(i,t,(t,n)=>{e[t]=n;}),selections:e}},getSelectionKeys:()=>[null!=r?r:n].concat(void 0===i?[]:o(i))})})}function v(t){return "number"==typeof t}function b(t){return "string"==typeof t}function w(t){return "bigint"==typeof t}const S=u(d(function(t){return !0})),O=S,j=t=>Object.assign(u(t),{startsWith:e=>{return j(m(t,(n=e,d(t=>b(t)&&t.startsWith(n)))));var n;},endsWith:e=>{return j(m(t,(n=e,d(t=>b(t)&&t.endsWith(n)))));var n;},minLength:e=>j(m(t,(t=>d(e=>b(e)&&e.length>=t))(e))),maxLength:e=>j(m(t,(t=>d(e=>b(e)&&e.length<=t))(e))),includes:e=>{return j(m(t,(n=e,d(t=>b(t)&&t.includes(n)))));var n;},regex:e=>{return j(m(t,(n=e,d(t=>b(t)&&Boolean(t.match(n))))));var n;}}),E=j(d(b)),K=t=>Object.assign(u(t),{between:(e,n)=>K(m(t,((t,e)=>d(n=>v(n)&&t<=n&&e>=n))(e,n))),lt:e=>K(m(t,(t=>d(e=>v(e)&&e<t))(e))),gt:e=>K(m(t,(t=>d(e=>v(e)&&e>t))(e))),lte:e=>K(m(t,(t=>d(e=>v(e)&&e<=t))(e))),gte:e=>K(m(t,(t=>d(e=>v(e)&&e>=t))(e))),int:()=>K(m(t,d(t=>v(t)&&Number.isInteger(t)))),finite:()=>K(m(t,d(t=>v(t)&&Number.isFinite(t)))),positive:()=>K(m(t,d(t=>v(t)&&t>0))),negative:()=>K(m(t,d(t=>v(t)&&t<0)))}),A=K(d(v)),x=t=>Object.assign(u(t),{between:(e,n)=>x(m(t,((t,e)=>d(n=>w(n)&&t<=n&&e>=n))(e,n))),lt:e=>x(m(t,(t=>d(e=>w(e)&&e<t))(e))),gt:e=>x(m(t,(t=>d(e=>w(e)&&e>t))(e))),lte:e=>x(m(t,(t=>d(e=>w(e)&&e<=t))(e))),gte:e=>x(m(t,(t=>d(e=>w(e)&&e>=t))(e))),positive:()=>x(m(t,d(t=>w(t)&&t>0))),negative:()=>x(m(t,d(t=>w(t)&&t<0)))}),P=x(d(w)),T=u(d(function(t){return "boolean"==typeof t})),k=u(d(function(t){return "symbol"==typeof t})),B=u(d(function(t){return null==t}));var _={__proto__:null,matcher:t,optional:l,array:function(...e){return h({[t]:()=>({match:t=>{if(!Array.isArray(t))return {matched:!1};if(0===e.length)return {matched:!0};const n=e[0];let r={};if(0===t.length)return o(n).forEach(t=>{r[t]=[];}),{matched:!0,selections:r};const i=(t,e)=>{r[t]=(r[t]||[]).concat([e]);};return {matched:t.every(t=>s(n,t,i)),selections:r}},getSelectionKeys:()=>0===e.length?[]:o(e[0])})})},set:function(...e){return u({[t]:()=>({match:t=>{if(!(t instanceof Set))return {matched:!1};let n={};if(0===t.size)return {matched:!0,selections:n};if(0===e.length)return {matched:!0};const r=(t,e)=>{n[t]=(n[t]||[]).concat([e]);},i=e[0];return {matched:f(t,t=>s(i,t,r)),selections:n}},getSelectionKeys:()=>0===e.length?[]:o(e[0])})})},map:function(...e){return u({[t]:()=>({match:t=>{if(!(t instanceof Map))return {matched:!1};let n={};if(0===t.size)return {matched:!0,selections:n};const r=(t,e)=>{n[t]=(n[t]||[]).concat([e]);};if(0===e.length)return {matched:!0};var i;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()}`);const[o,c]=e;return {matched:g(t,(t,e)=>{const n=s(o,e,r),i=s(c,t,r);return n&&i}),selections:n}},getSelectionKeys:()=>0===e.length?[]:[...o(e[0]),...o(e[1])]})})},intersection:m,union:y,not:function(e){return u({[t]:()=>({match:t=>({matched:!s(e,t,()=>{})}),getSelectionKeys:()=>[],matcherType:"not"})})},when:d,select:p,any:S,_:O,string:E,number:A,bigint:P,boolean:T,symbol:k,nullish:B,instanceOf:function(t){return u(d(function(t){return e=>e instanceof t}(t)))},shape:function(t){return u(d(a(t)))}};const W={matched:!1,value:void 0};function N(t){return new $(t,W)}class ${constructor(t,e){this.input=void 0,this.state=void 0,this.input=t,this.state=e;}with(...t){if(this.state.matched)return this;const e=t[t.length-1],r=[t[0]];let i;3===t.length&&"function"==typeof t[1]?(r.push(t[0]),i=t[1]):t.length>2&&r.push(...t.slice(1,t.length-1));let o=!1,c={};const a=(t,e)=>{o=!0,c[t]=e;},u=!r.some(t=>s(t,this.input,a))||i&&!Boolean(i(this.input))?W:{matched:!0,value:e(o?n in c?c[n]:c:this.input,this.input)};return new $(this.input,u)}when(t,e){if(this.state.matched)return this;const n=Boolean(t(this.input));return new $(this.input,n?{matched:!0,value:e(this.input,this.input)}:W)}otherwise(t){return this.state.matched?this.state.value:t(this.input)}exhaustive(){return this.run()}run(){if(this.state.matched)return this.state.value;let t;try{t=JSON.stringify(this.input);}catch(e){t=this.input;}throw new Error(`Pattern matching error: no pattern matches value ${t}`)}returnType(){return this}}
6868
6567
 
6869
- function isDestructuredFromPragma(variableName, context) {
6870
- const maybePragma = getPragmaFromContext(context);
6568
+ function isPropertyOfPragma(name, context, pragma = getPragmaFromContext(context)) {
6569
+ const isMatch = a({
6570
+ type: NodeType.MemberExpression,
6571
+ object: {
6572
+ type: NodeType.Identifier,
6573
+ name: pragma
6574
+ },
6575
+ property: {
6576
+ name
6577
+ }
6578
+ });
6579
+ return isMatch;
6580
+ }
6581
+
6582
+ function isInitializedFromPragma(variableName, context, pragma = getPragmaFromContext(context)) {
6871
6583
  const variables = getVariablesUpToGlobal(context.getScope());
6872
- if (effectEither_esm.isLeft(maybePragma)) {
6873
- return false;
6874
- }
6875
- const pragma = maybePragma.right;
6876
- const maybeLatestDef = effectFunction_esm.pipe(findVariableByName(variableName)(variables), effectOption_esm.flatMapNullable((variable)=>variable.defs.at(-1)));
6584
+ const maybeVariable = findVariableByName(variableName)(variables);
6585
+ const maybeLatestDef = effectOption_esm.flatMapNullable(maybeVariable, (variable)=>variable.defs.at(-1));
6877
6586
  if (effectOption_esm.isNone(maybeLatestDef)) {
6878
6587
  return false;
6879
6588
  }
@@ -6929,32 +6638,24 @@ function isDestructuredFromPragma(variableName, context) {
6929
6638
  }
6930
6639
  }, parent);
6931
6640
  }
6932
-
6933
6641
  /**
6934
6642
  * Checks if the given node is a call expression to the given function or method of the pragma
6935
6643
  * @param name The name of the function or method to check
6936
6644
  * @returns A predicate that checks if the given node is a call expression to the given function or method
6937
- */ const isCallFromPragma = (name)=>(node, context)=>{
6645
+ */ function isCallFromPragma(name) {
6646
+ return (node, context)=>{
6938
6647
  if (node.type !== NodeType.CallExpression || !("callee" in node)) {
6939
6648
  return false;
6940
6649
  }
6941
- const maybePragma = getPragmaFromContext(context);
6942
- if (effectEither_esm.isLeft(maybePragma)) {
6943
- return false;
6650
+ if (node.callee.type === NodeType.MemberExpression) {
6651
+ return isPropertyOfPragma(name, context)(node.callee);
6944
6652
  }
6945
- const pragma = maybePragma.right;
6946
- return N(node.callee).with({
6947
- type: NodeType.MemberExpression,
6948
- object: {
6949
- name: pragma
6950
- },
6951
- property: {
6952
- name
6953
- }
6954
- }, effectFunction_esm.constTrue).with({
6955
- name
6956
- }, ({ name })=>isDestructuredFromPragma(name, context)).otherwise(effectFunction_esm.constFalse);
6653
+ if ("name" in node.callee && node.callee.name === name) {
6654
+ return isInitializedFromPragma(name, context);
6655
+ }
6656
+ return false;
6957
6657
  };
6658
+ }
6958
6659
 
6959
6660
  /**
6960
6661
  * Checks if the given node is a call expression to `createElement`
@@ -6977,6 +6678,21 @@ function isChildrenOfCreateElement(node, context) {
6977
6678
  return maybeCallExpression.arguments.slice(2).some((child)=>child === node);
6978
6679
  }
6979
6680
 
6681
+ /**
6682
+ * Check if a node is a `JSXElement` of `User-Defined Component` type
6683
+ * @param node The AST node to check
6684
+ * @returns `true` if the node is a `JSXElement` of `User-Defined Component` type
6685
+ */ function isJSXElementOfUserDefinedComponent(node) {
6686
+ return node.type === NodeType.JSXElement && node.openingElement.name.type === NodeType.JSXIdentifier && /^[A-Z]/u.test(node.openingElement.name.name);
6687
+ }
6688
+ /**
6689
+ * Check if a node is a `JSXFragment` of `Built-in Component` type
6690
+ * @param node The AST node to check
6691
+ * @returns `true` if the node is a `JSXFragment` of `Built-in Component` type
6692
+ */ function isJSXElementOfBuiltinComponent(node) {
6693
+ return node.type === NodeType.JSXElement && node.openingElement.name.type === NodeType.JSXIdentifier && node.openingElement.name.name.toLowerCase() === node.openingElement.name.name && /^[a-z]/u.test(node.openingElement.name.name);
6694
+ }
6695
+
6980
6696
  /**
6981
6697
  * Determines whether inside createElement's props.
6982
6698
  * @param node The AST node to check
@@ -7133,21 +6849,87 @@ const hdlWheel = [
7133
6849
  ];
7134
6850
 
7135
6851
  /**
7136
- * Tests if a value is a `string`.
7137
- *
7138
- * @param input - The value to test.
7139
- *
7140
- * @example
7141
- * import { isString } from "effect/Predicate"
7142
- *
7143
- * assert.deepStrictEqual(isString("a"), true)
7144
- *
7145
- * assert.deepStrictEqual(isString(1), false)
7146
- *
7147
- * @category guards
7148
- * @since 2.0.0
7149
- */
7150
- const isString = input => typeof input === "string";
6852
+ * Check if a node is a Literal or JSXText
6853
+ * @param node The AST node to check
6854
+ * @returns boolean `true` if the node is a Literal or JSXText
6855
+ */ const isLiteral = isOneOf([
6856
+ NodeType.Literal,
6857
+ NodeType.JSXText
6858
+ ]);
6859
+ /**
6860
+ * Check if a Literal or JSXText node is whitespace
6861
+ * @param node The AST node to check
6862
+ * @returns boolean `true` if the node is whitespace
6863
+ */ function isWhiteSpace(node) {
6864
+ return isString(node.value) && node.value.trim() === "";
6865
+ }
6866
+ /**
6867
+ * Check if a Literal or JSXText node is a line break
6868
+ * @param node The AST node to check
6869
+ * @returns boolean
6870
+ */ function isLineBreak(node) {
6871
+ return isLiteral(node) && isWhiteSpace(node) && isMultiLine(node);
6872
+ }
6873
+ /**
6874
+ * Check if a Literal or JSXText node is padding spaces
6875
+ * @param node The AST node to check
6876
+ * @returns boolean
6877
+ */ function isPaddingSpaces(node) {
6878
+ return isLiteral(node) && isWhiteSpace(node) && node.raw.includes("\n");
6879
+ }
6880
+
6881
+ const isFragment = (node, pragma, fragment)=>{
6882
+ if (!isOneOf([
6883
+ NodeType.JSXElement,
6884
+ NodeType.JSXFragment
6885
+ ])(node)) {
6886
+ return false;
6887
+ }
6888
+ return isFragmentSyntax(node) || isFragmentElement(node, pragma, fragment);
6889
+ };
6890
+ /**
6891
+ * Check if a node is `<></>`
6892
+ */ const isFragmentSyntax = is(NodeType.JSXFragment);
6893
+ /**
6894
+ * Check if a node is `<Fragment></Fragment>` or `<Pragma.Fragment></Pragma.Fragment>`
6895
+ * @param node
6896
+ * @param pragma
6897
+ * @param fragment
6898
+ */ function isFragmentElement(node, pragma, fragment) {
6899
+ const { name } = node.openingElement;
6900
+ // <Fragment>
6901
+ if (name.type === NodeType.JSXIdentifier && name.name === fragment) {
6902
+ return true;
6903
+ }
6904
+ // <Pragma.Fragment>
6905
+ return name.type === NodeType.JSXMemberExpression && name.object.type === NodeType.JSXIdentifier && name.object.name === pragma && name.property.name === fragment;
6906
+ }
6907
+ /**
6908
+ * Check if a JSXElement or JSXFragment has only one literal child and is not a child
6909
+ * @param node The AST node to check
6910
+ * @returns `true` if the node has only one literal child and is not a child
6911
+ * @example Somehow fragment like this is useful: <Foo content={<>ee eeee eeee ...</>} />
6912
+ */ function isFragmentWithOnlyTextAndIsNotChild(node) {
6913
+ return node.children.length === 1 && isLiteral(node.children[0]) && !(node.parent.type === NodeType.JSXElement || node.parent.type === NodeType.JSXFragment);
6914
+ }
6915
+ function containsCallExpression(node) {
6916
+ return node.type === NodeType.JSXExpressionContainer && node.expression.type === NodeType.CallExpression;
6917
+ }
6918
+ /**
6919
+ * Check if a JSXElement or JSXFragment has less than two non-padding children and the first child is not a call expression
6920
+ * @param node The AST node to check
6921
+ * @returns boolean
6922
+ */ function isFragmentHasLessThanTwoChildren(node) {
6923
+ const nonPaddingChildren = node.children.filter((child)=>!isPaddingSpaces(child));
6924
+ if (nonPaddingChildren.length === 1) {
6925
+ return !containsCallExpression(nonPaddingChildren[0]);
6926
+ }
6927
+ return nonPaddingChildren.length === 0;
6928
+ }
6929
+ function isFragmentWithSingleExpression(node) {
6930
+ const children = node.children.filter((child)=>!isPaddingSpaces(child));
6931
+ return children.length === 1 && children[0]?.type === NodeType.JSXExpressionContainer;
6932
+ }
7151
6933
 
7152
6934
  const defaultJSXValueCheckOptions = {
7153
6935
  ignoreNull: false,
@@ -7356,45 +7138,28 @@ const defaultJSXValueCheckOptions = {
7356
7138
  }));
7357
7139
  };
7358
7140
  }
7359
- function getPropValue(attribute, context) {
7141
+ /**
7142
+ * Gets and resolves the static value of a JSX attribute
7143
+ * @param attribute The JSX attribute to get the value of
7144
+ * @param context The rule context
7145
+ * @returns The static value of the given JSX attribute
7146
+ */ function getPropValue(attribute, context) {
7147
+ const scope = context.getScope();
7360
7148
  if (attribute.type === NodeType.JSXAttribute && "value" in attribute) {
7361
7149
  const { value } = attribute;
7362
7150
  if (value === null) {
7363
7151
  return effectOption_esm.none();
7364
7152
  }
7365
7153
  if (value.type === NodeType.Literal) {
7366
- return effectOption_esm.some(getStaticValue(value, context.getScope()));
7154
+ return effectOption_esm.some(getStaticValue(value, scope));
7367
7155
  }
7368
7156
  if (value.type === NodeType.JSXExpressionContainer) {
7369
- return effectOption_esm.some(getStaticValue(value.expression, context.getScope()));
7157
+ return effectOption_esm.some(getStaticValue(value.expression, scope));
7370
7158
  }
7371
7159
  return effectOption_esm.none();
7372
7160
  }
7373
7161
  const { argument } = attribute;
7374
- return effectOption_esm.some(getStaticValue(argument, context.getScope()));
7375
- }
7376
-
7377
- /**
7378
- * Check if a node is a Literal or JSXText
7379
- * @param node The AST node to check
7380
- * @returns boolean `true` if the node is a Literal or JSXText
7381
- */ const isLiteral = isOneOf([
7382
- NodeType.Literal,
7383
- NodeType.JSXText
7384
- ]);
7385
- /**
7386
- * Check if a Literal or JSXText node is whitespace
7387
- * @param node The AST node to check
7388
- * @returns boolean `true` if the node is whitespace
7389
- */ function isWhiteSpace(node) {
7390
- return isString(node.value) && node.value.trim() === "";
7391
- }
7392
- /**
7393
- * Check if a Literal or JSXText node is a line break
7394
- * @param node The AST node to check
7395
- * @returns boolean
7396
- */ function isLineBreak(node) {
7397
- return isLiteral(node) && isWhiteSpace(node) && isMultiLine(node);
7162
+ return effectOption_esm.some(getStaticValue(argument, scope));
7398
7163
  }
7399
7164
 
7400
7165
  exports.defaultJSXValueCheckOptions = defaultJSXValueCheckOptions;
@@ -7425,15 +7190,26 @@ exports.hdlTouch = hdlTouch;
7425
7190
  exports.hdlTransition = hdlTransition;
7426
7191
  exports.hdlWheel = hdlWheel;
7427
7192
  exports.isCallFromPragma = isCallFromPragma;
7193
+ exports.isChildOfJSXElement = isChildOfJSXElement;
7428
7194
  exports.isChildrenOfCreateElement = isChildrenOfCreateElement;
7429
7195
  exports.isCloneElementCall = isCloneElementCall;
7430
7196
  exports.isCreateElementCall = isCreateElementCall;
7431
- exports.isDestructuredFromPragma = isDestructuredFromPragma;
7197
+ exports.isFragment = isFragment;
7198
+ exports.isFragmentElement = isFragmentElement;
7199
+ exports.isFragmentHasLessThanTwoChildren = isFragmentHasLessThanTwoChildren;
7200
+ exports.isFragmentSyntax = isFragmentSyntax;
7201
+ exports.isFragmentWithOnlyTextAndIsNotChild = isFragmentWithOnlyTextAndIsNotChild;
7202
+ exports.isFragmentWithSingleExpression = isFragmentWithSingleExpression;
7432
7203
  exports.isFunctionReturningJSXValue = isFunctionReturningJSXValue;
7204
+ exports.isInitializedFromPragma = isInitializedFromPragma;
7433
7205
  exports.isInsideCreateElementProps = isInsideCreateElementProps;
7434
7206
  exports.isInsidePropValue = isInsidePropValue;
7207
+ exports.isJSXElementOfBuiltinComponent = isJSXElementOfBuiltinComponent;
7208
+ exports.isJSXElementOfUserDefinedComponent = isJSXElementOfUserDefinedComponent;
7435
7209
  exports.isJSXValue = isJSXValue;
7436
7210
  exports.isLineBreak = isLineBreak;
7437
7211
  exports.isLiteral = isLiteral;
7212
+ exports.isPaddingSpaces = isPaddingSpaces;
7213
+ exports.isPropertyOfPragma = isPropertyOfPragma;
7438
7214
  exports.isWhiteSpace = isWhiteSpace;
7439
7215
  exports.traverseUpProp = traverseUpProp;