@eslint-react/core 2.7.1-next.1 → 2.7.1-next.2

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
@@ -117,6 +117,10 @@ interface FunctionComponent extends SemanticNode {
117
117
  * The initialization path of the function
118
118
  */
119
119
  initPath: unit | AST.FunctionInitPath;
120
+ /**
121
+ * Indicates if the component is exported as default
122
+ */
123
+ isExportDefault: boolean;
120
124
  /**
121
125
  * List of hook calls within the component
122
126
  */
@@ -170,6 +174,8 @@ type FunctionEntry$1 = {
170
174
  node: AST.TSESTreeFunction;
171
175
  hookCalls: TSESTree.CallExpression[];
172
176
  isComponent: boolean;
177
+ isComponentDefinition: boolean;
178
+ isExportDefault: boolean;
173
179
  rets: TSESTree.ReturnStatement["argument"][];
174
180
  };
175
181
  declare namespace useComponentCollector {
package/dist/index.js CHANGED
@@ -822,13 +822,18 @@ function isComponentDefinition(context, node, hint) {
822
822
  if (isChildrenOfCreateElement(context, node) || isFunctionOfRenderMethod(node)) return false;
823
823
  if (shouldExcludeBasedOnHint(node, hint)) return false;
824
824
  const significantParent = AST.findParentNode(node, AST.isOneOf([
825
+ AST_NODE_TYPES.ArrayPattern,
826
+ AST_NODE_TYPES.ArrayExpression,
825
827
  AST_NODE_TYPES.JSXExpressionContainer,
826
828
  AST_NODE_TYPES.ArrowFunctionExpression,
827
829
  AST_NODE_TYPES.FunctionExpression,
828
830
  AST_NODE_TYPES.Property,
829
831
  AST_NODE_TYPES.ClassBody
830
832
  ]));
831
- return significantParent == null || significantParent.type !== AST_NODE_TYPES.JSXExpressionContainer;
833
+ if (significantParent == null) return true;
834
+ if (significantParent.type === AST_NODE_TYPES.JSXExpressionContainer) return false;
835
+ if (significantParent.type === AST_NODE_TYPES.ArrayPattern || significantParent.type === AST_NODE_TYPES.ArrayExpression) return false;
836
+ return true;
832
837
  }
833
838
 
834
839
  //#endregion
@@ -960,6 +965,8 @@ function useComponentCollector(context, options = {}) {
960
965
  node,
961
966
  hookCalls: [],
962
967
  isComponent: false,
968
+ isComponentDefinition: isComponentDefinition(context, node, hint),
969
+ isExportDefault: AST.findParentNode(node, (n) => n.type === AST_NODE_TYPES.ExportDefaultDeclaration) != null,
963
970
  rets: []
964
971
  });
965
972
  };
@@ -982,9 +989,10 @@ function useComponentCollector(context, options = {}) {
982
989
  "ArrowFunctionExpression[body.type!='BlockStatement']"() {
983
990
  const entry = getCurrentEntry();
984
991
  if (entry == null) return;
992
+ if (!entry.isComponentDefinition) return;
985
993
  const { body } = entry.node;
986
994
  if (body.type === AST_NODE_TYPES.BlockStatement) return;
987
- if (!(hasNoneOrLooseComponentName(context, entry.node) && isJsxLike(context.sourceCode, body, hint) && isComponentDefinition(context, entry.node, hint))) return;
995
+ if (!(hasNoneOrLooseComponentName(context, entry.node) && isJsxLike(context.sourceCode, body, hint))) return;
988
996
  const initPath = AST.getFunctionInitPath(entry.node);
989
997
  const id = getFunctionComponentId(context, entry.node);
990
998
  const key = entry.key;
@@ -1000,6 +1008,7 @@ function useComponentCollector(context, options = {}) {
1000
1008
  hint,
1001
1009
  hookCalls: entry.hookCalls,
1002
1010
  initPath,
1011
+ isExportDefault: entry.isExportDefault,
1003
1012
  rets: [body]
1004
1013
  });
1005
1014
  },
@@ -1020,8 +1029,10 @@ function useComponentCollector(context, options = {}) {
1020
1029
  "ReturnStatement[type]"(node) {
1021
1030
  const entry = getCurrentEntry();
1022
1031
  if (entry == null) return;
1023
- entry.rets.push(node.argument);
1024
- if (!(hasNoneOrLooseComponentName(context, entry.node) && isJsxLike(context.sourceCode, node.argument, hint) && isComponentDefinition(context, entry.node, hint))) return;
1032
+ if (!entry.isComponentDefinition) return;
1033
+ const { argument } = node;
1034
+ entry.rets.push(argument);
1035
+ if (!(hasNoneOrLooseComponentName(context, entry.node) && isJsxLike(context.sourceCode, argument, hint))) return;
1025
1036
  entry.isComponent = true;
1026
1037
  const initPath = AST.getFunctionInitPath(entry.node);
1027
1038
  const id = getFunctionComponentId(context, entry.node);
@@ -1038,6 +1049,7 @@ function useComponentCollector(context, options = {}) {
1038
1049
  hint,
1039
1050
  hookCalls: entry.hookCalls,
1040
1051
  initPath,
1052
+ isExportDefault: entry.isExportDefault,
1041
1053
  rets: entry.rets
1042
1054
  });
1043
1055
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/core",
3
- "version": "2.7.1-next.1",
3
+ "version": "2.7.1-next.2",
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": {
@@ -35,10 +35,10 @@
35
35
  "@typescript-eslint/utils": "^8.53.0",
36
36
  "birecord": "^0.1.1",
37
37
  "ts-pattern": "^5.9.0",
38
- "@eslint-react/ast": "2.7.1-next.1",
39
- "@eslint-react/eff": "2.7.1-next.1",
40
- "@eslint-react/shared": "2.7.1-next.1",
41
- "@eslint-react/var": "2.7.1-next.1"
38
+ "@eslint-react/ast": "2.7.1-next.2",
39
+ "@eslint-react/shared": "2.7.1-next.2",
40
+ "@eslint-react/eff": "2.7.1-next.2",
41
+ "@eslint-react/var": "2.7.1-next.2"
42
42
  },
43
43
  "devDependencies": {
44
44
  "tsdown": "^0.20.0-beta.3",