@eslint-react/core 3.0.0-next.70 → 3.0.0-next.71

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.d.ts CHANGED
@@ -627,14 +627,14 @@ declare function isHookName(name: string): boolean;
627
627
  type JsxAttributeValue = {
628
628
  kind: "missing";
629
629
  node: TSESTree.JSXEmptyExpression;
630
- toStatic(): "{}";
630
+ toStatic(): null;
631
631
  } | {
632
632
  kind: "boolean";
633
633
  toStatic(): true;
634
634
  } | {
635
635
  kind: "element";
636
636
  node: TSESTree.JSXElement;
637
- toStatic(): unknown;
637
+ toStatic(): null;
638
638
  } | {
639
639
  kind: "literal";
640
640
  node: TSESTree.Literal;
@@ -647,12 +647,12 @@ type JsxAttributeValue = {
647
647
  kind: "spreadProps";
648
648
  getProperty(name: string): unknown;
649
649
  node: TSESTree.JSXSpreadAttribute["argument"];
650
- toStatic(): unknown;
650
+ toStatic(): null;
651
651
  } | {
652
652
  kind: "spreadChild";
653
653
  getChildren(at: number): unknown;
654
654
  node: TSESTree.JSXSpreadChild["expression"];
655
- toStatic(): unknown;
655
+ toStatic(): null;
656
656
  };
657
657
  //#endregion
658
658
  //#region src/jsx/jsx-config.d.ts
@@ -786,9 +786,8 @@ declare class JsxInspector {
786
786
  * later props win), or `undefined` if not found.
787
787
  * @param node The JSX element to search for the attribute.
788
788
  * @param name The name of the attribute to find (e.g. `"className"`).
789
- * @param initialScope An optional scope to use for resolving spread attributes. If not provided,
790
789
  */
791
- findAttribute(node: TSESTree.JSXElement, name: string, initialScope?: Scope): ast.TSESTreeJSXAttributeLike | undefined;
790
+ findAttribute(node: TSESTree.JSXElement, name: string): ast.TSESTreeJSXAttributeLike | undefined;
792
791
  /**
793
792
  * Get the stringified name of a `JSXAttribute` node
794
793
  * (e.g. `"className"`, `"aria-label"`, `"xml:space"`).
@@ -810,10 +809,9 @@ declare class JsxInspector {
810
809
  * cannot be statically determined.
811
810
  * @param node The JSX element to search for the attribute.
812
811
  * @param name The name of the attribute to resolve (e.g. `"className"`).
813
- * @param initialScope An optional scope to use for resolving spread attributes. If not provided, the scope will be determined from the context of the attribute node.
814
812
  * @returns The static value of the attribute, or `undefined` if not found or not statically resolvable.
815
813
  */
816
- getAttributeStaticValue(node: TSESTree.JSXElement, name: string, initialScope?: Scope): unknown;
814
+ getAttributeStaticValue(node: TSESTree.JSXElement, name: string): unknown;
817
815
  /**
818
816
  * **All-in-one helper** – find an attribute by name on an element *and*
819
817
  * resolve its value in a single call.
@@ -821,10 +819,9 @@ declare class JsxInspector {
821
819
  * Returns `undefined` when the attribute is not present.
822
820
  * @param node The JSX element to search for the attribute.
823
821
  * @param name The name of the attribute to find and resolve (e.g. `"className"`).
824
- * @param initialScope An optional scope to use for resolving spread attributes. If not provided, the scope will be determined from the context of the attribute node.
825
822
  * @returns A descriptor of the attribute's value that can be further inspected, or `undefined` if the attribute is not found.
826
823
  */
827
- getAttributeValue(node: TSESTree.JSXElement, name: string, initialScope?: Scope): JsxAttributeValue | undefined;
824
+ getAttributeValue(node: TSESTree.JSXElement, name: string): JsxAttributeValue | undefined;
828
825
  /**
829
826
  * Get the **self name** (last segment) of a JSX element type.
830
827
  *
@@ -848,10 +845,9 @@ declare class JsxInspector {
848
845
  * Shorthand: check whether an attribute exists on the element.
849
846
  * @param node The JSX element to check for the attribute.
850
847
  * @param name The name of the attribute to check for (e.g. `"className"`).
851
- * @param initialScope An optional scope to use for resolving spread attributes. If not provided, the scope will be determined from the context of the attribute node.
852
848
  * @returns `true` if the attribute exists on the element, `false` otherwise.
853
849
  */
854
- hasAttribute(node: TSESTree.JSXElement, name: string, initialScope?: Scope): boolean;
850
+ hasAttribute(node: TSESTree.JSXElement, name: string): boolean;
855
851
  /**
856
852
  * Whether the node is a React **Fragment** element (either `<Fragment>` /
857
853
  * `<React.Fragment>` or the shorthand `<>` syntax).
@@ -887,7 +883,7 @@ declare class JsxInspector {
887
883
  } | {
888
884
  readonly kind: "missing";
889
885
  readonly node: TSESTree.JSXEmptyExpression;
890
- readonly toStatic: () => "{}";
886
+ readonly toStatic: () => null;
891
887
  readonly getChildren?: never;
892
888
  } | {
893
889
  readonly kind: "expression";
@@ -901,14 +897,14 @@ declare class JsxInspector {
901
897
  readonly getChildren?: never;
902
898
  } | {
903
899
  readonly kind: "spreadChild";
904
- readonly getChildren: (_at: number) => null;
905
900
  readonly node: TSESTree.JSXEmptyExpression | TSESTree.Expression;
906
- readonly toStatic: () => unknown;
901
+ readonly toStatic: () => null;
902
+ readonly getChildren: (_at: number) => null;
907
903
  } | {
908
904
  readonly kind: "spreadProps";
909
- readonly getProperty: (name: string) => unknown;
910
905
  readonly node: TSESTree.Expression;
911
- readonly toStatic: () => unknown;
906
+ readonly toStatic: () => null;
907
+ readonly getProperty: (name: string) => unknown;
912
908
  };
913
909
  }
914
910
  //#endregion
package/dist/index.js CHANGED
@@ -596,10 +596,8 @@ var JsxInspector = class JsxInspector {
596
596
  * later props win), or `undefined` if not found.
597
597
  * @param node The JSX element to search for the attribute.
598
598
  * @param name The name of the attribute to find (e.g. `"className"`).
599
- * @param initialScope An optional scope to use for resolving spread attributes. If not provided,
600
599
  */
601
- findAttribute(node, name, initialScope) {
602
- initialScope ?? this.context.sourceCode.getScope(node);
600
+ findAttribute(node, name) {
603
601
  return node.openingElement.attributes.findLast((attr) => {
604
602
  if (attr.type === AST_NODE_TYPES.JSXAttribute) return stringifyJsx(attr.name) === name;
605
603
  switch (attr.argument.type) {
@@ -636,11 +634,10 @@ var JsxInspector = class JsxInspector {
636
634
  * cannot be statically determined.
637
635
  * @param node The JSX element to search for the attribute.
638
636
  * @param name The name of the attribute to resolve (e.g. `"className"`).
639
- * @param initialScope An optional scope to use for resolving spread attributes. If not provided, the scope will be determined from the context of the attribute node.
640
637
  * @returns The static value of the attribute, or `undefined` if not found or not statically resolvable.
641
638
  */
642
- getAttributeStaticValue(node, name, initialScope) {
643
- const attr = this.findAttribute(node, name, initialScope);
639
+ getAttributeStaticValue(node, name) {
640
+ const attr = this.findAttribute(node, name);
644
641
  if (attr == null) return void 0;
645
642
  const resolved = this.resolveAttributeValue(attr);
646
643
  if (resolved.kind === "spreadProps") return resolved.getProperty(name);
@@ -653,11 +650,10 @@ var JsxInspector = class JsxInspector {
653
650
  * Returns `undefined` when the attribute is not present.
654
651
  * @param node The JSX element to search for the attribute.
655
652
  * @param name The name of the attribute to find and resolve (e.g. `"className"`).
656
- * @param initialScope An optional scope to use for resolving spread attributes. If not provided, the scope will be determined from the context of the attribute node.
657
653
  * @returns A descriptor of the attribute's value that can be further inspected, or `undefined` if the attribute is not found.
658
654
  */
659
- getAttributeValue(node, name, initialScope) {
660
- const attr = this.findAttribute(node, name, initialScope);
655
+ getAttributeValue(node, name) {
656
+ const attr = this.findAttribute(node, name);
661
657
  if (attr == null) return void 0;
662
658
  return this.resolveAttributeValue(attr);
663
659
  }
@@ -689,11 +685,10 @@ var JsxInspector = class JsxInspector {
689
685
  * Shorthand: check whether an attribute exists on the element.
690
686
  * @param node The JSX element to check for the attribute.
691
687
  * @param name The name of the attribute to check for (e.g. `"className"`).
692
- * @param initialScope An optional scope to use for resolving spread attributes. If not provided, the scope will be determined from the context of the attribute node.
693
688
  * @returns `true` if the attribute exists on the element, `false` otherwise.
694
689
  */
695
- hasAttribute(node, name, initialScope) {
696
- return this.findAttribute(node, name, initialScope) != null;
690
+ hasAttribute(node, name) {
691
+ return this.findAttribute(node, name) != null;
697
692
  }
698
693
  /**
699
694
  * Whether the node is a React **Fragment** element (either `<Fragment>` /
@@ -725,11 +720,11 @@ var JsxInspector = class JsxInspector {
725
720
  * @returns A descriptor of the attribute's value that can be further inspected.
726
721
  */
727
722
  resolveAttributeValue(attribute) {
728
- const initialScope = this.context.sourceCode.getScope(attribute);
729
- if (attribute.type === AST_NODE_TYPES.JSXAttribute) return this.#resolveJsxAttribute(attribute, initialScope);
730
- return this.#resolveJsxSpreadAttribute(attribute, initialScope);
723
+ if (attribute.type === AST_NODE_TYPES.JSXAttribute) return this.#resolveJsxAttribute(attribute);
724
+ return this.#resolveJsxSpreadAttribute(attribute);
731
725
  }
732
- #resolveJsxAttribute(node, initialScope) {
726
+ #resolveJsxAttribute(node) {
727
+ const scope = this.context.sourceCode.getScope(node);
733
728
  if (node.value == null) return {
734
729
  kind: "boolean",
735
730
  toStatic() {
@@ -753,14 +748,14 @@ var JsxInspector = class JsxInspector {
753
748
  kind: "missing",
754
749
  node: expr,
755
750
  toStatic() {
756
- return "{}";
751
+ return null;
757
752
  }
758
753
  };
759
754
  return {
760
755
  kind: "expression",
761
756
  node: expr,
762
757
  toStatic() {
763
- return getStaticValue(expr, initialScope)?.value;
758
+ return getStaticValue(expr, scope)?.value;
764
759
  }
765
760
  };
766
761
  }
@@ -771,30 +766,30 @@ var JsxInspector = class JsxInspector {
771
766
  return null;
772
767
  }
773
768
  };
774
- case AST_NODE_TYPES.JSXSpreadChild: {
775
- const expr = node.value.expression;
769
+ case AST_NODE_TYPES.JSXSpreadChild:
770
+ node.value.expression;
776
771
  return {
777
772
  kind: "spreadChild",
778
- getChildren(_at) {
779
- return null;
780
- },
781
773
  node: node.value.expression,
782
774
  toStatic() {
783
- return getStaticValue(expr, initialScope)?.value;
775
+ return null;
776
+ },
777
+ getChildren(_at) {
778
+ return null;
784
779
  }
785
780
  };
786
- }
787
781
  }
788
782
  }
789
- #resolveJsxSpreadAttribute(node, initialScope) {
783
+ #resolveJsxSpreadAttribute(node) {
784
+ const scope = this.context.sourceCode.getScope(node);
790
785
  return {
791
786
  kind: "spreadProps",
792
- getProperty(name) {
793
- return match(getStaticValue(node.argument, initialScope)?.value).with({ [name]: P.select(P.any) }, identity).otherwise(() => null);
794
- },
795
787
  node: node.argument,
796
788
  toStatic() {
797
- return getStaticValue(node.argument, initialScope)?.value;
789
+ return null;
790
+ },
791
+ getProperty(name) {
792
+ return match(getStaticValue(node.argument, scope)?.value).with({ [name]: P.select(P.any) }, identity).otherwise(() => null);
798
793
  }
799
794
  };
800
795
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/core",
3
- "version": "3.0.0-next.70",
3
+ "version": "3.0.0-next.71",
4
4
  "description": "ESLint React's ESLint utility module for static analysis of React core APIs and patterns.",
5
5
  "homepage": "https://github.com/Rel1cx/eslint-react",
6
6
  "bugs": {
@@ -34,10 +34,10 @@
34
34
  "@typescript-eslint/types": "canary",
35
35
  "@typescript-eslint/utils": "canary",
36
36
  "ts-pattern": "^5.9.0",
37
- "@eslint-react/ast": "3.0.0-next.70",
38
- "@eslint-react/eff": "3.0.0-next.70",
39
- "@eslint-react/var": "3.0.0-next.70",
40
- "@eslint-react/shared": "3.0.0-next.70"
37
+ "@eslint-react/ast": "3.0.0-next.71",
38
+ "@eslint-react/eff": "3.0.0-next.71",
39
+ "@eslint-react/shared": "3.0.0-next.71",
40
+ "@eslint-react/var": "3.0.0-next.71"
41
41
  },
42
42
  "devDependencies": {
43
43
  "tsdown": "^0.21.0-beta.2",