@eslint-react/core 1.28.0-beta.0 → 1.28.0-beta.4

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.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var AST9 = require('@eslint-react/ast');
3
+ var AST8 = require('@eslint-react/ast');
4
4
  var eff = require('@eslint-react/eff');
5
5
  var JSX3 = require('@eslint-react/jsx');
6
6
  var shared = require('@eslint-react/shared');
@@ -29,27 +29,16 @@ function _interopNamespace(e) {
29
29
  return Object.freeze(n);
30
30
  }
31
31
 
32
- var AST9__namespace = /*#__PURE__*/_interopNamespace(AST9);
32
+ var AST8__namespace = /*#__PURE__*/_interopNamespace(AST8);
33
33
  var JSX3__namespace = /*#__PURE__*/_interopNamespace(JSX3);
34
34
  var VAR__namespace = /*#__PURE__*/_interopNamespace(VAR);
35
35
  var birecord__default = /*#__PURE__*/_interopDefault(birecord);
36
36
 
37
37
  // src/component/component-collector.ts
38
- var DISPLAY_NAME_ASSIGNMENT_SELECTOR = [
39
- "AssignmentExpression",
40
- "[type]",
41
- "[operator='=']",
42
- "[left.type='MemberExpression']",
43
- "[left.property.name='displayName']"
44
- ].join("");
45
- function isDisplayNameAssignment(node) {
46
- if (node == null) return false;
47
- return node.type === types.AST_NODE_TYPES.AssignmentExpression && node.operator === "=" && node.left.type === types.AST_NODE_TYPES.MemberExpression && node.left.property.type === types.AST_NODE_TYPES.Identifier && node.left.property.name === "displayName";
48
- }
49
38
  function getRequireExpressionArguments(node) {
50
39
  return tsPattern.match(node).with({ type: types.AST_NODE_TYPES.CallExpression, arguments: tsPattern.P.select(), callee: { type: types.AST_NODE_TYPES.Identifier, name: "require" } }, eff.identity).with({ type: types.AST_NODE_TYPES.MemberExpression, object: tsPattern.P.select() }, getRequireExpressionArguments).otherwise(() => eff._);
51
40
  }
