@eslint-react/core 2.0.7-next.1 → 2.0.7-next.3

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.
Files changed (2) hide show
  1. package/dist/index.js +72 -79
  2. package/package.json +9 -9
package/dist/index.js CHANGED
@@ -267,8 +267,7 @@ function isFunctionOfUseEffectCleanup(node) {
267
267
  if (node == null) return false;
268
268
  const pReturn = AST.findParentNode(node, AST.is(AST_NODE_TYPES.ReturnStatement));
269
269
  const pFunction = AST.findParentNode(node, AST.isFunction);
270
- const pFunctionOfReturn = AST.findParentNode(pReturn, AST.isFunction);
271
- if (pFunction !== pFunctionOfReturn) return false;
270
+ if (pFunction !== AST.findParentNode(pReturn, AST.isFunction)) return false;
272
271
  return isFunctionOfUseEffectSetup(pFunction);
273
272
  }
274
273
 
@@ -327,8 +326,7 @@ function getJsxAttribute(context, node, initialScope) {
327
326
  if (attr.type === AST_NODE_TYPES.JSXAttribute) return getJsxAttributeName(context, attr) === name;
328
327
  switch (attr.argument.type) {
329
328
  case AST_NODE_TYPES.Identifier: {
330
- const variable = findVariable(attr.argument.name, scope);
331
- const variableNode = getVariableDefinitionNode(variable, 0);
329
+ const variableNode = getVariableDefinitionNode(findVariable(attr.argument.name, scope), 0);
332
330
  if (variableNode?.type === AST_NODE_TYPES.ObjectExpression) return findProperty(name, variableNode.properties, scope) != null;
333
331
  return false;
334
332
  }
@@ -534,10 +532,7 @@ function isJsxLike(code, node, hint = DEFAULT_JSX_DETECTION_HINT) {
534
532
  if (hint & JsxDetectionHint.StrictConditional) return leftHasJSX(node) && rightHasJSX(node);
535
533
  return leftHasJSX(node) || rightHasJSX(node);
536
534
  }
537
- case AST_NODE_TYPES.SequenceExpression: {
538
- const exp = node.expressions.at(-1);
539
- return isJsxLike(code, exp, hint);
540
- }
535
+ case AST_NODE_TYPES.SequenceExpression: return isJsxLike(code, node.expressions.at(-1), hint);
541
536
  case AST_NODE_TYPES.CallExpression:
542
537
  if (hint & JsxDetectionHint.SkipCreateElement) return false;
543
538
  switch (node.callee.type) {
@@ -936,80 +931,78 @@ function useComponentCollector(context, options = {}) {
936
931
  }
937
932
  return functionEntries.pop();
938
933
  };
939
- const ctx = {
940
- getAllComponents(node) {
941
- return components;
942
- },
943
- getCurrentEntries() {
944
- return [...functionEntries];
945
- },
946
- getCurrentEntry
947
- };
948
- const listeners = {
949
- ":function[type]": onFunctionEnter,
950
- ":function[type]:exit": onFunctionExit,
951
- "ArrowFunctionExpression[body.type!='BlockStatement']"() {
952
- const entry = getCurrentEntry();
953
- if (entry == null) return;
954
- const { body } = entry.node;
955
- if (!(hasNoneOrLooseComponentName(context, entry.node) && isJsxLike(context.sourceCode, body, hint) && isComponentDefinition(context, entry.node, hint))) return;
956
- const initPath = AST.getFunctionInitPath(entry.node);
957
- const id = getFunctionComponentId(context, entry.node);
958
- const name = getComponentNameFromId(id);
959
- const key = getId();
960
- components.set(key, {
961
- id,
962
- key,
963
- kind: "function",
964
- name,
965
- node: entry.node,
966
- displayName: unit,
967
- flag: getComponentFlagFromInitPath(initPath),
968
- hint,
969
- hookCalls: entry.hookCalls,
970
- initPath
971
- });
934
+ return {
935
+ ctx: {
936
+ getAllComponents(node) {
937
+ return components;
938
+ },
939
+ getCurrentEntries() {
940
+ return [...functionEntries];
941
+ },
942
+ getCurrentEntry
972
943
  },
973
- ...collectDisplayName ? { [AST.SEL_DISPLAY_NAME_ASSIGNMENT_EXPRESSION](node) {
974
- const { left, right } = node;
975
- if (left.type !== AST_NODE_TYPES.MemberExpression) return;
976
- const componentName = left.object.type === AST_NODE_TYPES.Identifier ? left.object.name : unit;
977
- const component = [...components.values()].findLast(({ name }) => name != null && name === componentName);
978
- if (component == null) return;
979
- component.displayName = right;
980
- } } : {},
981
- ...collectHookCalls ? { "CallExpression[type]:exit"(node) {
982
- if (!isReactHookCall(node)) return;
983
- const entry = getCurrentEntry();
984
- if (entry == null) return;
985
- entry.hookCalls.push(node);
986
- } } : {},
987
- "ReturnStatement[type]"(node) {
988
- const entry = getCurrentEntry();
989
- if (entry == null) return;
990
- if (!(hasNoneOrLooseComponentName(context, entry.node) && isJsxLike(context.sourceCode, node.argument, hint) && isComponentDefinition(context, entry.node, hint))) return;
991
- entry.isComponent = true;
992
- const initPath = AST.getFunctionInitPath(entry.node);
993
- const id = getFunctionComponentId(context, entry.node);
994
- const name = getComponentNameFromId(id);
995
- components.set(entry.key, {
996
- id,
997
- key: entry.key,
998
- kind: "function",
999
- name,
1000
- node: entry.node,
1001
- displayName: unit,
1002
- flag: getComponentFlagFromInitPath(initPath),
1003
- hint,
1004
- hookCalls: entry.hookCalls,
1005
- initPath
1006
- });
944
+ listeners: {
945
+ ":function[type]": onFunctionEnter,
946
+ ":function[type]:exit": onFunctionExit,
947
+ "ArrowFunctionExpression[body.type!='BlockStatement']"() {
948
+ const entry = getCurrentEntry();
949
+ if (entry == null) return;
950
+ const { body } = entry.node;
951
+ if (!(hasNoneOrLooseComponentName(context, entry.node) && isJsxLike(context.sourceCode, body, hint) && isComponentDefinition(context, entry.node, hint))) return;
952
+ const initPath = AST.getFunctionInitPath(entry.node);
953
+ const id = getFunctionComponentId(context, entry.node);
954
+ const name = getComponentNameFromId(id);
955
+ const key = getId();
956
+ components.set(key, {
957
+ id,
958
+ key,
959
+ kind: "function",
960
+ name,
961
+ node: entry.node,
962
+ displayName: unit,
963
+ flag: getComponentFlagFromInitPath(initPath),
964
+ hint,
965
+ hookCalls: entry.hookCalls,
966
+ initPath
967
+ });
968
+ },
969
+ ...collectDisplayName ? { [AST.SEL_DISPLAY_NAME_ASSIGNMENT_EXPRESSION](node) {
970
+ const { left, right } = node;
971
+ if (left.type !== AST_NODE_TYPES.MemberExpression) return;
972
+ const componentName = left.object.type === AST_NODE_TYPES.Identifier ? left.object.name : unit;
973
+ const component = [...components.values()].findLast(({ name }) => name != null && name === componentName);
974
+ if (component == null) return;
975
+ component.displayName = right;
976
+ } } : {},
977
+ ...collectHookCalls ? { "CallExpression[type]:exit"(node) {
978
+ if (!isReactHookCall(node)) return;
979
+ const entry = getCurrentEntry();
980
+ if (entry == null) return;
981
+ entry.hookCalls.push(node);
982
+ } } : {},
983
+ "ReturnStatement[type]"(node) {
984
+ const entry = getCurrentEntry();
985
+ if (entry == null) return;
986
+ if (!(hasNoneOrLooseComponentName(context, entry.node) && isJsxLike(context.sourceCode, node.argument, hint) && isComponentDefinition(context, entry.node, hint))) return;
987
+ entry.isComponent = true;
988
+ const initPath = AST.getFunctionInitPath(entry.node);
989
+ const id = getFunctionComponentId(context, entry.node);
990
+ const name = getComponentNameFromId(id);
991
+ components.set(entry.key, {
992
+ id,
993
+ key: entry.key,
994
+ kind: "function",
995
+ name,
996
+ node: entry.node,
997
+ displayName: unit,
998
+ flag: getComponentFlagFromInitPath(initPath),
999
+ hint,
1000
+ hookCalls: entry.hookCalls,
1001
+ initPath
1002
+ });
1003
+ }
1007
1004
  }
1008
1005
  };
1009
- return {
1010
- ctx,
1011
- listeners
1012
- };
1013
1006
  }
1014
1007
 
1015
1008
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/core",
3
- "version": "2.0.7-next.1",
3
+ "version": "2.0.7-next.3",
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": {
@@ -27,16 +27,16 @@
27
27
  "./package.json"
28
28
  ],
29
29
  "dependencies": {
30
- "@typescript-eslint/scope-manager": "^8.45.0",
31
- "@typescript-eslint/types": "^8.45.0",
32
- "@typescript-eslint/utils": "^8.45.0",
30
+ "@typescript-eslint/scope-manager": "^8.46.0",
31
+ "@typescript-eslint/types": "^8.46.0",
32
+ "@typescript-eslint/utils": "^8.46.0",
33
33
  "birecord": "^0.1.1",
34
34
  "ts-pattern": "^5.8.0",
35
- "@eslint-react/ast": "2.0.7-next.1",
36
- "@eslint-react/eff": "2.0.7-next.1",
37
- "@eslint-react/kit": "2.0.7-next.1",
38
- "@eslint-react/var": "2.0.7-next.1",
39
- "@eslint-react/shared": "2.0.7-next.1"
35
+ "@eslint-react/ast": "2.0.7-next.3",
36
+ "@eslint-react/eff": "2.0.7-next.3",
37
+ "@eslint-react/shared": "2.0.7-next.3",
38
+ "@eslint-react/var": "2.0.7-next.3",
39
+ "@eslint-react/kit": "2.0.7-next.3"
40
40
  },
41
41
  "devDependencies": {
42
42
  "tsdown": "^0.15.6",