@eslint-react/jsx 0.6.0 → 0.6.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.
package/dist/index.cjs CHANGED
@@ -470,9 +470,10 @@ var effectFunction_esm = /*#__PURE__*/ Object.freeze({
470
470
  unsafeCoerce: unsafeCoerce,
471
471
  untupled: untupled
472
472
  });
473
+ const moduleVersion = "2.0.0-next.54";
473
474
  /**
474
475
  * @since 2.0.0
475
- */ const globalStoreId = /*#__PURE__*/ Symbol.for("effect/GlobalValue/globalStoreId");
476
+ */ const globalStoreId = /*#__PURE__*/ Symbol.for(`effect/GlobalValue/globalStoreId/${moduleVersion}`);
476
477
  if (!(globalStoreId in globalThis)) {
477
478
  globalThis[globalStoreId] = /*#__PURE__*/ new Map();
478
479
  }
@@ -516,7 +517,35 @@ const globalStore = globalThis[globalStoreId];
516
517
  *
517
518
  * @category guards
518
519
  * @since 2.0.0
519
- */ const isObject = (input)=>typeof input === "object" && input != null || isFunction(input);
520
+ */ const isObject = (input)=>typeof input === "object" && input !== null || isFunction(input);
521
+ /**
522
+ * Checks whether a value is an `object` containing a specified property key.
523
+ *
524
+ * @param property - The field to check within the object.
525
+ * @param self - The value to examine.
526
+ *
527
+ * @category guards
528
+ * @since 2.0.0
529
+ */ const hasProperty = /*#__PURE__*/ dual(2, (self, property)=>isObject(self) && property in self);
530
+ /**
531
+ * Tests if a value is an `object` with a property `_tag` that matches the given tag.
532
+ *
533
+ * @param input - The value to test.
534
+ * @param tag - The tag to test for.
535
+ *
536
+ * @example
537
+ * import { isTagged } from "effect/Predicate"
538
+ *
539
+ * assert.deepStrictEqual(isTagged(1, "a"), false)
540
+ * assert.deepStrictEqual(isTagged(null, "a"), false)
541
+ * assert.deepStrictEqual(isTagged({}, "a"), false)
542
+ * assert.deepStrictEqual(isTagged({ a: "a" }, "a"), false)
543
+ * assert.deepStrictEqual(isTagged({ _tag: "a" }, "a"), true)
544
+ * assert.deepStrictEqual(isTagged("a")({ _tag: "a" }), true)
545
+ *
546
+ * @category guards
547
+ * @since 2.0.0
548
+ */ const isTagged = /*#__PURE__*/ dual(2, (self, tag)=>hasProperty(self, "_tag") && self["_tag"] === tag);
520
549
  /**
521
550
  * A guard that succeeds when the input is `null` or `undefined`.
522
551
  *
@@ -895,7 +924,7 @@ function add64(out, aHi, aLo, bHi, bLo) {
895
924
  /**
896
925
  * @since 2.0.0
897
926
  * @category guards
898
- */ const isHash = (u)=>typeof u === "object" && u !== null && symbol$1 in u;
927
+ */ const isHash = (u)=>hasProperty(u, symbol$1);
899
928
  /**
900
929
  * @since 2.0.0
901
930
  * @category hashing
@@ -982,7 +1011,7 @@ function compareBoth(self, that) {
982
1011
  /**
983
1012
  * @since 2.0.0
984
1013
  * @category guards
985
- */ const isEqual = (u)=>typeof u === "object" && u !== null && symbol in u;
1014
+ */ const isEqual = (u)=>hasProperty(u, symbol);
986
1015
  /**
987
1016
  * @since 2.0.0
988
1017
  * @category instances
@@ -1018,7 +1047,7 @@ function compareBoth(self, that) {
1018
1047
  */ /**
1019
1048
  * @since 2.0.0
1020
1049
  */ const toJSON = (x)=>{
1021
- if (typeof x === "object" && x !== null && "toJSON" in x && typeof x["toJSON"] === "function" && x["toJSON"].length === 0) {
1050
+ if (hasProperty(x, "toJSON") && isFunction(x["toJSON"]) && x["toJSON"].length === 0) {
1022
1051
  return x.toJSON();
1023
1052
  } else if (Array.isArray(x)) {
1024
1053
  return x.map(toJSON);
@@ -1112,10 +1141,11 @@ function compareBoth(self, that) {
1112
1141
  /** @internal */ const StreamTypeId = /*#__PURE__*/ Symbol.for("effect/Stream");
1113
1142
  /** @internal */ const SinkTypeId = /*#__PURE__*/ Symbol.for("effect/Sink");
1114
1143
  /** @internal */ const ChannelTypeId = /*#__PURE__*/ Symbol.for("effect/Channel");
1115
- /** @internal */ const effectVariance$1 = {
1144
+ /** @internal */ const effectVariance = {
1116
1145
  _R: (_)=>_,
1117
1146
  _E: (_)=>_,
1118
- _A: (_)=>_
1147
+ _A: (_)=>_,
1148
+ _V: moduleVersion
1119
1149
  };
1120
1150
  /** @internal */ const sinkVariance = {
1121
1151
  _R: (_)=>_,
@@ -1134,8 +1164,8 @@ function compareBoth(self, that) {
1134
1164
  _OutDone: (_)=>_
1135
1165
  };
1136
1166
  /** @internal */ const EffectPrototype = {
1137
- [EffectTypeId$1]: effectVariance$1,
1138
- [StreamTypeId]: effectVariance$1,
1167
+ [EffectTypeId$1]: effectVariance,
1168
+ [StreamTypeId]: effectVariance,
1139
1169
  [SinkTypeId]: sinkVariance,
1140
1170
  [ChannelTypeId]: channelVariance,
1141
1171
  [symbol] (that) {
@@ -1204,7 +1234,7 @@ const NoneProto = /*#__PURE__*/ Object.assign(/*#__PURE__*/ Object.create(Common
1204
1234
  };
1205
1235
  }
1206
1236
  });
1207
- /** @internal */ const isOption$1 = (input)=>typeof input === "object" && input != null && TypeId$8 in input;
1237
+ /** @internal */ const isOption$1 = (input)=>hasProperty(input, TypeId$8);
1208
1238
  /** @internal */ const isNone$1 = (fa)=>fa._tag === "None";
1209
1239
  /** @internal */ const isSome$1 = (fa)=>fa._tag === "Some";
1210
1240
  /** @internal */ const none$1 = /*#__PURE__*/ Object.create(NoneProto);
@@ -1264,7 +1294,7 @@ const LeftProto = /*#__PURE__*/ Object.assign(/*#__PURE__*/ Object.create(Common
1264
1294
  };
1265
1295
  }
1266
1296
  });
1267
- /** @internal */ const isEither$1 = (input)=>typeof input === "object" && input != null && TypeId$7 in input;
1297
+ /** @internal */ const isEither$1 = (input)=>hasProperty(input, TypeId$7);
1268
1298
  /** @internal */ const isLeft$1 = (ma)=>ma._tag === "Left";
1269
1299
  /** @internal */ const isRight$1 = (ma)=>ma._tag === "Right";
1270
1300
  /** @internal */ const left$1 = (left)=>{
@@ -2291,7 +2321,7 @@ const emptyArray = [];
2291
2321
  *
2292
2322
  * @category equivalence
2293
2323
  * @since 2.0.0
2294
- */ const getEquivalence$1 = (isEquivalent)=>make$7((self, that)=>toReadonlyArray$1(self).every((value, i)=>isEquivalent(value, unsafeGet(that, i))));
2324
+ */ const getEquivalence$1 = (isEquivalent)=>make$7((self, that)=>self.length === that.length && toReadonlyArray$1(self).every((value, i)=>isEquivalent(value, unsafeGet(that, i))));
2295
2325
  const _equivalence$1 = /*#__PURE__*/ getEquivalence$1(equals);
2296
2326
  const ChunkProto = {
2297
2327
  [TypeId$4]: {
@@ -2387,7 +2417,7 @@ const makeChunk = (backing)=>{
2387
2417
  *
2388
2418
  * @category constructors
2389
2419
  * @since 2.0.0
2390
- */ const isChunk = (u)=>isObject(u) && TypeId$4 in u;
2420
+ */ const isChunk = (u)=>hasProperty(u, TypeId$4);
2391
2421
  const _empty$4 = /*#__PURE__*/ makeChunk({
2392
2422
  _tag: "IEmpty"
2393
2423
  });
@@ -2715,7 +2745,7 @@ const copyToArray = (self, array, initial)=>{
2715
2745
  ...EffectPrototype,
2716
2746
  _tag: "Tag",
2717
2747
  _op: "Tag",
2718
- [STMTypeId]: effectVariance$1,
2748
+ [STMTypeId]: effectVariance,
2719
2749
  [TagTypeId]: {
2720
2750
  _S: (_)=>_,
2721
2751
  _I: (_)=>_
@@ -2803,7 +2833,7 @@ const tagRegistry = /*#__PURE__*/ globalValue("effect/Context/Tag/tagRegistry",
2803
2833
  context.unsafeMap = unsafeMap;
2804
2834
  return context;
2805
2835
  };
2806
- /** @internal */ const isContext = (u)=>typeof u === "object" && u !== null && TypeId$3 in u;
2836
+ /** @internal */ const isContext = (u)=>hasProperty(u, TypeId$3);
2807
2837
  const _empty$3 = /*#__PURE__*/ makeContext(/*#__PURE__*/ new Map());
2808
2838
  /** @internal */ const empty$7 = ()=>_empty$3;
2809
2839
  /** @internal */ const make$4 = (tag, service)=>makeContext(new Map([
@@ -3091,7 +3121,7 @@ const makeUpdateService = (tag, update)=>{
3091
3121
  }
3092
3122
  }
3093
3123
  /** @internal */ function isEmptyNode(a) {
3094
- return typeof a === "object" && a !== null && "_tag" in a && a._tag === "EmptyNode";
3124
+ return isTagged(a, "EmptyNode");
3095
3125
  }
3096
3126
  /** @internal */ function isLeafNode(node) {
3097
3127
  return isEmptyNode(node) || node._tag === "LeafNode" || node._tag === "CollisionNode";
@@ -3442,7 +3472,7 @@ const visitLazyChildren = (len, children, i, f, cont)=>{
3442
3472
  };
3443
3473
  const _empty$1 = /*#__PURE__*/ makeImpl$1(false, 0, /*#__PURE__*/ new EmptyNode(), 0);
3444
3474
  /** @internal */ const empty$4 = ()=>_empty$1;
3445
- /** @internal */ const isHashMap = (u)=>isObject(u) && HashMapTypeId in u;
3475
+ /** @internal */ const isHashMap = (u)=>hasProperty(u, HashMapTypeId);
3446
3476
  /** @internal */ const getHash = /*#__PURE__*/ dual(3, (self, key, hash)=>{
3447
3477
  let node = self._root;
3448
3478
  let shift = 0;
@@ -3576,7 +3606,7 @@ const _empty$1 = /*#__PURE__*/ makeImpl$1(false, 0, /*#__PURE__*/ new EmptyNode(
3576
3606
  set._keyMap = keyMap;
3577
3607
  return set;
3578
3608
  };
3579
- /** @internal */ const isHashSet = (u)=>isObject(u) && HashSetTypeId in u;
3609
+ /** @internal */ const isHashSet = (u)=>hasProperty(u, HashSetTypeId);
3580
3610
  const _empty = /*#__PURE__*/ makeImpl(/*#__PURE__*/ empty$4());
3581
3611
  /** @internal */ const empty$3 = ()=>_empty;
3582
3612
  /** @internal */ const size$2 = (self)=>size$3(self._keyMap);
@@ -3907,7 +3937,7 @@ var effectMutableRef_esm = /*#__PURE__*/ Object.freeze({
3907
3937
  // -----------------------------------------------------------------------------
3908
3938
  // Refinements
3909
3939
  // -----------------------------------------------------------------------------
3910
- /** @internal */ const isCause = (u)=>typeof u === "object" && u != null && CauseTypeId in u;
3940
+ /** @internal */ const isCause = (u)=>hasProperty(u, CauseTypeId);
3911
3941
  /** @internal */ const isInterruptedOnly = (self)=>reduceWithContext(undefined, IsInterruptedOnlyCauseReducer)(self);
3912
3942
  /** @internal */ const causeEquals = (left, right)=>{
3913
3943
  let leftStack = of$1(left);
@@ -4277,7 +4307,7 @@ class PrettyError {
4277
4307
  return `Error: ${u}`;
4278
4308
  }
4279
4309
  // 2)
4280
- if (typeof u === "object" && u != null && "toString" in u && typeof u["toString"] === "function" && u["toString"] !== Object.prototype.toString) {
4310
+ if (hasProperty(u, "toString") && isFunction(u["toString"]) && u["toString"] !== Object.prototype.toString) {
4281
4311
  return u["toString"]();
4282
4312
  }
4283
4313
  // 3)
@@ -4285,8 +4315,8 @@ class PrettyError {
4285
4315
  };
4286
4316
  const spanSymbol$1 = /*#__PURE__*/ Symbol.for("effect/SpanAnnotation");
4287
4317
  const defaultRenderError = (error)=>{
4288
- const span = typeof error === "object" && error !== null && spanSymbol$1 in error && error[spanSymbol$1];
4289
- if (typeof error === "object" && error !== null && error instanceof Error) {
4318
+ const span = hasProperty(error, spanSymbol$1) && error[spanSymbol$1];
4319
+ if (error instanceof Error) {
4290
4320
  return new PrettyError(prettyErrorMessage(error), error.stack?.split("\n").filter((_)=>_.match(/at (.*)/)).join("\n"), span);
4291
4321
  }
4292
4322
  return new PrettyError(prettyErrorMessage(error), void 0, span);
@@ -4386,11 +4416,6 @@ const defaultRenderError = (error)=>{
4386
4416
  return this.toJSON();
4387
4417
  }
4388
4418
  }
4389
- /** @internal */ const effectVariance = {
4390
- _R: (_)=>_,
4391
- _E: (_)=>_,
4392
- _A: (_)=>_
4393
- };
4394
4419
  /* @internal */ const withFiberRuntime = (withRuntime)=>{
4395
4420
  const effect = new EffectPrimitive(OP_WITH_RUNTIME);
4396
4421
  effect.i0 = withRuntime;
@@ -4418,7 +4443,7 @@ const originalSymbol = /*#__PURE__*/ Symbol.for("effect/OriginalAnnotation");
4418
4443
  }
4419
4444
  return obj;
4420
4445
  };
4421
- /* @internal */ const fail$1 = (error)=>typeof error === "object" && error !== null && !(spanSymbol in error) ? withFiberRuntime((fiber)=>failCause(fail$2(capture(error, currentSpanFromFiber(fiber))))) : failCause(fail$2(error));
4446
+ /* @internal */ const fail$1 = (error)=>isObject(error) && !(spanSymbol in error) ? withFiberRuntime((fiber)=>failCause(fail$2(capture(error, currentSpanFromFiber(fiber))))) : failCause(fail$2(error));
4422
4447
  /* @internal */ const failCause = (cause)=>{
4423
4448
  const effect = new EffectPrimitiveFailure(OP_FAILURE);
4424
4449
  effect.i0 = cause;
@@ -4464,14 +4489,14 @@ const originalSymbol = /*#__PURE__*/ Symbol.for("effect/OriginalAnnotation");
4464
4489
  *
4465
4490
  * @see https://github.com/oven-sh/bun/issues/3333
4466
4491
  */ /** @internal */ typeof process === "undefined" ? false : !!process?.isBun;
4467
- /**
4468
- * @since 2.0.0
4469
- * @category constructors
4470
- */ const fail = fail$1;
4471
4492
  /**
4472
4493
  * @since 2.0.0
4473
4494
  * @category prototypes
4474
4495
  */ const StructuralCommitPrototype = StructuralCommitPrototype$1;
4496
+ /**
4497
+ * @since 2.0.0
4498
+ * @category constructors
4499
+ */ const fail = fail$1;
4475
4500
  /**
4476
4501
  * @since 2.0.0
4477
4502
  */ /**
@@ -6498,13 +6523,24 @@ function isStringLiteral(node) {
6498
6523
  */ function findVariableByNameUpToGlobal(name, startScope) {
6499
6524
  return effectFunction_esm.pipe(getVariablesUpToGlobal(startScope), findVariableByName(name));
6500
6525
  }
6526
+ /**
6527
+ * Get the first definition of a variable
6528
+ * @param variable The variable to get the definition from
6529
+ */ function getVariableDefinitionFirst(variable) {
6530
+ return effectOption_esm.fromNullable(variable.defs[0]);
6531
+ }
6501
6532
  /**
6502
6533
  * Get the init node of the nth definition of a variable
6503
- * @param at The index of the definition to get, negative numbers are counted from the end, -1 is the last definition
6504
- */ function getVariableNthDefNodeInit(at) {
6505
- return (variable)=>{
6506
- return effectFunction_esm.pipe(effectOption_esm.some(variable), effectOption_esm.flatMapNullable((v)=>v.defs.at(at)), effectOption_esm.flatMapNullable((d)=>d.node), effectOption_esm.flatMapNullable((n)=>"init" in n ? n.init : null));
6507
- };
6534
+ * @param variable
6535
+ * @param getDefinition A function that returns the nth definition of a variable
6536
+ */ function getVariableInit(variable, getDefinition) {
6537
+ return effectFunction_esm.pipe(effectOption_esm.some(variable), effectOption_esm.flatMap(getDefinition), effectOption_esm.flatMapNullable((d)=>d.node), effectOption_esm.flatMapNullable((n)=>"init" in n ? n.init : null));
6538
+ }
6539
+ /**
6540
+ * Get the init node of the first definition of a variable
6541
+ * @param variable
6542
+ */ function getVariableInitFirst(variable) {
6543
+ return getVariableInit(variable, getVariableDefinitionFirst);
6508
6544
  }
6509
6545
 
6510
6546
  /**
@@ -6563,7 +6599,7 @@ const getPragmaFromContext = memo((context)=>{
6563
6599
  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
6600
  });
6565
6601
 
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}}
6602
+ 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 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"})})}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}u(d(function(t){return !0}));const 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;}});j(d(b));const 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)))});K(d(v));const 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)))});x(d(w));u(d(function(t){return "boolean"==typeof t}));u(d(function(t){return "symbol"==typeof t}));u(d(function(t){return null==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}}
6567
6603
 
6568
6604
  function isPropertyOfPragma(name, context, pragma = getPragmaFromContext(context)) {
6569
6605
  const isMatch = a({
@@ -6931,190 +6967,175 @@ function isFragmentWithSingleExpression(node) {
6931
6967
  return children.length === 1 && children[0]?.type === NodeType.JSXExpressionContainer;
6932
6968
  }
6933
6969
 
6934
- const defaultJSXValueCheckOptions = {
6935
- ignoreNull: false,
6936
- strict: false
6970
+ /* eslint-disable perfectionist/sort-objects */ const JSXValueCheckHint = {
6971
+ None: 0n,
6972
+ IgnoreNull: 1n << 0n,
6973
+ IgnoreCreateElement: 1n << 1n,
6974
+ StrictLogical: 1n << 2n,
6975
+ StrictConditional: 1n << 3n
6937
6976
  };
6938
- /**
6977
+ /* eslint-enable perfectionist/sort-objects */ /**
6939
6978
  * Check if a node is a JSX value
6940
6979
  * @param node The AST node to check
6941
6980
  * @param context The rule context
6942
- * @param options The `JSXValueCheckOptions` to use
6981
+ * @param hint The `JSXValueCheckHint` to use
6943
6982
  * @returns boolean
6944
- */ function isJSXValue(node, context, options = defaultJSXValueCheckOptions) {
6983
+ */ function isJSXValue(node, context, hint = JSXValueCheckHint.None) {
6945
6984
  if (!node) {
6946
6985
  return false;
6947
6986
  }
6948
- // TODO: implement strict mode
6949
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
6950
- const { ignoreNull = false, strict = false } = options;
6951
- return N(node.type).with(NodeType.JSXElement, effectFunction_esm.constTrue).with(NodeType.JSXFragment, effectFunction_esm.constTrue).with(NodeType.Literal, ()=>{
6952
- if (!("value" in node) || ignoreNull) {
6987
+ return N(node).with({
6988
+ type: NodeType.JSXElement
6989
+ }, effectFunction_esm.constTrue).with({
6990
+ type: NodeType.JSXFragment
6991
+ }, effectFunction_esm.constTrue).with({
6992
+ type: NodeType.Literal
6993
+ }, (node)=>{
6994
+ if (!("value" in node) || hint & JSXValueCheckHint.IgnoreNull) {
6953
6995
  return false;
6954
6996
  }
6955
6997
  return node.value === null;
6956
- }).with(NodeType.ConditionalExpression, ()=>{
6998
+ }).with({
6999
+ type: NodeType.ConditionalExpression
7000
+ }, (node)=>{
6957
7001
  if (!("consequent" in node)) {
6958
7002
  return false;
6959
7003
  }
6960
- const leftHasJSX = N(node.consequent).with(_.array(), (n)=>n.some((n)=>isJSXValue(n, context, options))).with(_.any, (n)=>isJSXValue(n, context, options)).exhaustive();
6961
- if (leftHasJSX) {
6962
- return true;
7004
+ function leftHasJSX(node) {
7005
+ if (!("consequent" in node)) {
7006
+ return false;
7007
+ }
7008
+ if (Array.isArray(node.consequent)) {
7009
+ return node.consequent.some((n)=>isJSXValue(n, context, hint));
7010
+ }
7011
+ return isJSXValue(node.consequent, context, hint);
6963
7012
  }
6964
- return "alternate" in node && isJSXValue(node.alternate, context, options);
6965
- }).with(NodeType.LogicalExpression, ()=>{
7013
+ function rightHasJSX(node) {
7014
+ return "alternate" in node && isJSXValue(node.alternate, context, hint);
7015
+ }
7016
+ if (hint & JSXValueCheckHint.StrictConditional) {
7017
+ return leftHasJSX(node) && rightHasJSX(node);
7018
+ }
7019
+ return leftHasJSX(node) || rightHasJSX(node);
7020
+ }).with({
7021
+ type: NodeType.LogicalExpression
7022
+ }, (node)=>{
6966
7023
  if (!("left" in node)) {
6967
7024
  return false;
6968
7025
  }
6969
- return isJSXValue(node.left, context, options) || isJSXValue(node.right, context, options);
6970
- }).with(NodeType.SequenceExpression, ()=>{
7026
+ return isJSXValue(node.left, context, hint) || isJSXValue(node.right, context, hint);
7027
+ }).with({
7028
+ type: NodeType.SequenceExpression
7029
+ }, (node)=>{
6971
7030
  if (!("expressions" in node)) {
6972
7031
  return false;
6973
7032
  }
6974
7033
  const exp = node.expressions.at(-1);
6975
- return isJSXValue(exp, context, options);
6976
- }).with(NodeType.CallExpression, ()=>isCreateElementCall(node, context)).with(NodeType.Identifier, ()=>{
7034
+ return isJSXValue(exp, context, hint);
7035
+ }).with({
7036
+ type: NodeType.CallExpression
7037
+ }, (node)=>{
7038
+ if (hint & JSXValueCheckHint.IgnoreCreateElement) {
7039
+ return false;
7040
+ }
7041
+ return isCreateElementCall(node, context);
7042
+ }).with({
7043
+ type: NodeType.Identifier
7044
+ }, (node)=>{
6977
7045
  if (!("name" in node)) {
6978
7046
  return false;
6979
7047
  }
6980
7048
  if (isJSXTagNameExpression(node)) {
6981
7049
  return true;
6982
7050
  }
6983
- if (!isString(node.name) && node.name.type !== NodeType.Identifier) {
6984
- return isJSXTagNameExpression(node.name);
6985
- }
6986
- const name = N(node.name).with(_.string, effectFunction_esm.identity).with({
6987
- type: NodeType.Identifier
6988
- }, (n)=>n.name).exhaustive();
6989
- const variable = findVariableByNameUpToGlobal(name, context.getScope());
6990
- return effectFunction_esm.pipe(variable, effectOption_esm.flatMap(getVariableNthDefNodeInit(0)), effectOption_esm.map(isOneOf([
7051
+ const variable = findVariableByNameUpToGlobal(node.name, context.getScope());
7052
+ return effectFunction_esm.pipe(variable, effectOption_esm.flatMap(getVariableInitFirst), effectOption_esm.filter(isOneOf([
6991
7053
  NodeType.JSXElement,
6992
7054
  NodeType.JSXFragment
6993
- ])), effectOption_esm.getOrElse(effectFunction_esm.constFalse));
6994
- }).otherwise(effectFunction_esm.constFalse);
7055
+ ])), effectOption_esm.isSome);
7056
+ }).with({
7057
+ type: NodeType.JSXMemberExpression
7058
+ }, effectFunction_esm.constTrue).with({
7059
+ type: NodeType.JSXNamespacedName
7060
+ }, effectFunction_esm.constTrue).otherwise(effectFunction_esm.constFalse);
6995
7061
  }
6996
7062
 
6997
7063
  /**
6998
7064
  * Check if function is returning JSX
6999
7065
  * @param node The return statement node to check
7000
7066
  * @param context The rule context
7001
- * @param options The JSX value check options
7067
+ * @param hint The `JSXValueCheckHint` to use
7002
7068
  * @returns boolean
7003
- */ function isFunctionReturningJSXValue(node, context, options) {
7069
+ */ function isFunctionReturningJSXValue(node, context, hint = JSXValueCheckHint.None) {
7004
7070
  if (node.body.type !== NodeType.BlockStatement) {
7005
- return isJSXValue(node.body, context, options);
7071
+ return isJSXValue(node.body, context, hint);
7006
7072
  }
7007
7073
  const statements = getNestedReturnStatements(node.body);
7008
- return statements.some((statement)=>isJSXValue(statement.argument, context, options));
7074
+ return statements.some((statement)=>isJSXValue(statement.argument, context, hint));
7009
7075
  }
7010
7076
 
7011
- /**
7012
- * Check if the given prop name is present in the given attributes
7013
- * @param attributes The attributes to search in
7014
- * @param propName The prop name to search for
7015
- * @param context The rule context
7016
- * @returns `true` if the given prop name is present in the given properties
7017
- */ function hasProp(attributes, propName, context) {
7018
- return effectOption_esm.isSome(findPropInAttributes(attributes, context)(propName));
7019
- }
7020
- /**
7021
- * Check if any of the given prop names are present in the given attributes
7022
- * @param attributes The attributes to search in
7023
- * @param propNames The prop names to search for
7024
- * @param context The rule context
7025
- * @returns `true` if any of the given prop names are present in the given attributes
7026
- */ function hasAnyProp(attributes, propNames, context) {
7027
- return propNames.some((propName)=>hasProp(attributes, propName, context));
7028
- }
7029
- /**
7030
- * Check if all of the given prop names are present in the given attributes
7031
- * @param attributes The attributes to search in
7032
- * @param propNames The prop names to search for
7033
- * @param context The rule context
7034
- * @returns `true` if all of the given prop names are present in the given attributes
7035
- */ function hasEveryProp(attributes, propNames, context) {
7036
- return propNames.every((propName)=>hasProp(attributes, propName, context));
7037
- }
7038
- /**
7039
- * Get the name of a JSX attribute
7040
- * @param node The JSX attribute node
7041
- * @returns string
7042
- */ function getPropName(node) {
7043
- return N(node.name).when(is(NodeType.JSXIdentifier), (n)=>n.name).when(is(NodeType.JSXNamespacedName), (n)=>n.name.name).exhaustive();
7044
- }
7045
- /**
7046
- * Get the name of a JSX attribute with namespace
7047
- * @param node The JSX attribute node
7048
- * @returns string
7049
- */ function getPropNameWithNamespace(node) {
7050
- return N(node.name).when(is(NodeType.JSXIdentifier), (n)=>n.name).when(is(NodeType.JSXNamespacedName), (n)=>`${n.namespace.name}:${n.name.name}`).exhaustive();
7051
- }
7052
- /**
7053
- * Traverses up prop node
7054
- * @param node The AST node to start traversing from
7055
- * @param predicate The predicate to check each node
7056
- * @returns prop node if found
7057
- */ function traverseUpProp(node, predicate = effectFunction_esm.constTrue) {
7058
- const matcher = (node)=>{
7059
- return node.type === NodeType.JSXAttribute && predicate(node);
7060
- };
7061
- return effectOption_esm.fromNullable(traverseUpGuard(node, matcher));
7062
- }
7063
- /**
7064
- * Checks if the node is inside a prop's value
7065
- * @param node The AST node to check
7066
- * @returns `true` if the node is inside a prop's value
7067
- */ function isInsidePropValue(node) {
7068
- if (isStringLiteral(node)) {
7069
- return node.parent.type === NodeType.JSXAttribute;
7070
- }
7071
- return effectOption_esm.isSome(traverseUpProp(node, (n)=>n.value?.type === NodeType.JSXExpressionContainer));
7072
- }
7073
7077
  /**
7074
7078
  * @param properties The properties to search in
7075
7079
  * @param context The rule context
7076
7080
  * @param seenProps The properties that have already been seen
7077
7081
  * @returns A function that searches for a property in the given properties
7078
7082
  */ function findPropInProperties(properties, context, seenProps = []) {
7083
+ const startScope = context.getScope();
7079
7084
  /**
7080
7085
  * Search for a property in the given properties
7081
7086
  * @param propName The name of the property to search for
7082
7087
  * @returns The property if found
7083
7088
  */ return (propName)=>{
7084
7089
  return effectOption_esm.fromNullable(properties.find((prop)=>{
7085
- if (prop.type === NodeType.Property) {
7090
+ return N(prop).when(is(NodeType.Property), (prop)=>{
7086
7091
  return "name" in prop.key && prop.key.name === propName;
7087
- }
7088
- if (prop.type === NodeType.SpreadElement) {
7089
- if (!("argument" in prop && "name" in prop.argument)) {
7090
- return false;
7091
- }
7092
- const { name } = prop.argument;
7093
- const maybeFirstDefNodeInit = effectFunction_esm.pipe(findVariableByNameUpToGlobal(name, context.getScope()), effectOption_esm.flatMap(getVariableNthDefNodeInit(0)));
7094
- if (effectOption_esm.isNone(maybeFirstDefNodeInit)) {
7095
- return false;
7096
- }
7097
- const firstDefNodeInit = maybeFirstDefNodeInit.value;
7098
- if (firstDefNodeInit.type !== NodeType.ObjectExpression) {
7099
- return false;
7100
- }
7101
- if (seenProps.includes(name)) {
7102
- return false;
7103
- }
7104
- return effectOption_esm.isSome(findPropInProperties(firstDefNodeInit.properties, context, [
7105
- ...seenProps,
7106
- name
7107
- ])(propName));
7108
- }
7109
- return false;
7092
+ }).when(is(NodeType.SpreadElement), (prop)=>{
7093
+ return N(prop.argument).when(is(NodeType.Identifier), (argument)=>{
7094
+ const { name } = argument;
7095
+ const maybeInit = effectOption_esm.flatMap(findVariableByNameUpToGlobal(name, startScope), getVariableInitFirst);
7096
+ if (effectOption_esm.isNone(maybeInit)) {
7097
+ return false;
7098
+ }
7099
+ const init = maybeInit.value;
7100
+ if (init.type !== NodeType.ObjectExpression) {
7101
+ return false;
7102
+ }
7103
+ if (seenProps.includes(name)) {
7104
+ return false;
7105
+ }
7106
+ return effectOption_esm.isSome(findPropInProperties(init.properties, context, [
7107
+ ...seenProps,
7108
+ name
7109
+ ])(propName));
7110
+ }).when(is(NodeType.ObjectExpression), (argument)=>{
7111
+ return effectOption_esm.isSome(findPropInProperties(argument.properties, context, seenProps)(propName));
7112
+ }).when(is(NodeType.MemberExpression), ()=>{
7113
+ // Not implemented
7114
+ }).when(is(NodeType.CallExpression), ()=>{
7115
+ // Not implemented
7116
+ }).otherwise(effectFunction_esm.constFalse);
7117
+ }).when(is(NodeType.RestElement), ()=>{
7118
+ // Not implemented
7119
+ return false;
7120
+ }).otherwise(effectFunction_esm.constFalse);
7110
7121
  }));
7111
7122
  };
7112
7123
  }
7124
+
7125
+ /**
7126
+ * Get the name of a JSX attribute with namespace
7127
+ * @param node The JSX attribute node
7128
+ * @returns string
7129
+ */ function getPropName(node) {
7130
+ return N(node.name).when(is(NodeType.JSXIdentifier), (n)=>n.name).when(is(NodeType.JSXNamespacedName), (n)=>`${n.namespace.name}:${n.name.name}`).exhaustive();
7131
+ }
7132
+
7113
7133
  /**
7114
7134
  * @param attributes The attributes to search in
7115
7135
  * @param context The rule context
7116
7136
  * @returns A function that searches for a property in the given attributes
7117
7137
  */ function findPropInAttributes(attributes, context) {
7138
+ const startScope = context.getScope();
7118
7139
  /**
7119
7140
  * Search for a property in the given attributes
7120
7141
  * @param propName The name of the property to search for
@@ -7122,22 +7143,36 @@ const defaultJSXValueCheckOptions = {
7122
7143
  */ return (propName)=>{
7123
7144
  return effectOption_esm.fromNullable(attributes.find((attr)=>{
7124
7145
  return N(attr).when(is(NodeType.JSXAttribute), (attr)=>getPropName(attr) === propName).when(is(NodeType.JSXSpreadAttribute), (attr)=>{
7125
- if (!("argument" in attr && "name" in attr.argument)) {
7126
- return false;
7127
- }
7128
- const { name } = attr.argument;
7129
- const maybeFirstDefNodeInit = effectFunction_esm.pipe(findVariableByNameUpToGlobal(name, context.getScope()), effectOption_esm.flatMap(getVariableNthDefNodeInit(0)));
7130
- if (effectOption_esm.isNone(maybeFirstDefNodeInit)) {
7146
+ return N(attr.argument).with({
7147
+ type: NodeType.Identifier
7148
+ }, (argument)=>{
7149
+ const { name } = argument;
7150
+ const maybeInit = effectOption_esm.flatMap(findVariableByNameUpToGlobal(name, startScope), getVariableInitFirst);
7151
+ if (effectOption_esm.isNone(maybeInit)) {
7152
+ return false;
7153
+ }
7154
+ const init = maybeInit.value;
7155
+ if (!("properties" in init)) {
7156
+ return false;
7157
+ }
7158
+ return effectOption_esm.isSome(findPropInProperties(init.properties, context)(propName));
7159
+ }).when(is(NodeType.ObjectExpression), (argument)=>{
7160
+ return effectOption_esm.isSome(findPropInProperties(argument.properties, context)(propName));
7161
+ }).when(is(NodeType.MemberExpression), ()=>{
7162
+ // Not implemented
7131
7163
  return false;
7132
- }
7133
- if (!("properties" in maybeFirstDefNodeInit.value)) {
7164
+ }).when(is(NodeType.CallExpression), ()=>{
7165
+ // Not implemented
7134
7166
  return false;
7135
- }
7136
- return effectOption_esm.isSome(findPropInProperties(maybeFirstDefNodeInit.value.properties, context)(propName));
7167
+ }).otherwise(effectFunction_esm.constFalse);
7137
7168
  }).otherwise(effectFunction_esm.constFalse);
7138
7169
  }));
7139
7170
  };
7140
7171
  }
7172
+
7173
+ function getProp(props, propName, context) {
7174
+ return findPropInAttributes(props, context)(propName);
7175
+ }
7141
7176
  /**
7142
7177
  * Gets and resolves the static value of a JSX attribute
7143
7178
  * @param attribute The JSX attribute to get the value of
@@ -7162,14 +7197,65 @@ const defaultJSXValueCheckOptions = {
7162
7197
  return effectOption_esm.some(getStaticValue(argument, scope));
7163
7198
  }
7164
7199
 
7165
- exports.defaultJSXValueCheckOptions = defaultJSXValueCheckOptions;
7200
+ /**
7201
+ * Check if the given prop name is present in the given attributes
7202
+ * @param attributes The attributes to search in
7203
+ * @param propName The prop name to search for
7204
+ * @param context The rule context
7205
+ * @returns `true` if the given prop name is present in the given properties
7206
+ */ function hasProp(attributes, propName, context) {
7207
+ return effectOption_esm.isSome(findPropInAttributes(attributes, context)(propName));
7208
+ }
7209
+ /**
7210
+ * Check if any of the given prop names are present in the given attributes
7211
+ * @param attributes The attributes to search in
7212
+ * @param propNames The prop names to search for
7213
+ * @param context The rule context
7214
+ * @returns `true` if any of the given prop names are present in the given attributes
7215
+ */ function hasAnyProp(attributes, propNames, context) {
7216
+ return propNames.some((propName)=>hasProp(attributes, propName, context));
7217
+ }
7218
+ /**
7219
+ * Check if all of the given prop names are present in the given attributes
7220
+ * @param attributes The attributes to search in
7221
+ * @param propNames The prop names to search for
7222
+ * @param context The rule context
7223
+ * @returns `true` if all of the given prop names are present in the given attributes
7224
+ */ function hasEveryProp(attributes, propNames, context) {
7225
+ return propNames.every((propName)=>hasProp(attributes, propName, context));
7226
+ }
7227
+
7228
+ /**
7229
+ * Traverses up prop node
7230
+ * @param node The AST node to start traversing from
7231
+ * @param predicate The predicate to check each node
7232
+ * @returns prop node if found
7233
+ */ function traverseUpProp(node, predicate = effectFunction_esm.constTrue) {
7234
+ const matcher = (node)=>{
7235
+ return node.type === NodeType.JSXAttribute && predicate(node);
7236
+ };
7237
+ return effectOption_esm.fromNullable(traverseUpGuard(node, matcher));
7238
+ }
7239
+
7240
+ /**
7241
+ * Checks if the node is inside a prop's value
7242
+ * @param node The AST node to check
7243
+ * @returns `true` if the node is inside a prop's value
7244
+ */ function isInsidePropValue(node) {
7245
+ if (isStringLiteral(node)) {
7246
+ return node.parent.type === NodeType.JSXAttribute;
7247
+ }
7248
+ return effectOption_esm.isSome(traverseUpProp(node, (n)=>n.value?.type === NodeType.JSXExpressionContainer));
7249
+ }
7250
+
7251
+ exports.JSXValueCheckHint = JSXValueCheckHint;
7166
7252
  exports.elementType = elementType;
7167
7253
  exports.findPropInAttributes = findPropInAttributes;
7168
7254
  exports.findPropInProperties = findPropInProperties;
7169
7255
  exports.getFragmentFromContext = getFragmentFromContext;
7170
7256
  exports.getPragmaFromContext = getPragmaFromContext;
7257
+ exports.getProp = getProp;
7171
7258
  exports.getPropName = getPropName;
7172
- exports.getPropNameWithNamespace = getPropNameWithNamespace;
7173
7259
  exports.getPropValue = getPropValue;
7174
7260
  exports.hasAnyProp = hasAnyProp;
7175
7261
  exports.hasChildren = hasChildren;