@eslint-react/core 2.7.5-next.7 → 2.7.5-next.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.d.ts CHANGED
@@ -251,15 +251,8 @@ interface ClassComponentSemanticNode extends SemanticNode {
251
251
  type ComponentSemanticNode = ClassComponentSemanticNode | FunctionComponentSemanticNode;
252
252
  //#endregion
253
253
  //#region src/component/component-collector.d.ts
254
- type FunctionEntry$1 = {
255
- key: string;
256
- node: AST.TSESTreeFunction;
257
- hookCalls: TSESTree.CallExpression[];
258
- isComponent: boolean;
254
+ type FunctionEntry$1 = FunctionComponentSemanticNode & {
259
255
  isComponentDefinition: boolean;
260
- isExportDefault: boolean;
261
- isExportDefaultDeclaration: boolean;
262
- rets: TSESTree.ReturnStatement["argument"][];
263
256
  };
264
257
  declare namespace useComponentCollector {
265
258
  type Options = {
@@ -574,7 +567,6 @@ interface HookSemanticNode extends SemanticNode {
574
567
  type FunctionEntry = {
575
568
  key: string;
576
569
  node: AST.TSESTreeFunction;
577
- isHook: boolean;
578
570
  };
579
571
  declare namespace useHookCollector {
580
572
  type ReturnType = {
package/dist/index.js CHANGED
@@ -269,28 +269,20 @@ function useHookCollector(context) {
269
269
  const onFunctionEnter = (node) => {
270
270
  const id = AST.getFunctionId(node);
271
271
  const key = idGen$2.next();
272
- if (id != null && isHookId(id)) {
273
- functionEntries.push({
274
- key,
275
- node,
276
- isHook: true
277
- });
278
- hooks.set(key, {
279
- id,
280
- key,
281
- kind: "function",
282
- name: AST.toStringFormat(id, getText),
283
- node,
284
- flag: 0n,
285
- hint: 0n,
286
- hookCalls: []
287
- });
288
- return;
289
- }
290
272
  functionEntries.push({
291
273
  key,
274
+ node
275
+ });
276
+ if (id == null || !isHookId(id)) return;
277
+ hooks.set(key, {
278
+ id,
279
+ key,
280
+ kind: "function",
281
+ name: AST.toStringFormat(id, getText),
292
282
  node,
293
- isHook: false
283
+ flag: 0n,
284
+ hint: 0n,
285
+ hookCalls: []
294
286
  });
295
287
  };
296
288
  const onFunctionExit = () => {
@@ -309,11 +301,9 @@ function useHookCollector(context) {
309
301
  ":function:exit": onFunctionExit,
310
302
  CallExpression(node) {
311
303
  if (!isHookCall(node)) return;
312
- const fEntry = getCurrentEntry();
313
- if (fEntry?.key == null) return;
314
- const hook = hooks.get(fEntry.key);
315
- if (hook == null) return;
316
- hook.hookCalls.push(node);
304
+ const entry = getCurrentEntry();
305
+ if (entry == null) return;
306
+ hooks.get(entry.key)?.hookCalls.push(node);
317
307
  }
318
308
  }
319
309
  };
@@ -953,12 +943,21 @@ function useComponentCollector(context, options = {}) {
953
943
  const exp = AST.findParentNode(node, (n) => n.type === AST_NODE_TYPES.ExportDefaultDeclaration);
954
944
  const isExportDefault = exp != null;
955
945
  const isExportDefaultDeclaration = exp != null && AST.getUnderlyingExpression(exp.declaration) === node;
946
+ const id = getFunctionComponentId(context, node);
947
+ const name = id == null ? unit : AST.toStringFormat(id, getText);
948
+ const initPath = AST.getFunctionInitPath(node);
956
949
  functionEntries.push({
950
+ id: getFunctionComponentId(context, node),
957
951
  key,
952
+ kind: "function",
953
+ name,
958
954
  node,
955
+ displayName: unit,
956
+ flag: getComponentFlagFromInitPath(initPath),
957
+ hint,
959
958
  hookCalls: [],
960
- isComponent: false,
961
- isComponentDefinition: isComponentDefinition(context, node, hint),
959
+ initPath,
960
+ isComponentDefinition: hasNoneOrLooseComponentName(context, node) && isComponentDefinition(context, node, hint),
962
961
  isExportDefault,
963
962
  isExportDefaultDeclaration,
964
963
  rets: []
@@ -983,29 +982,12 @@ function useComponentCollector(context, options = {}) {
983
982
  "ArrowFunctionExpression[body.type!='BlockStatement']"() {
984
983
  const entry = getCurrentEntry();
985
984
  if (entry == null) return;
986
- if (!entry.isComponentDefinition) return;
987
985
  const { body } = entry.node;
988
986
  if (body.type === AST_NODE_TYPES.BlockStatement) return;
989
- if (!(hasNoneOrLooseComponentName(context, entry.node) && isJsxLike(context.sourceCode, body, hint))) return;
990
- const initPath = AST.getFunctionInitPath(entry.node);
991
- const id = getFunctionComponentId(context, entry.node);
992
- const key = entry.key;
993
- const name = id == null ? unit : AST.toStringFormat(id, getText);
994
- components.set(key, {
995
- id,
996
- key,
997
- kind: "function",
998
- name,
999
- node: entry.node,
1000
- displayName: unit,
1001
- flag: getComponentFlagFromInitPath(initPath),
1002
- hint,
1003
- hookCalls: entry.hookCalls,
1004
- initPath,
1005
- isExportDefault: entry.isExportDefault,
1006
- isExportDefaultDeclaration: entry.isExportDefaultDeclaration,
1007
- rets: [body]
1008
- });
987
+ entry.rets.push(body);
988
+ if (!entry.isComponentDefinition) return;
989
+ if (!components.has(entry.key) && !isJsxLike(context.sourceCode, body, hint)) return;
990
+ components.set(entry.key, entry);
1009
991
  },
1010
992
  ...collectDisplayName ? { [AST.SEL_DISPLAY_NAME_ASSIGNMENT_EXPRESSION](node) {
1011
993
  const { left, right } = node;
@@ -1024,30 +1006,11 @@ function useComponentCollector(context, options = {}) {
1024
1006
  ReturnStatement(node) {
1025
1007
  const entry = getCurrentEntry();
1026
1008
  if (entry == null) return;
1009
+ entry.rets.push(node.argument);
1027
1010
  if (!entry.isComponentDefinition) return;
1028
1011
  const { argument } = node;
1029
- entry.rets.push(argument);
1030
- if (!(hasNoneOrLooseComponentName(context, entry.node) && isJsxLike(context.sourceCode, argument, hint))) return;
1031
- entry.isComponent = true;
1032
- const initPath = AST.getFunctionInitPath(entry.node);
1033
- const id = getFunctionComponentId(context, entry.node);
1034
- const key = entry.key;
1035
- const name = id == null ? unit : AST.toStringFormat(id, getText);
1036
- components.set(key, {
1037
- id,
1038
- key,
1039
- kind: "function",
1040
- name,
1041
- node: entry.node,
1042
- displayName: unit,
1043
- flag: getComponentFlagFromInitPath(initPath),
1044
- hint,
1045
- hookCalls: entry.hookCalls,
1046
- initPath,
1047
- isExportDefault: entry.isExportDefault,
1048
- isExportDefaultDeclaration: entry.isExportDefaultDeclaration,
1049
- rets: entry.rets
1050
- });
1012
+ if (!components.has(entry.key) && !isJsxLike(context.sourceCode, argument, hint)) return;
1013
+ components.set(entry.key, entry);
1051
1014
  }
1052
1015
  }
1053
1016
  };
@@ -1120,9 +1083,7 @@ function isAssignmentToThisState(node) {
1120
1083
  * @param isStatic Whether the method is static
1121
1084
  */
1122
1085
  function createLifecycleChecker(methodName, isStatic = false) {
1123
- return function(node) {
1124
- return AST.isMethodOrProperty(node) && node.static === isStatic && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === methodName;
1125
- };
1086
+ return (node) => AST.isMethodOrProperty(node) && node.static === isStatic && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === methodName;
1126
1087
  }
1127
1088
  const isRender = createLifecycleChecker("render");
1128
1089
  const isComponentDidCatch = createLifecycleChecker("componentDidCatch");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/core",
3
- "version": "2.7.5-next.7",
3
+ "version": "2.7.5-next.9",
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": "^8.54.0",
35
35
  "@typescript-eslint/utils": "^8.54.0",
36
36
  "ts-pattern": "^5.9.0",
37
- "@eslint-react/ast": "2.7.5-next.7",
38
- "@eslint-react/eff": "2.7.5-next.7",
39
- "@eslint-react/shared": "2.7.5-next.7",
40
- "@eslint-react/var": "2.7.5-next.7"
37
+ "@eslint-react/ast": "2.7.5-next.9",
38
+ "@eslint-react/eff": "2.7.5-next.9",
39
+ "@eslint-react/shared": "2.7.5-next.9",
40
+ "@eslint-react/var": "2.7.5-next.9"
41
41
  },
42
42
  "devDependencies": {
43
43
  "tsdown": "^0.20.1",