@eslint-react/core 3.0.0-next.81 → 3.0.0-next.83

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
@@ -92,6 +92,7 @@ type ComponentDetectionHint = bigint;
92
92
  * Hints for component collector
93
93
  */
94
94
  declare const ComponentDetectionHint: {
95
+ readonly DoNotIncludeFunctionDefinedAsArbitraryCallExpressionCallback: bigint;
95
96
  readonly DoNotIncludeFunctionDefinedAsArrayFlatMapCallback: bigint;
96
97
  readonly DoNotIncludeFunctionDefinedAsArrayMapCallback: bigint;
97
98
  readonly DoNotIncludeFunctionDefinedInArrayExpression: bigint;
package/dist/index.js CHANGED
@@ -1109,7 +1109,8 @@ function isComponentWrapperCallLoose(context, node) {
1109
1109
  */
1110
1110
  function isComponentWrapperCallback(context, node) {
1111
1111
  if (!ast.isFunction(node)) return false;
1112
- const parent = node.parent;
1112
+ let parent = node.parent;
1113
+ while (ast.isTypeExpression(parent)) parent = parent.parent;
1113
1114
  if (parent.type !== AST_NODE_TYPES.CallExpression) return false;
1114
1115
  return isComponentWrapperCall(context, parent);
1115
1116
  }
@@ -1121,7 +1122,8 @@ function isComponentWrapperCallback(context, node) {
1121
1122
  */
1122
1123
  function isComponentWrapperCallbackLoose(context, node) {
1123
1124
  if (!ast.isFunction(node)) return false;
1124
- const parent = node.parent;
1125
+ let parent = node.parent;
1126
+ while (ast.isTypeExpression(parent)) parent = parent.parent;
1125
1127
  if (parent.type !== AST_NODE_TYPES.CallExpression) return false;
1126
1128
  return isComponentWrapperCallLoose(context, parent);
1127
1129
  }
@@ -1137,7 +1139,8 @@ function isComponentWrapperCallbackLoose(context, node) {
1137
1139
  function getFunctionComponentId(context, node) {
1138
1140
  const functionId = ast.getFunctionId(node);
1139
1141
  if (functionId != null) return functionId;
1140
- const { parent } = node;
1142
+ let parent = node.parent;
1143
+ while (ast.isTypeExpression(parent)) parent = parent.parent;
1141
1144
  if (parent.type === AST_NODE_TYPES.CallExpression && isComponentWrapperCallLoose(context, parent) && parent.parent.type === AST_NODE_TYPES.VariableDeclarator) return parent.parent.id;
1142
1145
  if (parent.type === AST_NODE_TYPES.CallExpression && isComponentWrapperCallLoose(context, parent) && parent.parent.type === AST_NODE_TYPES.CallExpression && isComponentWrapperCallLoose(context, parent.parent) && parent.parent.parent.type === AST_NODE_TYPES.VariableDeclarator) return parent.parent.parent.id;
1143
1146
  return null;
@@ -1181,6 +1184,7 @@ function isFunctionWithLooseComponentName(context, fn, allowNone = false) {
1181
1184
  */
1182
1185
  const ComponentDetectionHint = {
1183
1186
  ...JsxDetectionHint,
1187
+ DoNotIncludeFunctionDefinedAsArbitraryCallExpressionCallback: 1n << 18n,
1184
1188
  DoNotIncludeFunctionDefinedAsArrayFlatMapCallback: 1n << 17n,
1185
1189
  DoNotIncludeFunctionDefinedAsArrayMapCallback: 1n << 16n,
1186
1190
  DoNotIncludeFunctionDefinedInArrayExpression: 1n << 15n,
@@ -1192,7 +1196,7 @@ const ComponentDetectionHint = {
1192
1196
  /**
1193
1197
  * Default component detection hint
1194
1198
  */
1195
- const DEFAULT_COMPONENT_DETECTION_HINT = 0n | ComponentDetectionHint.DoNotIncludeJsxWithBigIntValue | ComponentDetectionHint.DoNotIncludeJsxWithBooleanValue | ComponentDetectionHint.DoNotIncludeJsxWithNumberValue | ComponentDetectionHint.DoNotIncludeJsxWithStringValue | ComponentDetectionHint.DoNotIncludeJsxWithUndefinedValue | ComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayFlatMapCallback | ComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayMapCallback | ComponentDetectionHint.DoNotIncludeFunctionDefinedInArrayExpression | ComponentDetectionHint.DoNotIncludeFunctionDefinedInArrayPattern | ComponentDetectionHint.RequireAllArrayElementsToBeJsx | ComponentDetectionHint.RequireBothBranchesOfConditionalExpressionToBeJsx | ComponentDetectionHint.RequireBothSidesOfLogicalExpressionToBeJsx;
1199
+ const DEFAULT_COMPONENT_DETECTION_HINT = 0n | ComponentDetectionHint.DoNotIncludeJsxWithBigIntValue | ComponentDetectionHint.DoNotIncludeJsxWithBooleanValue | ComponentDetectionHint.DoNotIncludeJsxWithNumberValue | ComponentDetectionHint.DoNotIncludeJsxWithStringValue | ComponentDetectionHint.DoNotIncludeJsxWithUndefinedValue | ComponentDetectionHint.DoNotIncludeFunctionDefinedAsArbitraryCallExpressionCallback | ComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayFlatMapCallback | ComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayMapCallback | ComponentDetectionHint.DoNotIncludeFunctionDefinedInArrayExpression | ComponentDetectionHint.DoNotIncludeFunctionDefinedInArrayPattern | ComponentDetectionHint.RequireAllArrayElementsToBeJsx | ComponentDetectionHint.RequireBothBranchesOfConditionalExpressionToBeJsx | ComponentDetectionHint.RequireBothSidesOfLogicalExpressionToBeJsx;
1196
1200
  /**
1197
1201
  * Determine if a function node represents a valid React component definition
1198
1202
  *
@@ -1207,28 +1211,33 @@ function isComponentDefinition(context, node, hint) {
1207
1211
  case node.parent.type === AST_NODE_TYPES.CallExpression && isCreateElementCall(context, node.parent) && node.parent.arguments.slice(2).some((arg) => arg === node): return false;
1208
1212
  case isRenderMethodCallback(node): return false;
1209
1213
  }
1214
+ let parent = node.parent;
1215
+ while (ast.isTypeExpression(parent)) parent = parent.parent;
1210
1216
  switch (true) {
1211
- case ast.isOneOf([AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression])(node) && node.parent.type === AST_NODE_TYPES.Property && node.parent.parent.type === AST_NODE_TYPES.ObjectExpression:
1217
+ case ast.isOneOf([AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression])(node) && parent.type === AST_NODE_TYPES.Property && parent.parent.type === AST_NODE_TYPES.ObjectExpression:
1212
1218
  if (hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedOnObjectMethod) return false;
1213
1219
  break;
1214
- case ast.isOneOf([AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression])(node) && node.parent.type === AST_NODE_TYPES.MethodDefinition:
1220
+ case ast.isOneOf([AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression])(node) && parent.type === AST_NODE_TYPES.MethodDefinition:
1215
1221
  if (hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedOnClassMethod) return false;
1216
1222
  break;
1217
- case ast.isOneOf([AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression])(node) && node.parent.type === AST_NODE_TYPES.Property:
1223
+ case ast.isOneOf([AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression])(node) && parent.type === AST_NODE_TYPES.Property:
1218
1224
  if (hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedOnClassProperty) return false;
1219
1225
  break;
1220
- case node.parent.type === AST_NODE_TYPES.ArrayPattern:
1226
+ case parent.type === AST_NODE_TYPES.ArrayPattern:
1221
1227
  if (hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedInArrayPattern) return false;
1222
1228
  break;
1223
- case node.parent.type === AST_NODE_TYPES.ArrayExpression:
1229
+ case parent.type === AST_NODE_TYPES.ArrayExpression:
1224
1230
  if (hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedInArrayExpression) return false;
1225
1231
  break;
1226
- case node.parent.type === AST_NODE_TYPES.CallExpression && node.parent.callee.type === AST_NODE_TYPES.MemberExpression && node.parent.callee.property.type === AST_NODE_TYPES.Identifier && node.parent.callee.property.name === "map":
1232
+ case parent.type === AST_NODE_TYPES.CallExpression && parent.callee.type === AST_NODE_TYPES.MemberExpression && parent.callee.property.type === AST_NODE_TYPES.Identifier && parent.callee.property.name === "map":
1227
1233
  if (hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayMapCallback) return false;
1228
1234
  break;
1229
- case node.parent.type === AST_NODE_TYPES.CallExpression && node.parent.callee.type === AST_NODE_TYPES.MemberExpression && node.parent.callee.property.type === AST_NODE_TYPES.Identifier && node.parent.callee.property.name === "flatMap":
1235
+ case parent.type === AST_NODE_TYPES.CallExpression && parent.callee.type === AST_NODE_TYPES.MemberExpression && parent.callee.property.type === AST_NODE_TYPES.Identifier && parent.callee.property.name === "flatMap":
1230
1236
  if (hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayFlatMapCallback) return false;
1231
1237
  break;
1238
+ case parent.type === AST_NODE_TYPES.CallExpression && ast.getFunctionId(node) == null && !isComponentWrapperCallLoose(context, parent) && !isCreateElementCall(context, parent):
1239
+ if (hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedAsArbitraryCallExpressionCallback) return false;
1240
+ break;
1232
1241
  }
1233
1242
  const significantParent = ast.findParentNode(node, ast.isOneOf([
1234
1243
  AST_NODE_TYPES.JSXExpressionContainer,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/core",
3
- "version": "3.0.0-next.81",
3
+ "version": "3.0.0-next.83",
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,9 +34,9 @@
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.81",
38
- "@eslint-react/shared": "3.0.0-next.81",
39
- "@eslint-react/var": "3.0.0-next.81"
37
+ "@eslint-react/shared": "3.0.0-next.83",
38
+ "@eslint-react/ast": "3.0.0-next.83",
39
+ "@eslint-react/var": "3.0.0-next.83"
40
40
  },
41
41
  "devDependencies": {
42
42
  "tsdown": "^0.21.0",