52
- function isInitializedFromReact(name, source, initialScope) {
41
+ function isInitializedFromReact(name, importSource, initialScope) {
53
42
  if (name.toLowerCase() === "react") return true;
54
43
  const latestDef = VAR__namespace.findVariable(name, initialScope)?.defs.at(-1);
55
44
  if (latestDef == null) return false;
@@ -57,81 +46,101 @@ function isInitializedFromReact(name, source, initialScope) {
57
46
  if (node.type === types.AST_NODE_TYPES.VariableDeclarator && node.init != null) {
58
47
  const { init } = node;
59
48
  if (init.type === types.AST_NODE_TYPES.MemberExpression && init.object.type === types.AST_NODE_TYPES.Identifier) {
60
- return isInitializedFromReact(init.object.name, source, initialScope);
49
+ return isInitializedFromReact(init.object.name, importSource, initialScope);
61
50
  }
62
51
  if (init.type === types.AST_NODE_TYPES.Identifier) {
63
- return isInitializedFromReact(init.name, source, initialScope);
52
+ return isInitializedFromReact(init.name, importSource, initialScope);
64
53
  }
65
54
  const args = getRequireExpressionArguments(init);
66
55
  const arg0 = args?.[0];
67
- if (arg0 == null || !AST9__namespace.isStringLiteral(arg0)) {
56
+ if (arg0 == null || !AST8__namespace.isKindOfLiteral(arg0, "string")) {
68
57
  return false;
69
58
  }
70
- return arg0.value === source || arg0.value.startsWith(`${source}/`);
59
+ return arg0.value === importSource || arg0.value.startsWith(`${importSource}/`);
71
60
  }
72
- return parent?.type === types.AST_NODE_TYPES.ImportDeclaration && parent.source.value === source;
61
+ return parent?.type === types.AST_NODE_TYPES.ImportDeclaration && parent.source.value === importSource;
73
62
  }
74
63
 
75
64
  // src/utils/is-from-react.ts
65
+ var defaultImportSource = shared.DEFAULT_ESLINT_REACT_SETTINGS.importSource;
66
+ function isFromReactLoose(node, name) {
67
+ if (node.type === types.AST_NODE_TYPES.MemberExpression) {
68
+ return node.object.type === types.AST_NODE_TYPES.Identifier && node.property.type === types.AST_NODE_TYPES.Identifier && node.property.name === name;
69
+ }
70
+ return node.name === name;
71
+ }
72
+ function isFromReactStrict(node, name, importSource, initialScope) {
73
+ if (node.type === types.AST_NODE_TYPES.MemberExpression) {
74
+ return node.object.type === types.AST_NODE_TYPES.Identifier && node.property.type === types.AST_NODE_TYPES.Identifier && node.property.name === name && isInitializedFromReact(node.object.name, importSource, initialScope);
75
+ }
76
+ if (node.name === name) {
77
+ return isInitializedFromReact(name, importSource, initialScope);
78
+ }
79
+ return false;
80
+ }
76
81
  function isFromReact(name) {
77
- return (node, context) => {
78
- const settings = shared.unsafeDecodeSettings(context.settings);
79
- if (!settings.strictImportCheck) {
80
- if (node.type === types.AST_NODE_TYPES.MemberExpression) {
81
- return node.object.type === types.AST_NODE_TYPES.Identifier && node.property.type === types.AST_NODE_TYPES.Identifier && node.property.name === name;
82
- }
83
- return node.name === name;
84
- }
85
- const importSource = settings.importSource ?? shared.DEFAULT_ESLINT_REACT_SETTINGS.importSource;
86
- const initialScope = context.sourceCode.getScope(node);
87
- if (node.type === types.AST_NODE_TYPES.MemberExpression) {
88
- return node.object.type === types.AST_NODE_TYPES.Identifier && node.property.type === types.AST_NODE_TYPES.Identifier && node.property.name === name && isInitializedFromReact(node.object.name, importSource, initialScope);
89
- }
90
- if (node.name === name) {
91
- return isInitializedFromReact(name, importSource, initialScope);
92
- }
93
- return false;
82
+ return (context, node) => {
83
+ const { importSource = defaultImportSource, strictImportCheck = false } = shared.unsafeDecodeSettings(context.settings);
84
+ if (!strictImportCheck) return isFromReactLoose(node, name);
85
+ return isFromReactStrict(node, name, importSource, context.sourceCode.getScope(node));
94
86
  };
95
87
  }
96
- function isFromReactMember(memberName, name) {
97
- return (node, context) => {
98
- const settings = shared.unsafeDecodeSettings(context.settings);
99
- if (!settings.strictImportCheck) {
100
- if (node.property.type !== types.AST_NODE_TYPES.Identifier || node.property.name !== name) return false;
101
- if (node.object.type === types.AST_NODE_TYPES.Identifier && node.object.name === memberName) return true;
102
- if (node.object.type === types.AST_NODE_TYPES.MemberExpression && node.object.object.type === types.AST_NODE_TYPES.Identifier && node.object.property.type === types.AST_NODE_TYPES.Identifier) {
103
- return node.object.property.name === memberName;
104
- }
105
- return false;
106
- }
107
- const importSource = settings.importSource ?? shared.DEFAULT_ESLINT_REACT_SETTINGS.importSource;
108
- const initialScope = context.sourceCode.getScope(node);
109
- if (node.property.type !== types.AST_NODE_TYPES.Identifier || node.property.name !== name) {
110
- return false;
111
- }
112
- if (node.object.type === types.AST_NODE_TYPES.Identifier && node.object.name === memberName) {
113
- return isInitializedFromReact(node.object.name, importSource, initialScope);
114
- }
115
- if (node.object.type === types.AST_NODE_TYPES.MemberExpression && node.object.object.type === types.AST_NODE_TYPES.Identifier && isInitializedFromReact(node.object.object.name, importSource, initialScope) && node.object.property.type === types.AST_NODE_TYPES.Identifier) {
116
- return node.object.property.name === memberName;
117
- }
88
+ function isFromReactMemberLoose(node, memberName, name) {
89
+ const { object, property } = node;
90
+ if (property.type !== types.AST_NODE_TYPES.Identifier || property.name !== name) return false;
91
+ if (object.type === types.AST_NODE_TYPES.Identifier && object.name === memberName) return true;
92
+ if (object.type === types.AST_NODE_TYPES.MemberExpression && object.object.type === types.AST_NODE_TYPES.Identifier && object.property.type === types.AST_NODE_TYPES.Identifier) {
93
+ return object.property.name === memberName;
94
+ }
95
+ return false;
96
+ }
97
+ function isFromReactMemberStrict(node, memberName, name, importSource, initialScope) {
98
+ const { object, property } = node;
99
+ if (property.type !== types.AST_NODE_TYPES.Identifier || property.name !== name) {
118
100
  return false;
101
+ }
102
+ if (object.type === types.AST_NODE_TYPES.Identifier && object.name === memberName) {
103
+ return isInitializedFromReact(object.name, importSource, initialScope);
104
+ }
105
+ if (object.type === types.AST_NODE_TYPES.MemberExpression && object.object.type === types.AST_NODE_TYPES.Identifier && isInitializedFromReact(object.object.name, importSource, initialScope) && object.property.type === types.AST_NODE_TYPES.Identifier) {
106
+ return object.property.name === memberName;
107
+ }
108
+ return false;
109
+ }
110
+ function isFromReactMember(memberName, name) {
111
+ return (context, node) => {
112
+ const { importSource = defaultImportSource, strictImportCheck = false } = shared.unsafeDecodeSettings(context.settings);
113
+ if (!strictImportCheck) return isFromReactMemberLoose(node, memberName, name);
114
+ return isFromReactMemberStrict(node, memberName, name, importSource, context.sourceCode.getScope(node));
119
115
  };
120
116
  }
117
+
118
+ // src/utils/is-call-from-react.ts
121
119
  function isCallFromReact(name) {
122
- return eff.dual(2, (node, context) => {
120
+ return eff.dual(2, (context, node) => {
123
121
  if (node.type !== types.AST_NODE_TYPES.CallExpression) return false;
124
- if (!AST9__namespace.isOneOf([types.AST_NODE_TYPES.Identifier, types.AST_NODE_TYPES.MemberExpression])(node.callee)) return false;
125
- return isFromReact(name)(node.callee, context);
122
+ if (!AST8__namespace.isOneOf([types.AST_NODE_TYPES.Identifier, types.AST_NODE_TYPES.MemberExpression])(node.callee)) return false;
123
+ return isFromReact(name)(context, node.callee);
126
124
  });
127
125
  }
128
126
  function isCallFromReactMember(pragmaMemberName, name) {
129
- return eff.dual(2, (node, context) => {
127
+ return eff.dual(2, (context, node) => {
130
128
  if (node.type !== types.AST_NODE_TYPES.CallExpression) return false;
131
- if (!AST9__namespace.is(types.AST_NODE_TYPES.MemberExpression)(node.callee)) return false;
132
- return isFromReactMember(pragmaMemberName, name)(node.callee, context);
129
+ if (!AST8__namespace.is(types.AST_NODE_TYPES.MemberExpression)(node.callee)) return false;
130
+ return isFromReactMember(pragmaMemberName, name)(context, node.callee);
133
131
  });
134
132
  }
133
+ var DISPLAY_NAME_ASSIGNMENT_SELECTOR = [
134
+ "AssignmentExpression",
135
+ "[type]",
136
+ "[operator='=']",
137
+ "[left.type='MemberExpression']",
138
+ "[left.property.name='displayName']"
139
+ ].join("");
140
+ function isDisplayNameAssignment(node) {
141
+ if (node == null) return false;
142
+ return node.type === types.AST_NODE_TYPES.AssignmentExpression && node.operator === "=" && node.left.type === types.AST_NODE_TYPES.MemberExpression && node.left.property.type === types.AST_NODE_TYPES.Identifier && node.left.property.name === "displayName";
143
+ }
135
144
 
136
145
  // src/utils/is-react-api.ts
137
146
  function isReactAPIWithName(name, member) {
@@ -163,21 +172,6 @@ var isCreateRefCall = isReactAPICallWithName("createRef");
163
172
  var isForwardRefCall = isReactAPICallWithName("forwardRef");
164
173
  var isMemoCall = isReactAPICallWithName("memo");
165
174
 
166
- // src/element/hierarchy.ts
167
- function isInsideCreateElementProps(node, context) {
168
- const call = AST9__namespace.findParentNode(node, isCreateElementCall(context));
169
- if (call == null) return false;
170
- const prop = AST9__namespace.findParentNode(node, AST9__namespace.is(types.AST_NODE_TYPES.ObjectExpression));
171
- if (prop == null) return false;
172
- return prop === call.arguments[1];
173
- }
174
- function isChildrenOfCreateElement(node, context) {
175
- const parent = node.parent;
176
- if (parent == null || parent.type !== types.AST_NODE_TYPES.CallExpression) return false;
177
- if (!isCreateElementCall(parent, context)) return false;
178
- return parent.arguments.slice(2).some((arg) => arg === node);
179
- }
180
-
181
175
  // src/hook/hook-name.ts
182
176
  var RE_HOOK_NAME = /^use[A-Z\d]/u;
183
177
  function isReactHookName(name) {
@@ -187,7 +181,7 @@ function isReactHookName(name) {
187
181
  // src/hook/is.ts
188
182
  function isReactHook(node) {
189
183
  if (node == null) return eff._;
190
- const id = AST9__namespace.getFunctionIdentifier(node);
184
+ const id = AST8__namespace.getFunctionIdentifier(node);
191
185
  return id?.name != null && isReactHookName(id.name);
192
186
  }
193
187
  function isReactHookCall(node) {
@@ -203,7 +197,7 @@ function isReactHookCall(node) {
203
197
  }
204
198
  return false;
205
199
  }
206
- function isReactHookCallWithName(node, context) {
200
+ function isReactHookCallWithName(context, node) {
207
201
  if (node == null) return eff.constFalse;
208
202
  const settings = shared.unsafeDecodeSettings(context.settings);
209
203
  const importSource = settings.importSource ?? "react";
@@ -232,7 +226,7 @@ function isReactHookCallWithNameLoose(node) {
232
226
  }
233
227
  };
234
228
  }
235
- function isReactHookCallWithNameAlias(name, context, alias) {
229
+ function isReactHookCallWithNameAlias(context, name, alias) {
236
230
  const settings = shared.unsafeDecodeSettings(context);
237
231
  const importSource = settings.importSource ?? "react";
238
232
  return (node) => {
@@ -279,13 +273,13 @@ var isUseTransitionCall = eff.flip(isReactHookCallWithName)("useTransition");
279
273
 
280
274
  // src/hook/hierarchy.ts
281
275
  function isInsideReactHook(node) {
282
- return isReactHook(AST9__namespace.findParentNode(node, AST9__namespace.isFunction));
276
+ return isReactHook(AST8__namespace.findParentNode(node, AST8__namespace.isFunction));
283
277
  }
284
278
  function useHookCollector() {
285
279
  const hooks = /* @__PURE__ */ new Map();
286
280
  const functionEntries = [];
287
281
  const onFunctionEnter = (node) => {
288
- const id = AST9__namespace.getFunctionIdentifier(node);
282
+ const id = AST8__namespace.getFunctionIdentifier(node);
289
283
  const key = shared.getId();
290
284
  const name = id?.name;
291
285
  if (name != null && isReactHookName(name)) {
@@ -374,26 +368,53 @@ var ERComponentFlag = {
374
368
  ForwardRef: 1n << 3n,
375
369
  Async: 1n << 4n
376
370
  };
377
- function isComponentWrapperCall(node, context) {
371
+ function isComponentWrapperCall(context, node) {
378
372
  if (node.type !== types.AST_NODE_TYPES.CallExpression) {
379
373
  return false;
380
374
  }
381
- return isMemoCall(node, context) || isForwardRefCall(node, context) || isReactHookCallWithNameLoose(node)("useCallback");
375
+ return isMemoCall(context, node) || isForwardRefCall(context, node) || isReactHookCallWithNameLoose(node)("useCallback");
382
376
  }
383
- function getFunctionComponentIdentifier(node, context) {
384
- const functionId = AST9__namespace.getFunctionIdentifier(node);
377
+ function getFunctionComponentIdentifier(context, node) {
378
+ const functionId = AST8__namespace.getFunctionIdentifier(node);
385
379
  if (functionId != null) {
386
380
  return functionId;
387
381
  }
388
382
  const { parent } = node;
389
- if (parent.type === types.AST_NODE_TYPES.CallExpression && isComponentWrapperCall(parent, context) && parent.parent.type === types.AST_NODE_TYPES.VariableDeclarator && parent.parent.id.type === types.AST_NODE_TYPES.Identifier) {
383
+ if (parent.type === types.AST_NODE_TYPES.CallExpression && isComponentWrapperCall(context, parent) && parent.parent.type === types.AST_NODE_TYPES.VariableDeclarator && parent.parent.id.type === types.AST_NODE_TYPES.Identifier) {
390
384
  return parent.parent.id;
391
385
  }
392
- if (parent.type === types.AST_NODE_TYPES.CallExpression && isComponentWrapperCall(parent, context) && parent.parent.type === types.AST_NODE_TYPES.CallExpression && isComponentWrapperCall(parent.parent, context) && parent.parent.parent.type === types.AST_NODE_TYPES.VariableDeclarator && parent.parent.parent.id.type === types.AST_NODE_TYPES.Identifier) {
386
+ if (parent.type === types.AST_NODE_TYPES.CallExpression && isComponentWrapperCall(context, parent) && parent.parent.type === types.AST_NODE_TYPES.CallExpression && isComponentWrapperCall(context, parent.parent) && parent.parent.parent.type === types.AST_NODE_TYPES.VariableDeclarator && parent.parent.parent.id.type === types.AST_NODE_TYPES.Identifier) {
393
387
  return parent.parent.parent.id;
394
388
  }
395
389
  return eff._;
396
390
  }
391
+ var RE_COMPONENT_NAME = /^_?[A-Z]/u;
392
+ function getComponentNameFromIdentifier(node) {
393
+ if (node == null) return eff._;
394
+ return Array.isArray(node) ? node.map((n) => n.name).join(".") : node.name;
395
+ }
396
+ function isComponentName(name) {
397
+ return RE_COMPONENT_NAME.test(name);
398
+ }
399
+ function hasNoneOrValidComponentName(context, node) {
400
+ const id = getFunctionComponentIdentifier(context, node);
401
+ if (id == null) return true;
402
+ const name = Array.isArray(id) ? id.at(-1)?.name : id.name;
403
+ return name != null && isComponentName(name);
404
+ }
405
+ function isInsideCreateElementProps(context, node) {
406
+ const call = AST8__namespace.findParentNode(node, isCreateElementCall(context));
407
+ if (call == null) return false;
408
+ const prop = AST8__namespace.findParentNode(node, AST8__namespace.is(types.AST_NODE_TYPES.ObjectExpression));
409
+ if (prop == null) return false;
410
+ return prop === call.arguments[1];
411
+ }
412
+ function isChildrenOfCreateElement(context, node) {
413
+ const parent = node.parent;
414
+ if (parent == null || parent.type !== types.AST_NODE_TYPES.CallExpression) return false;
415
+ if (!isCreateElementCall(context, parent)) return false;
416
+ return parent.arguments.slice(2).some((arg) => arg === node);
417
+ }
397
418
  function isClassComponent(node) {
398
419
  if ("superClass" in node && node.superClass != null) {
399
420
  const re = /^(?:Pure)?Component$/u;
@@ -421,28 +442,28 @@ function isPureComponent(node) {
421
442
 
422
443
  // src/component/component-lifecycle.ts
423
444
  function isComponentDidMount(node) {
424
- return AST9__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentDidMount";
445
+ return AST8__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentDidMount";
425
446
  }
426
447
  function isComponentWillUnmount(node) {
427
- return AST9__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentWillUnmount";
448
+ return AST8__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentWillUnmount";
428
449
  }
429
450
  function isComponentDidCatch(node) {
430
- return AST9__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentDidCatch";
451
+ return AST8__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentDidCatch";
431
452
  }
432
453
  function isGetDerivedStateFromError(node) {
433
- return AST9__namespace.isMethodOrProperty(node) && node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromError";
454
+ return AST8__namespace.isMethodOrProperty(node) && node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromError";
434
455
  }
435
456
  function isGetDerivedStateFromProps(node) {
436
- return AST9__namespace.isMethodOrProperty(node) && node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromProps";
457
+ return AST8__namespace.isMethodOrProperty(node) && node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromProps";
437
458
  }
438
459
  function isFunctionOfComponentDidMount(node) {
439
- return AST9__namespace.isFunction(node) && isComponentDidMount(node.parent) && node.parent.value === node;
460
+ return AST8__namespace.isFunction(node) && isComponentDidMount(node.parent) && node.parent.value === node;
440
461
  }
441
462
  function isFunctionOfComponentWillUnmount(node) {
442
- return AST9__namespace.isFunction(node) && isComponentWillUnmount(node.parent) && node.parent.value === node;
463
+ return AST8__namespace.isFunction(node) && isComponentWillUnmount(node.parent) && node.parent.value === node;
443
464
  }
444
465
  function isRenderMethodLike(node) {
445
- return AST9__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "render" && node.parent.parent.type === types.AST_NODE_TYPES.ClassDeclaration;
466
+ return AST8__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "render" && node.parent.parent.type === types.AST_NODE_TYPES.ClassDeclaration;
446
467
  }
447
468
  function isFunctionOfRenderMethod(node) {
448
469
  if (!isRenderMethodLike(node.parent)) {
@@ -451,21 +472,46 @@ function isFunctionOfRenderMethod(node) {
451
472
  return isClassComponent(node.parent.parent.parent);
452
473
  }
453
474
  function isInsideRenderMethod(node) {
454
- return AST9__namespace.findParentNode(node, (node2) => isRenderMethodLike(node2) && isClassComponent(node2.parent.parent)) != null;
475
+ return AST8__namespace.findParentNode(node, (node2) => isRenderMethodLike(node2) && isClassComponent(node2.parent.parent)) != null;
455
476
  }
456
- var RE_COMPONENT_NAME = /^_?[A-Z]/u;
457
- function getComponentNameFromIdentifier(node) {
458
- if (node == null) return eff._;
459
- return Array.isArray(node) ? node.map((n) => n.name).join(".") : node.name;
477
+
478
+ // src/component/hierarchy.ts
479
+ function hasValidHierarchy(context, node, hint) {
480
+ if (isChildrenOfCreateElement(context, node) || isFunctionOfRenderMethod(node)) {
481
+ return false;
482
+ }
483
+ if (hint & ERComponentHint.SkipMapCallback && AST8__namespace.isMapCallLoose(node.parent)) {
484
+ return false;
485
+ }
486
+ if (hint & ERComponentHint.SkipObjectMethod && isFunctionOfObjectMethod(node.parent)) {
487
+ return false;
488
+ }
489
+ if (hint & ERComponentHint.SkipClassMethod && isFunctionOfClassMethod(node.parent)) {
490
+ return false;
491
+ }
492
+ if (hint & ERComponentHint.SkipClassProperty && isFunctionOfClassProperty(node.parent)) {
493
+ return false;
494
+ }
495
+ const boundaryNode = AST8__namespace.findParentNode(
496
+ node,
497
+ AST8__namespace.isOneOf([
498
+ types.AST_NODE_TYPES.JSXExpressionContainer,
499
+ types.AST_NODE_TYPES.ArrowFunctionExpression,
500
+ types.AST_NODE_TYPES.FunctionExpression,
501
+ types.AST_NODE_TYPES.Property,
502
+ types.AST_NODE_TYPES.ClassBody
503
+ ])
504
+ );
505
+ return boundaryNode == null || boundaryNode.type !== types.AST_NODE_TYPES.JSXExpressionContainer;
460
506
  }
461
- function isComponentName(name) {
462
- return RE_COMPONENT_NAME.test(name);
507
+ function isFunctionOfClassMethod(node) {
508
+ return (node.type === types.AST_NODE_TYPES.FunctionExpression || node.type === types.AST_NODE_TYPES.ArrowFunctionExpression) && node.parent.type === types.AST_NODE_TYPES.MethodDefinition;
463
509
  }
464
- function hasNoneOrValidComponentName(node, context) {
465
- const id = getFunctionComponentIdentifier(node, context);
466
- if (id == null) return true;
467
- const name = Array.isArray(id) ? id.at(-1)?.name : id.name;
468
- return name != null && isComponentName(name);
510
+ function isFunctionOfClassProperty(node) {
511
+ return (node.type === types.AST_NODE_TYPES.FunctionExpression || node.type === types.AST_NODE_TYPES.ArrowFunctionExpression) && node.parent.type === types.AST_NODE_TYPES.Property;
512
+ }
513
+ function isFunctionOfObjectMethod(node) {
514
+ return (node.type === types.AST_NODE_TYPES.FunctionExpression || node.type === types.AST_NODE_TYPES.ArrowFunctionExpression) && node.parent.type === types.AST_NODE_TYPES.Property && node.parent.parent.type === types.AST_NODE_TYPES.ObjectExpression;
469
515
  }
470
516
 
471
517
  // src/component/component-collector.ts
@@ -483,7 +529,7 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT, options =
483
529
  const entry = functionEntries.at(-1);
484
530
  if (entry == null) return;
485
531
  if (!entry.isComponent) return functionEntries.pop();
486
- const shouldDrop = AST9__namespace.getNestedReturnStatements(entry.node.body).slice().reverse().some((r) => {
532
+ const shouldDrop = AST8__namespace.getNestedReturnStatements(entry.node.body).slice().reverse().some((r) => {
487
533
  return context.sourceCode.getScope(r).block === entry.node && r.argument != null && !JSX3__namespace.isJSXValue(r.argument, jsxCtx, hint);
488
534
  });
489
535
  if (shouldDrop) {
@@ -508,10 +554,10 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT, options =
508
554
  const entry = getCurrentEntry();
509
555
  if (entry == null) return;
510
556
  const { body } = entry.node;
511
- const isComponent = hasNoneOrValidComponentName(entry.node, context) && JSX3__namespace.isJSXValue(body, jsxCtx, hint) && hasValidHierarchy(entry.node, context, hint);
557
+ const isComponent = hasNoneOrValidComponentName(context, entry.node) && JSX3__namespace.isJSXValue(body, jsxCtx, hint) && hasValidHierarchy(context, entry.node, hint);
512
558
  if (!isComponent) return;
513
- const initPath = AST9__namespace.getFunctionInitPath(entry.node);
514
- const id = getFunctionComponentIdentifier(entry.node, context);
559
+ const initPath = AST8__namespace.getFunctionInitPath(entry.node);
560
+ const id = getFunctionComponentIdentifier(context, entry.node);
515
561
  const name = getComponentNameFromIdentifier(id);
516
562
  const key = shared.getId();
517
563
  components.set(key, {
@@ -548,11 +594,11 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT, options =
548
594
  "ReturnStatement[type]"(node) {
549
595
  const entry = getCurrentEntry();
550
596
  if (entry == null) return;
551
- const isComponent = hasNoneOrValidComponentName(entry.node, context) && JSX3__namespace.isJSXValue(node.argument, jsxCtx, hint) && hasValidHierarchy(entry.node, context, hint);
597
+ const isComponent = hasNoneOrValidComponentName(context, entry.node) && JSX3__namespace.isJSXValue(node.argument, jsxCtx, hint) && hasValidHierarchy(context, entry.node, hint);
552
598
  if (!isComponent) return;
553
599
  entry.isComponent = true;
554
- const initPath = AST9__namespace.getFunctionInitPath(entry.node);
555
- const id = getFunctionComponentIdentifier(entry.node, context);
600
+ const initPath = AST8__namespace.getFunctionInitPath(entry.node);
601
+ const id = getFunctionComponentIdentifier(context, entry.node);
556
602
  const name = getComponentNameFromIdentifier(id);
557
603
  components.set(entry.key, {
558
604
  id,
@@ -570,40 +616,12 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT, options =
570
616
  };
571
617
  return { ctx, listeners };
572
618
  }
573
- function hasValidHierarchy(node, context, hint) {
574
- if (isChildrenOfCreateElement(node, context) || isFunctionOfRenderMethod(node)) {
575
- return false;
576
- }
577
- if (hint & ERComponentHint.SkipMapCallback && AST9__namespace.isMapCallLoose(node.parent)) {
578
- return false;
579
- }
580
- if (hint & ERComponentHint.SkipObjectMethod && AST9__namespace.isFunctionOfObjectMethod(node.parent)) {
581
- return false;
582
- }
583
- if (hint & ERComponentHint.SkipClassMethod && AST9__namespace.isFunctionOfClassMethod(node.parent)) {
584
- return false;
585
- }
586
- if (hint & ERComponentHint.SkipClassProperty && AST9__namespace.isFunctionOfClassProperty(node.parent)) {
587
- return false;
588
- }
589
- const boundaryNode = AST9__namespace.findParentNode(
590
- node,
591
- AST9__namespace.isOneOf([
592
- types.AST_NODE_TYPES.JSXExpressionContainer,
593
- types.AST_NODE_TYPES.ArrowFunctionExpression,
594
- types.AST_NODE_TYPES.FunctionExpression,
595
- types.AST_NODE_TYPES.Property,
596
- types.AST_NODE_TYPES.ClassBody
597
- ])
598
- );
599
- return boundaryNode == null || boundaryNode.type !== types.AST_NODE_TYPES.JSXExpressionContainer;
600
- }
601
619
  function getComponentFlag(initPath) {
602
620
  let flag = ERComponentFlag.None;
603
- if (initPath != null && AST9__namespace.hasCallInFunctionInitPath("memo", initPath)) {
621
+ if (initPath != null && AST8__namespace.hasCallInFunctionInitPath("memo", initPath)) {
604
622
  flag |= ERComponentFlag.Memo;
605
623
  }
606
- if (initPath != null && AST9__namespace.hasCallInFunctionInitPath("forwardRef", initPath)) {
624
+ if (initPath != null && AST8__namespace.hasCallInFunctionInitPath("forwardRef", initPath)) {
607
625
  flag |= ERComponentFlag.ForwardRef;
608
626
  }
609
627
  return flag;
@@ -620,7 +638,7 @@ function useComponentCollectorLegacy() {
620
638
  if (!isClassComponent(node)) {
621
639
  return;
622
640
  }
623
- const id = AST9__namespace.getClassIdentifier(node);
641
+ const id = AST8__namespace.getClassIdentifier(node);
624
642
  const key = shared.getId();
625
643
  const flag = isPureComponent(node) ? ERComponentFlag.PureComponent : ERComponentFlag.None;
626
644
  components.set(
@@ -651,9 +669,9 @@ var ERPhaseRelevance = birecord__default.default({
651
669
  setup: "cleanup"
652
670
  });
653
671
  var isInversePhase = eff.dual(2, (a, b) => ERPhaseRelevance.get(a) === b);
654
- function isRenderFunctionLoose(node, context) {
672
+ function isRenderFunctionLoose(context, node) {
655
673
  const { body, parent } = node;
656
- if (AST9__namespace.getFunctionIdentifier(node)?.name.startsWith("render")) {
674
+ if (AST8__namespace.getFunctionIdentifier(node)?.name.startsWith("render")) {
657
675
  return parent.type === types.AST_NODE_TYPES.JSXExpressionContainer && parent.parent.type === types.AST_NODE_TYPES.JSXAttribute && parent.parent.name.type === types.AST_NODE_TYPES.JSXIdentifier && parent.parent.name.name.startsWith("render");
658
676
  }
659
677
  return JSX3__namespace.isJSXValue(
@@ -664,11 +682,11 @@ function isRenderFunctionLoose(node, context) {
664
682
  JSX3__namespace.JSXValueHint.SkipNullLiteral | JSX3__namespace.JSXValueHint.SkipUndefined | JSX3__namespace.JSXValueHint.StrictLogical | JSX3__namespace.JSXValueHint.StrictConditional
665
683
  );
666
684
  }
667
- function isRenderPropLoose(node, context) {
685
+ function isRenderPropLoose(context, node) {
668
686
  if (node.name.type !== types.AST_NODE_TYPES.JSXIdentifier) {
669
687
  return false;
670
688
  }
671
- return node.name.name.startsWith("render") && node.value?.type === types.AST_NODE_TYPES.JSXExpressionContainer && AST9__namespace.isFunction(node.value.expression) && isRenderFunctionLoose(node.value.expression, context);
689
+ return node.name.name.startsWith("render") && node.value?.type === types.AST_NODE_TYPES.JSXExpressionContainer && AST8__namespace.isFunction(node.value.expression) && isRenderFunctionLoose(context, node.value.expression);
672
690
  }
673
691
  function isDirectValueOfRenderPropertyLoose(node) {
674
692
  const matching = (node2) => {
@@ -680,7 +698,7 @@ function isDeclaredInRenderPropLoose(node) {
680
698
  if (isDirectValueOfRenderPropertyLoose(node)) {
681
699
  return true;
682
700
  }
683
- const parent = AST9__namespace.findParentNode(node, AST9__namespace.is(types.AST_NODE_TYPES.JSXExpressionContainer))?.parent;
701
+ const parent = AST8__namespace.findParentNode(node, AST8__namespace.is(types.AST_NODE_TYPES.JSXExpressionContainer))?.parent;
684
702
  if (parent?.type !== types.AST_NODE_TYPES.JSXAttribute) {
685
703
  return false;
686
704
  }
@@ -688,16 +706,16 @@ function isDeclaredInRenderPropLoose(node) {
688
706
  }
689
707
  function isThisSetState(node) {
690
708
  const { callee } = node;
691
- return callee.type === types.AST_NODE_TYPES.MemberExpression && AST9__namespace.isThisExpression(callee.object) && callee.property.type === types.AST_NODE_TYPES.Identifier && callee.property.name === "setState";
709
+ return callee.type === types.AST_NODE_TYPES.MemberExpression && AST8__namespace.isThisExpression(callee.object) && callee.property.type === types.AST_NODE_TYPES.Identifier && callee.property.name === "setState";
692
710
  }
693
711
  function isFunctionOfUseEffectSetup(node) {
694
712
  if (node == null) return eff._;
695
713
  return node.parent?.type === types.AST_NODE_TYPES.CallExpression && node.parent.callee !== node && node.parent.callee.type === types.AST_NODE_TYPES.Identifier && node.parent.arguments.at(0) === node && isUseEffectCallLoose(node.parent);
696
714
  }
697
715
  function isFunctionOfUseEffectCleanup(node) {
698
- const nearReturn = AST9__namespace.findParentNode(node, AST9__namespace.is(types.AST_NODE_TYPES.ReturnStatement));
699
- const nearFunction = AST9__namespace.findParentNode(node, AST9__namespace.isFunction);
700
- const nearFunctionOfReturn = AST9__namespace.findParentNode(nearReturn, AST9__namespace.isFunction);
716
+ const nearReturn = AST8__namespace.findParentNode(node, AST8__namespace.is(types.AST_NODE_TYPES.ReturnStatement));
717
+ const nearFunction = AST8__namespace.findParentNode(node, AST8__namespace.isFunction);
718
+ const nearFunctionOfReturn = AST8__namespace.findParentNode(nearReturn, AST8__namespace.isFunction);
701
719
  return nearFunction === nearFunctionOfReturn && isFunctionOfUseEffectSetup(nearFunction);
702
720
  }
703
721
 
@@ -711,6 +729,7 @@ exports.RE_HOOK_NAME = RE_HOOK_NAME;
711
729
  exports.getComponentNameFromIdentifier = getComponentNameFromIdentifier;
712
730
  exports.getFunctionComponentIdentifier = getFunctionComponentIdentifier;
713
731
  exports.hasNoneOrValidComponentName = hasNoneOrValidComponentName;
732
+ exports.hasValidHierarchy = hasValidHierarchy;
714
733
  exports.isCallFromReact = isCallFromReact;
715
734
  exports.isCallFromReactMember = isCallFromReactMember;
716
735
  exports.isChildrenCount = isChildrenCount;
@@ -743,7 +762,11 @@ exports.isDisplayNameAssignment = isDisplayNameAssignment;
743
762
  exports.isForwardRef = isForwardRef;
744
763
  exports.isForwardRefCall = isForwardRefCall;
745
764
  exports.isFromReact = isFromReact;
765
+ exports.isFromReactLoose = isFromReactLoose;
746
766
  exports.isFromReactMember = isFromReactMember;
767
+ exports.isFromReactMemberLoose = isFromReactMemberLoose;
768
+ exports.isFromReactMemberStrict = isFromReactMemberStrict;
769
+ exports.isFromReactStrict = isFromReactStrict;
747
770
  exports.isFunctionOfComponentDidMount = isFunctionOfComponentDidMount;
748
771
  exports.isFunctionOfComponentWillUnmount = isFunctionOfComponentWillUnmount;
749
772
  exports.isFunctionOfRenderMethod = isFunctionOfRenderMethod;