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