@eslint-react/core 1.23.2 → 1.23.3-beta.5

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,13 +1,13 @@
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 JSX4 = require('@eslint-react/jsx');
6
- var types = require('@typescript-eslint/types');
6
+ var types$1 = require('@typescript-eslint/types');
7
7
  var tsPattern = require('ts-pattern');
8
8
  var shared = require('@eslint-react/shared');
9
9
  var VAR = require('@eslint-react/var');
10
- var types$1 = require('@eslint-react/types');
10
+ var types = require('@eslint-react/types');
11
11
 
12
12
  function _interopNamespace(e) {
13
13
  if (e && e.__esModule) return e;
@@ -27,17 +27,21 @@ function _interopNamespace(e) {
27
27
  return Object.freeze(n);
28
28
  }
29
29
 
30
- var AST9__namespace = /*#__PURE__*/_interopNamespace(AST9);
30
+ var AST8__namespace = /*#__PURE__*/_interopNamespace(AST8);
31
31
  var JSX4__namespace = /*#__PURE__*/_interopNamespace(JSX4);
32
32
  var VAR__namespace = /*#__PURE__*/_interopNamespace(VAR);
33
33
 
34
34
  // src/component/component-collector.ts
35
35
  function getElementRepresentName(node, context) {
36
36
  const rawElementName = JSX4__namespace.getElementName(node);
37
- if (rawElementName === rawElementName.toLowerCase()) return rawElementName;
37
+ if (rawElementName === rawElementName.toLowerCase()) {
38
+ return rawElementName;
39
+ }
38
40
  const { components, polymorphicPropName } = shared.getSettingsFromContext(context);
39
41
  const asElementName = components.get(rawElementName);
40
- if (eff.isString(asElementName)) return asElementName;
42
+ if (eff.isString(asElementName)) {
43
+ return asElementName;
44
+ }
41
45
  return eff.F.pipe(
42
46
  eff.O.fromNullable(polymorphicPropName),
43
47
  eff.O.flatMap(JSX4__namespace.findPropInAttributes(node.attributes, context.sourceCode.getScope(node))),
@@ -63,14 +67,14 @@ function isFromReact(name) {
63
67
  return (node, context) => {
64
68
  const settings = shared.unsafeDecodeSettings(context.settings);
65
69
  if (!settings.strictImportCheck) {
66
- if (node.type === types.AST_NODE_TYPES.MemberExpression) {
67
- return node.object.type === types.AST_NODE_TYPES.Identifier && node.property.type === types.AST_NODE_TYPES.Identifier && node.property.name === name;
70
+ if (node.type === types$1.AST_NODE_TYPES.MemberExpression) {
71
+ return node.object.type === types$1.AST_NODE_TYPES.Identifier && node.property.type === types$1.AST_NODE_TYPES.Identifier && node.property.name === name;
68
72
  }
69
73
  return node.name === name;
70
74
  }
71
75
  const initialScope = context.sourceCode.getScope(node);
72
- if (node.type === types.AST_NODE_TYPES.MemberExpression) {
73
- 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, initialScope, settings.importSource);
76
+ if (node.type === types$1.AST_NODE_TYPES.MemberExpression) {
77
+ return node.object.type === types$1.AST_NODE_TYPES.Identifier && node.property.type === types$1.AST_NODE_TYPES.Identifier && node.property.name === name && isInitializedFromReact(node.object.name, initialScope, settings.importSource);
74
78
  }
75
79
  if (node.name === name) {
76
80
  return isInitializedFromReact(name, initialScope, settings.importSource);
@@ -82,19 +86,25 @@ function isFromReactMember(memberName, name) {
82
86
  return (node, context) => {
83
87
  const settings = shared.unsafeDecodeSettings(context.settings);
84
88
  if (!settings.strictImportCheck) {
85
- if (node.property.type !== types.AST_NODE_TYPES.Identifier || node.property.name !== name) return false;
86
- if (node.object.type === types.AST_NODE_TYPES.Identifier && node.object.name === memberName) return true;
87
- 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) {
89
+ if (node.property.type !== types$1.AST_NODE_TYPES.Identifier || node.property.name !== name) {
90
+ return false;
91
+ }
92
+ if (node.object.type === types$1.AST_NODE_TYPES.Identifier && node.object.name === memberName) {
93
+ return true;
94
+ }
95
+ if (node.object.type === types$1.AST_NODE_TYPES.MemberExpression && node.object.object.type === types$1.AST_NODE_TYPES.Identifier && node.object.property.type === types$1.AST_NODE_TYPES.Identifier) {
88
96
  return node.object.property.name === memberName;
89
97
  }
90
98
  return false;
91
99
  }
92
100
  const initialScope = context.sourceCode.getScope(node);
93
- if (node.property.type !== types.AST_NODE_TYPES.Identifier || node.property.name !== name) return false;
94
- if (node.object.type === types.AST_NODE_TYPES.Identifier && node.object.name === memberName) {
101
+ if (node.property.type !== types$1.AST_NODE_TYPES.Identifier || node.property.name !== name) {
102
+ return false;
103
+ }
104
+ if (node.object.type === types$1.AST_NODE_TYPES.Identifier && node.object.name === memberName) {
95
105
  return isInitializedFromReact(node.object.name, initialScope, settings.importSource);
96
106
  }
97
- if (node.object.type === types.AST_NODE_TYPES.MemberExpression && node.object.object.type === types.AST_NODE_TYPES.Identifier && isInitializedFromReact(node.object.object.name, initialScope, settings.importSource) && node.object.property.type === types.AST_NODE_TYPES.Identifier) {
107
+ if (node.object.type === types$1.AST_NODE_TYPES.MemberExpression && node.object.object.type === types$1.AST_NODE_TYPES.Identifier && isInitializedFromReact(node.object.object.name, initialScope, settings.importSource) && node.object.property.type === types$1.AST_NODE_TYPES.Identifier) {
98
108
  return node.object.property.name === memberName;
99
109
  }
100
110
  return false;
@@ -102,15 +112,23 @@ function isFromReactMember(memberName, name) {
102
112
  }
103
113
  function isCallFromReact(name) {
104
114
  return eff.F.dual(2, (node, context) => {
105
- if (node.type !== types.AST_NODE_TYPES.CallExpression) return false;
106
- if (!AST9__namespace.isOneOf([types.AST_NODE_TYPES.Identifier, types.AST_NODE_TYPES.MemberExpression])(node.callee)) return false;
115
+ if (node.type !== types$1.AST_NODE_TYPES.CallExpression) {
116
+ return false;
117
+ }
118
+ if (!AST8__namespace.isOneOf([types$1.AST_NODE_TYPES.Identifier, types$1.AST_NODE_TYPES.MemberExpression])(node.callee)) {
119
+ return false;
120
+ }
107
121
  return isFromReact(name)(node.callee, context);
108
122
  });
109
123
  }
110
124
  function isCallFromReactMember(pragmaMemberName, name) {
111
125
  return eff.F.dual(2, (node, context) => {
112
- if (node.type !== types.AST_NODE_TYPES.CallExpression) return false;
113
- if (!AST9__namespace.is(types.AST_NODE_TYPES.MemberExpression)(node.callee)) return false;
126
+ if (node.type !== types$1.AST_NODE_TYPES.CallExpression) {
127
+ return false;
128
+ }
129
+ if (!AST8__namespace.is(types$1.AST_NODE_TYPES.MemberExpression)(node.callee)) {
130
+ return false;
131
+ }
114
132
  return isFromReactMember(pragmaMemberName, name)(node.callee, context);
115
133
  });
116
134
  }
@@ -149,8 +167,8 @@ var isMemoCall = isReactAPICallWithName("memo");
149
167
  function isInsideCreateElementProps(node, context) {
150
168
  return eff.F.pipe(
151
169
  eff.O.Do,
152
- eff.O.bind("call", () => AST9__namespace.findParentNodeGuard(node, isCreateElementCall(context))),
153
- eff.O.bind("prop", () => AST9__namespace.findParentNodeGuard(node, AST9__namespace.is(types.AST_NODE_TYPES.ObjectExpression))),
170
+ eff.O.bind("call", () => AST8__namespace.findParentNodeGuard(node, isCreateElementCall(context))),
171
+ eff.O.bind("prop", () => AST8__namespace.findParentNodeGuard(node, AST8__namespace.is(types$1.AST_NODE_TYPES.ObjectExpression))),
154
172
  eff.O.bind("arg1", ({ call }) => eff.O.fromNullable(call.arguments[1])),
155
173
  eff.O.exists(({ arg1, prop }) => prop === arg1)
156
174
  );
@@ -158,7 +176,7 @@ function isInsideCreateElementProps(node, context) {
158
176
  function isChildrenOfCreateElement(node, context) {
159
177
  return eff.F.pipe(
160
178
  eff.O.fromNullable(node.parent),
161
- eff.O.filter(AST9__namespace.is(types.AST_NODE_TYPES.CallExpression)),
179
+ eff.O.filter(AST8__namespace.is(types$1.AST_NODE_TYPES.CallExpression)),
162
180
  eff.O.filter(isCreateElementCall(context)),
163
181
  eff.O.exists(
164
182
  (n) => n.arguments.slice(2).some((arg) => arg === node)
@@ -175,16 +193,20 @@ function isReactHookName(name) {
175
193
  // src/hook/is.ts
176
194
  function isReactHook(node) {
177
195
  return eff.F.pipe(
178
- AST9__namespace.getFunctionIdentifier(node),
196
+ AST8__namespace.getFunctionIdentifier(node),
179
197
  eff.O.flatMapNullable((id2) => id2.name),
180
198
  eff.O.exists(isReactHookName)
181
199
  );
182
200
  }
183
201
  function isReactHookCall(node) {
184
- if (node.type !== types.AST_NODE_TYPES.CallExpression) return false;
185
- if (node.callee.type === types.AST_NODE_TYPES.Identifier) return isReactHookName(node.callee.name);
186
- if (node.callee.type === types.AST_NODE_TYPES.MemberExpression) {
187
- return node.callee.property.type === types.AST_NODE_TYPES.Identifier && isReactHookName(node.callee.property.name);
202
+ if (node.type !== types$1.AST_NODE_TYPES.CallExpression) {
203
+ return false;
204
+ }
205
+ if (node.callee.type === types$1.AST_NODE_TYPES.Identifier) {
206
+ return isReactHookName(node.callee.name);
207
+ }
208
+ if (node.callee.type === types$1.AST_NODE_TYPES.MemberExpression) {
209
+ return node.callee.property.type === types$1.AST_NODE_TYPES.Identifier && isReactHookName(node.callee.property.name);
188
210
  }
189
211
  return false;
190
212
  }
@@ -193,9 +215,9 @@ function isReactHookCallWithName(node, context) {
193
215
  return (name) => {
194
216
  const initialScope = context.sourceCode.getScope(node);
195
217
  switch (true) {
196
- case (node.callee.type === types.AST_NODE_TYPES.Identifier && node.callee.name === name):
218
+ case (node.callee.type === types$1.AST_NODE_TYPES.Identifier && node.callee.name === name):
197
219
  return !settings.strictImportCheck || isInitializedFromReact(name, initialScope, settings.importSource);
198
- case (node.callee.type === types.AST_NODE_TYPES.MemberExpression && node.callee.property.type === types.AST_NODE_TYPES.Identifier && node.callee.property.name === name && "name" in node.callee.object):
220
+ case (node.callee.type === types$1.AST_NODE_TYPES.MemberExpression && node.callee.property.type === types$1.AST_NODE_TYPES.Identifier && node.callee.property.name === name && "name" in node.callee.object):
199
221
  return !settings.strictImportCheck || isInitializedFromReact(node.callee.object.name, initialScope, settings.importSource);
200
222
  default:
201
223
  return false;
@@ -205,10 +227,10 @@ function isReactHookCallWithName(node, context) {
205
227
  function isReactHookCallWithNameLoose(node) {
206
228
  return (name) => {
207
229
  switch (node.callee.type) {
208
- case types.AST_NODE_TYPES.Identifier:
230
+ case types$1.AST_NODE_TYPES.Identifier:
209
231
  return node.callee.name === name;
210
- case types.AST_NODE_TYPES.MemberExpression:
211
- return node.callee.property.type === types.AST_NODE_TYPES.Identifier && node.callee.property.name === name;
232
+ case types$1.AST_NODE_TYPES.MemberExpression:
233
+ return node.callee.property.type === types$1.AST_NODE_TYPES.Identifier && node.callee.property.name === name;
212
234
  default:
213
235
  return false;
214
236
  }
@@ -219,9 +241,9 @@ function isReactHookCallWithNameAlias(name, context, alias) {
219
241
  return (node) => {
220
242
  const initialScope = context.sourceCode.getScope(node);
221
243
  switch (true) {
222
- case (node.callee.type === types.AST_NODE_TYPES.Identifier && node.callee.name === name):
244
+ case (node.callee.type === types$1.AST_NODE_TYPES.Identifier && node.callee.name === name):
223
245
  return !settings.strictImportCheck || isInitializedFromReact(name, initialScope, settings.importSource);
224
- case (node.callee.type === types.AST_NODE_TYPES.MemberExpression && node.callee.property.type === types.AST_NODE_TYPES.Identifier && node.callee.property.name === name && "name" in node.callee.object):
246
+ case (node.callee.type === types$1.AST_NODE_TYPES.MemberExpression && node.callee.property.type === types$1.AST_NODE_TYPES.Identifier && node.callee.property.name === name && "name" in node.callee.object):
225
247
  return !settings.strictImportCheck || isInitializedFromReact(node.callee.object.name, initialScope, settings.importSource);
226
248
  default:
227
249
  return alias.some(isReactHookCallWithNameLoose(node));
@@ -229,12 +251,14 @@ function isReactHookCallWithNameAlias(name, context, alias) {
229
251
  };
230
252
  }
231
253
  function isUseEffectCallLoose(node) {
232
- if (node.type !== types.AST_NODE_TYPES.CallExpression) return false;
254
+ if (node.type !== types$1.AST_NODE_TYPES.CallExpression) {
255
+ return false;
256
+ }
233
257
  switch (node.callee.type) {
234
- case types.AST_NODE_TYPES.Identifier:
258
+ case types$1.AST_NODE_TYPES.Identifier:
235
259
  return /^use\w*Effect$/u.test(node.callee.name);
236
- case types.AST_NODE_TYPES.MemberExpression:
237
- return node.callee.property.type === types.AST_NODE_TYPES.Identifier && /^use\w*Effect$/u.test(node.callee.property.name);
260
+ case types$1.AST_NODE_TYPES.MemberExpression:
261
+ return node.callee.property.type === types$1.AST_NODE_TYPES.Identifier && /^use\w*Effect$/u.test(node.callee.property.name);
238
262
  default:
239
263
  return false;
240
264
  }
@@ -257,13 +281,13 @@ var isUseTransitionCall = eff.F.flip(isReactHookCallWithName)("useTransition");
257
281
 
258
282
  // src/hook/hierarchy.ts
259
283
  function isInsideReactHook(node) {
260
- return eff.O.exists(AST9__namespace.findParentNodeGuard(node, AST9__namespace.isFunction), isReactHook);
284
+ return eff.O.exists(AST8__namespace.findParentNodeGuard(node, AST8__namespace.isFunction), isReactHook);
261
285
  }
262
286
  function useHookCollector() {
263
287
  const hooks = /* @__PURE__ */ new Map();
264
288
  const fStack = [];
265
289
  const onFunctionEnter = (node) => {
266
- const id2 = AST9__namespace.getFunctionIdentifier(node);
290
+ const id2 = AST8__namespace.getFunctionIdentifier(node);
267
291
  const name = eff.O.flatMapNullable(id2, (id3) => id3.name);
268
292
  if (eff.O.isSome(id2) && eff.O.isSome(name) && isReactHookName(name.value)) {
269
293
  const key = getId();
@@ -297,9 +321,13 @@ function useHookCollector() {
297
321
  ":function[type]": onFunctionEnter,
298
322
  ":function[type]:exit": onFunctionExit,
299
323
  "CallExpression[type]"(node) {
300
- if (!isReactHookCall(node)) return;
324
+ if (!isReactHookCall(node)) {
325
+ return;
326
+ }
301
327
  const [fNode, hookId] = fStack.at(-1) ?? [];
302
- if (!fNode || !hookId) return;
328
+ if (!fNode || !hookId) {
329
+ return;
330
+ }
303
331
  eff.F.pipe(
304
332
  eff.O.Do,
305
333
  eff.O.bind("id", () => hookId),
@@ -334,7 +362,7 @@ var ERComponentHint = {
334
362
  // Skip function component defined on class property
335
363
  SkipClassProperty: 1n << 69n
336
364
  };
337
- var DEFAULT_COMPONENT_HINT = 0n | ERComponentHint.SkipBooleanLiteral | ERComponentHint.SkipMapCallback | ERComponentHint.SkipNumberLiteral | ERComponentHint.SkipStringLiteral | ERComponentHint.SkipUndefinedLiteral | ERComponentHint.SkipEmptyArray | ERComponentHint.StrictArray | ERComponentHint.StrictConditional | ERComponentHint.StrictLogical;
365
+ var DEFAULT_COMPONENT_HINT = 0n | ERComponentHint.SkipBooleanLiteral | ERComponentHint.SkipMapCallback | ERComponentHint.SkipNumberLiteral | ERComponentHint.SkipStringLiteral | ERComponentHint.SkipUndefined | ERComponentHint.SkipEmptyArray | ERComponentHint.StrictArray | ERComponentHint.StrictConditional | ERComponentHint.StrictLogical;
338
366
 
339
367
  // src/component/component-flag.ts
340
368
  var ERClassComponentFlag = {
@@ -355,17 +383,21 @@ var ERFunctionComponentFlag = {
355
383
  // Async: 1n << 4n,
356
384
  };
357
385
  function isComponentWrapperCall(node, context) {
358
- if (node.type !== types.AST_NODE_TYPES.CallExpression) return false;
386
+ if (node.type !== types$1.AST_NODE_TYPES.CallExpression) {
387
+ return false;
388
+ }
359
389
  return isMemoCall(node, context) || isForwardRefCall(node, context) || isReactHookCallWithNameLoose(node)("useCallback");
360
390
  }
361
391
  function getFunctionComponentIdentifier(node, context) {
362
- const functionId = AST9__namespace.getFunctionIdentifier(node);
363
- if (eff.O.isSome(functionId)) return functionId;
392
+ const functionId = AST8__namespace.getFunctionIdentifier(node);
393
+ if (eff.O.isSome(functionId)) {
394
+ return functionId;
395
+ }
364
396
  const { parent } = node;
365
- 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) {
397
+ if (parent.type === types$1.AST_NODE_TYPES.CallExpression && isComponentWrapperCall(parent, context) && parent.parent.type === types$1.AST_NODE_TYPES.VariableDeclarator && parent.parent.id.type === types$1.AST_NODE_TYPES.Identifier) {
366
398
  return eff.O.some(parent.parent.id);
367
399
  }
368
- 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) {
400
+ if (parent.type === types$1.AST_NODE_TYPES.CallExpression && isComponentWrapperCall(parent, context) && parent.parent.type === types$1.AST_NODE_TYPES.CallExpression && isComponentWrapperCall(parent.parent, context) && parent.parent.parent.type === types$1.AST_NODE_TYPES.VariableDeclarator && parent.parent.parent.id.type === types$1.AST_NODE_TYPES.Identifier) {
369
401
  return eff.O.some(parent.parent.parent.id);
370
402
  }
371
403
  return eff.O.none();
@@ -380,98 +412,42 @@ function isComponentName(name) {
380
412
  return !!name && RE_COMPONENT_NAME.test(name);
381
413
  }
382
414
  function isClassComponent(node) {
383
- if (!("superClass" in node && node.superClass)) return false;
384
- const { superClass } = node;
385
- return tsPattern.match(superClass).with({
386
- type: types.AST_NODE_TYPES.Identifier,
387
- name: tsPattern.P.string
388
- }, ({ name }) => /^(?:Pure)?Component$/u.test(name)).with({
389
- type: types.AST_NODE_TYPES.MemberExpression,
390
- property: { name: tsPattern.P.string }
391
- }, ({ property }) => /^(?:Pure)?Component$/u.test(property.name)).otherwise(() => false);
392
- }
393
- function isPureComponent(node) {
394
415
  if ("superClass" in node && node.superClass) {
395
- return tsPattern.match(node.superClass).with({
396
- type: types.AST_NODE_TYPES.Identifier,
397
- name: tsPattern.P.string
398
- }, ({ name }) => /^PureComponent$/u.test(name)).with({
399
- type: types.AST_NODE_TYPES.MemberExpression,
400
- property: { name: tsPattern.P.string }
401
- }, ({ property }) => /^PureComponent$/u.test(property.name)).otherwise(() => false);
416
+ const re = /^(?:Pure)?Component$/u;
417
+ switch (true) {
418
+ case node.superClass.type === types$1.AST_NODE_TYPES.Identifier:
419
+ return re.test(node.superClass.name);
420
+ case (node.superClass.type === types$1.AST_NODE_TYPES.MemberExpression && node.superClass.property.type === types$1.AST_NODE_TYPES.Identifier):
421
+ return re.test(node.superClass.property.name);
422
+ }
402
423
  }
403
424
  return false;
404
425
  }
405
- function isComponentDidMount(node) {
406
- return AST9__namespace.isOneOf([types.AST_NODE_TYPES.MethodDefinition, types.AST_NODE_TYPES.PropertyDefinition])(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentDidMount";
407
- }
408
- function isComponentWillUnmount(node) {
409
- return AST9__namespace.isOneOf([types.AST_NODE_TYPES.MethodDefinition, types.AST_NODE_TYPES.PropertyDefinition])(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentWillUnmount";
410
- }
411
- function isComponentDidMountFunction(node) {
412
- return AST9__namespace.isFunction(node) && isComponentDidMount(node.parent) && node.parent.value === node;
413
- }
414
- function isComponentWillUnmountFunction(node) {
415
- return AST9__namespace.isFunction(node) && isComponentWillUnmount(node.parent) && node.parent.value === node;
416
- }
417
- function useComponentCollectorLegacy() {
418
- const components = /* @__PURE__ */ new Map();
419
- const ctx = {
420
- getAllComponents(_) {
421
- return components;
426
+ function isPureComponent(node) {
427
+ if ("superClass" in node && node.superClass) {
428
+ const re = /^PureComponent$/u;
429
+ switch (true) {
430
+ case node.superClass.type === types$1.AST_NODE_TYPES.Identifier:
431
+ return re.test(node.superClass.name);
432
+ case (node.superClass.type === types$1.AST_NODE_TYPES.MemberExpression && node.superClass.property.type === types$1.AST_NODE_TYPES.Identifier):
433
+ return re.test(node.superClass.property.name);
422
434
  }
423
- };
424
- const collect = (node) => {
425
- if (!isClassComponent(node)) return;
426
- const id2 = AST9__namespace.getClassIdentifier(node);
427
- const key = getId();
428
- const flag = isPureComponent(node) ? ERClassComponentFlag.PureComponent : ERClassComponentFlag.None;
429
- components.set(
430
- key,
431
- {
432
- _: key,
433
- id: id2,
434
- kind: "class",
435
- name: eff.O.flatMapNullable(id2, (n) => n.name),
436
- node,
437
- // TODO: Get displayName of class component
438
- displayName: eff.O.none(),
439
- flag,
440
- hint: 0n,
441
- // TODO: Get methods of class component
442
- methods: []
443
- }
444
- );
445
- };
446
- const listeners = {
447
- "ClassDeclaration[type]": collect,
448
- "ClassExpression[type]": collect
449
- };
450
- return { ctx, listeners };
435
+ }
436
+ return false;
451
437
  }
452
438
 
453
439
  // src/component/component-render-method.ts
454
- var isRenderMethodLike = tsPattern.isMatching({
455
- key: {
456
- type: types.AST_NODE_TYPES.Identifier,
457
- name: "render"
458
- },
459
- type: tsPattern.P.union(types.AST_NODE_TYPES.MethodDefinition, types.AST_NODE_TYPES.PropertyDefinition),
460
- parent: {
461
- type: types.AST_NODE_TYPES.ClassBody,
462
- parent: {
463
- type: types.AST_NODE_TYPES.ClassDeclaration
464
- }
465
- }
466
- });
440
+ function isRenderMethodLike(node) {
441
+ return (node.type === types$1.AST_NODE_TYPES.MethodDefinition || node.type === types$1.AST_NODE_TYPES.PropertyDefinition) && node.key.type === types$1.AST_NODE_TYPES.Identifier && node.key.name === "render" && node.parent.parent.type === types$1.AST_NODE_TYPES.ClassDeclaration;
442
+ }
467
443
  function isFunctionOfRenderMethod(node) {
468
- if (!isRenderMethodLike(node.parent)) return false;
444
+ if (!isRenderMethodLike(node.parent)) {
445
+ return false;
446
+ }
469
447
  return isClassComponent(node.parent.parent.parent);
470
448
  }
471
449
  function isInsideRenderMethod(node) {
472
- return eff.O.isSome(AST9__namespace.findParentNode(node, (node2) => {
473
- return isRenderMethodLike(node2) && isClassComponent(node2.parent.parent);
474
- }));
450
+ return eff.O.isSome(AST8__namespace.findParentNode(node, (node2) => isRenderMethodLike(node2) && isClassComponent(node2.parent.parent)));
475
451
  }
476
452
  function hasNoneOrValidComponentName(node, context) {
477
453
  const mbIdentifier = getFunctionComponentIdentifier(node, context);
@@ -488,38 +464,38 @@ function hasValidHierarchy(node, context, hint) {
488
464
  if (isChildrenOfCreateElement(node, context) || isFunctionOfRenderMethod(node)) {
489
465
  return false;
490
466
  }
491
- if (hint & ERComponentHint.SkipMapCallback && AST9__namespace.isMapCallLoose(node.parent)) {
467
+ if (hint & ERComponentHint.SkipMapCallback && AST8__namespace.isMapCallLoose(node.parent)) {
492
468
  return false;
493
469
  }
494
- if (hint & ERComponentHint.SkipObjectMethod && AST9__namespace.isFunctionOfObjectMethod(node.parent)) {
470
+ if (hint & ERComponentHint.SkipObjectMethod && AST8__namespace.isFunctionOfObjectMethod(node.parent)) {
495
471
  return false;
496
472
  }
497
- if (hint & ERComponentHint.SkipClassMethod && AST9__namespace.isFunctionOfClassMethod(node.parent)) {
473
+ if (hint & ERComponentHint.SkipClassMethod && AST8__namespace.isFunctionOfClassMethod(node.parent)) {
498
474
  return false;
499
475
  }
500
- if (hint & ERComponentHint.SkipClassProperty && AST9__namespace.isFunctionOfClassProperty(node.parent)) {
476
+ if (hint & ERComponentHint.SkipClassProperty && AST8__namespace.isFunctionOfClassProperty(node.parent)) {
501
477
  return false;
502
478
  }
503
479
  return !eff.O.exists(
504
- AST9__namespace.findParentNode(
480
+ AST8__namespace.findParentNode(
505
481
  node,
506
- AST9__namespace.isOneOf([
507
- types.AST_NODE_TYPES.JSXExpressionContainer,
508
- types.AST_NODE_TYPES.ArrowFunctionExpression,
509
- types.AST_NODE_TYPES.FunctionExpression,
510
- types.AST_NODE_TYPES.Property,
511
- types.AST_NODE_TYPES.ClassBody
482
+ AST8__namespace.isOneOf([
483
+ types$1.AST_NODE_TYPES.JSXExpressionContainer,
484
+ types$1.AST_NODE_TYPES.ArrowFunctionExpression,
485
+ types$1.AST_NODE_TYPES.FunctionExpression,
486
+ types$1.AST_NODE_TYPES.Property,
487
+ types$1.AST_NODE_TYPES.ClassBody
512
488
  ])
513
489
  ),
514
- AST9__namespace.is(types.AST_NODE_TYPES.JSXExpressionContainer)
490
+ AST8__namespace.is(types$1.AST_NODE_TYPES.JSXExpressionContainer)
515
491
  );
516
492
  }
517
493
  function getComponentFlag(initPath) {
518
494
  let flag = ERFunctionComponentFlag.None;
519
- if (AST9__namespace.hasCallInFunctionInitPath("memo")(initPath)) {
495
+ if (AST8__namespace.hasCallInFunctionInitPath("memo")(initPath)) {
520
496
  flag |= ERFunctionComponentFlag.Memo;
521
497
  }
522
- if (AST9__namespace.hasCallInFunctionInitPath("forwardRef")(initPath)) {
498
+ if (AST8__namespace.hasCallInFunctionInitPath("forwardRef")(initPath)) {
523
499
  flag |= ERFunctionComponentFlag.ForwardRef;
524
500
  }
525
501
  return flag;
@@ -534,12 +510,16 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT) {
534
510
  functionEntries.push({ key, node, hookCalls: [], isComponent: false });
535
511
  };
536
512
  const onFunctionExit = () => {
537
- const { key, node, isComponent } = functionEntries.at(-1) ?? {};
538
- if (!key || !node || !isComponent) return functionEntries.pop();
539
- const shouldDrop = AST9__namespace.getNestedReturnStatements(node.body).slice().reverse().some((r) => {
540
- return context.sourceCode.getScope(r).block === node && r.argument !== null && !JSX4__namespace.isJSXValue(r.argument, jsxCtx, hint);
513
+ const entry = functionEntries.at(-1);
514
+ if (!entry?.isComponent) {
515
+ return functionEntries.pop();
516
+ }
517
+ const shouldDrop = AST8__namespace.getNestedReturnStatements(entry.node.body).slice().reverse().some((r) => {
518
+ return context.sourceCode.getScope(r).block === entry.node && r.argument !== null && !JSX4__namespace.isJSXValue(r.argument, jsxCtx, hint);
541
519
  });
542
- if (shouldDrop) components.delete(key);
520
+ if (shouldDrop) {
521
+ components.delete(entry.key);
522
+ }
543
523
  return functionEntries.pop();
544
524
  };
545
525
  const ctx = {
@@ -556,12 +536,16 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT) {
556
536
  ":function[type]:exit": onFunctionExit,
557
537
  "ArrowFunctionExpression[type][body.type!='BlockStatement']"() {
558
538
  const mbEntry = getCurrentFunction();
559
- if (eff.O.isNone(mbEntry)) return;
539
+ if (eff.O.isNone(mbEntry)) {
540
+ return;
541
+ }
560
542
  const entry = mbEntry.value;
561
543
  const { body } = entry.node;
562
544
  const isComponent = hasNoneOrValidComponentName(entry.node, context) && JSX4__namespace.isJSXValue(body, jsxCtx, hint) && hasValidHierarchy(entry.node, context, hint);
563
- if (!isComponent) return;
564
- const initPath = AST9__namespace.getFunctionInitPath(entry.node);
545
+ if (!isComponent) {
546
+ return;
547
+ }
548
+ const initPath = AST8__namespace.getFunctionInitPath(entry.node);
565
549
  const id2 = getFunctionComponentIdentifier(entry.node, context);
566
550
  const name = eff.O.flatMapNullable(id2, getComponentNameFromIdentifier);
567
551
  const key = getId();
@@ -580,33 +564,45 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT) {
580
564
  },
581
565
  "AssignmentExpression[type][operator='='][left.type='MemberExpression'][left.property.name='displayName']"(node) {
582
566
  const { left, right } = node;
583
- const mbComponentName = tsPattern.match(left.object).with({ type: types.AST_NODE_TYPES.Identifier }, (n) => eff.O.some(n.name)).otherwise(eff.O.none);
584
- if (eff.O.isNone(mbComponentName)) return;
567
+ const mbComponentName = tsPattern.match(left.object).with({ type: types$1.AST_NODE_TYPES.Identifier }, (n) => eff.O.some(n.name)).otherwise(eff.O.none);
568
+ if (eff.O.isNone(mbComponentName)) {
569
+ return;
570
+ }
585
571
  const componentName = mbComponentName.value;
586
572
  const component = Array.from(components.values()).findLast(({ name }) => eff.O.exists(name, (n) => n === componentName));
587
- if (!component) return;
573
+ if (!component) {
574
+ return;
575
+ }
588
576
  components.set(component._, {
589
577
  ...component,
590
578
  displayName: eff.O.some(right)
591
579
  });
592
580
  },
593
581
  "CallExpression[type]:exit"(node) {
594
- if (!isReactHookCall(node)) return;
582
+ if (!isReactHookCall(node)) {
583
+ return;
584
+ }
595
585
  const mbEntry = getCurrentFunction();
596
- if (eff.O.isNone(mbEntry)) return;
586
+ if (eff.O.isNone(mbEntry)) {
587
+ return;
588
+ }
597
589
  const entry = mbEntry.value;
598
590
  functionEntries.pop();
599
591
  functionEntries.push({ ...entry, hookCalls: [...entry.hookCalls, node] });
600
592
  },
601
593
  "ReturnStatement[type]"(node) {
602
594
  const mbEntry = getCurrentFunction();
603
- if (eff.O.isNone(mbEntry)) return;
595
+ if (eff.O.isNone(mbEntry)) {
596
+ return;
597
+ }
604
598
  const entry = mbEntry.value;
605
599
  const isComponent = hasNoneOrValidComponentName(entry.node, context) && JSX4__namespace.isJSXValue(node.argument, jsxCtx, hint) && hasValidHierarchy(entry.node, context, hint);
606
- if (!isComponent) return;
600
+ if (!isComponent) {
601
+ return;
602
+ }
607
603
  functionEntries.pop();
608
604
  functionEntries.push({ ...entry, isComponent });
609
- const initPath = AST9__namespace.getFunctionInitPath(entry.node);
605
+ const initPath = AST8__namespace.getFunctionInitPath(entry.node);
610
606
  const id2 = getFunctionComponentIdentifier(entry.node, context);
611
607
  const name = eff.O.flatMapNullable(id2, getComponentNameFromIdentifier);
612
608
  components.set(entry.key, {
@@ -625,18 +621,71 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT) {
625
621
  };
626
622
  return { ctx, listeners };
627
623
  }
624
+ function useComponentCollectorLegacy() {
625
+ const components = /* @__PURE__ */ new Map();
626
+ const ctx = {
627
+ getAllComponents(_) {
628
+ return components;
629
+ }
630
+ };
631
+ const collect = (node) => {
632
+ if (!isClassComponent(node)) {
633
+ return;
634
+ }
635
+ const id2 = AST8__namespace.getClassIdentifier(node);
636
+ const key = getId();
637
+ const flag = isPureComponent(node) ? ERClassComponentFlag.PureComponent : ERClassComponentFlag.None;
638
+ components.set(
639
+ key,
640
+ {
641
+ _: key,
642
+ id: id2,
643
+ kind: "class",
644
+ name: eff.O.flatMapNullable(id2, (n) => n.name),
645
+ node,
646
+ // TODO: Get displayName of class component
647
+ displayName: eff.O.none(),
648
+ flag,
649
+ hint: 0n,
650
+ // TODO: Get methods of class component
651
+ methods: []
652
+ }
653
+ );
654
+ };
655
+ const listeners = {
656
+ "ClassDeclaration[type]": collect,
657
+ "ClassExpression[type]": collect
658
+ };
659
+ return { ctx, listeners };
660
+ }
628
661
  function isSetupFunction(node) {
629
- 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);
662
+ return node.parent?.type === types$1.AST_NODE_TYPES.CallExpression && node.parent.callee !== node && node.parent.callee.type === types$1.AST_NODE_TYPES.Identifier && node.parent.arguments.at(0) === node && isUseEffectCallLoose(node.parent);
630
663
  }
631
664
  function isCleanupFunction(node) {
632
- const nearestRet = eff.O.getOrNull(AST9__namespace.findParentNodeGuard(node, AST9__namespace.is(types.AST_NODE_TYPES.ReturnStatement)));
633
- if (!nearestRet) return false;
634
- const nearestFunction = eff.O.getOrNull(AST9__namespace.findParentNodeGuard(node, AST9__namespace.isFunction));
635
- const nearestFunctionOfRet = eff.O.getOrNull(AST9__namespace.findParentNodeGuard(nearestRet, AST9__namespace.isFunction));
636
- if (!nearestFunction || !nearestFunctionOfRet) return false;
665
+ const nearestRet = eff.O.getOrNull(AST8__namespace.findParentNodeGuard(node, AST8__namespace.is(types$1.AST_NODE_TYPES.ReturnStatement)));
666
+ if (!nearestRet) {
667
+ return false;
668
+ }
669
+ const nearestFunction = eff.O.getOrNull(AST8__namespace.findParentNodeGuard(node, AST8__namespace.isFunction));
670
+ const nearestFunctionOfRet = eff.O.getOrNull(AST8__namespace.findParentNodeGuard(nearestRet, AST8__namespace.isFunction));
671
+ if (!nearestFunction || !nearestFunctionOfRet) {
672
+ return false;
673
+ }
637
674
  return nearestFunction === nearestFunctionOfRet && isSetupFunction(nearestFunction);
638
675
  }
639
- var ERPhaseRelevance = types$1.birecord({
676
+ function isComponentDidMount(node) {
677
+ return AST8__namespace.isOneOf([types$1.AST_NODE_TYPES.MethodDefinition, types$1.AST_NODE_TYPES.PropertyDefinition])(node) && node.key.type === types$1.AST_NODE_TYPES.Identifier && node.key.name === "componentDidMount";
678
+ }
679
+ function isComponentWillUnmount(node) {
680
+ return AST8__namespace.isOneOf([types$1.AST_NODE_TYPES.MethodDefinition, types$1.AST_NODE_TYPES.PropertyDefinition])(node) && node.key.type === types$1.AST_NODE_TYPES.Identifier && node.key.name === "componentWillUnmount";
681
+ }
682
+ function isComponentDidMountFunction(node) {
683
+ return AST8__namespace.isFunction(node) && isComponentDidMount(node.parent) && node.parent.value === node;
684
+ }
685
+ function isComponentWillUnmountFunction(node) {
686
+ return AST8__namespace.isFunction(node) && isComponentWillUnmount(node.parent) && node.parent.value === node;
687
+ }
688
+ var ERPhaseRelevance = types.birecord({
640
689
  mount: "unmount",
641
690
  setup: "cleanup"
642
691
  });
@@ -644,10 +693,10 @@ var isInversePhase = eff.F.dual(2, (a, b) => ERPhaseRelevance.get(a) === b);
644
693
  function isDirectValueOfRenderPropertyLoose(node) {
645
694
  const matching = tsPattern.isMatching({
646
695
  key: {
647
- type: types.AST_NODE_TYPES.Identifier,
696
+ type: types$1.AST_NODE_TYPES.Identifier,
648
697
  name: tsPattern.P.string.startsWith("render")
649
698
  },
650
- type: types.AST_NODE_TYPES.Property
699
+ type: types$1.AST_NODE_TYPES.Property
651
700
  });
652
701
  return matching(node) || matching(node.parent);
653
702
  }
@@ -656,36 +705,38 @@ function isDeclaredInRenderPropLoose(node) {
656
705
  return true;
657
706
  }
658
707
  return eff.F.pipe(
659
- AST9__namespace.findParentNodeGuard(node, AST9__namespace.is(types.AST_NODE_TYPES.JSXExpressionContainer)),
708
+ AST8__namespace.findParentNodeGuard(node, AST8__namespace.is(types$1.AST_NODE_TYPES.JSXExpressionContainer)),
660
709
  eff.O.flatMapNullable((c) => c.parent),
661
- eff.O.filter(AST9__namespace.is(types.AST_NODE_TYPES.JSXAttribute)),
710
+ eff.O.filter(AST8__namespace.is(types$1.AST_NODE_TYPES.JSXAttribute)),
662
711
  eff.O.flatMapNullable((a) => a.name),
663
712
  eff.O.exists(tsPattern.isMatching({
664
- type: types.AST_NODE_TYPES.JSXIdentifier,
713
+ type: types$1.AST_NODE_TYPES.JSXIdentifier,
665
714
  name: tsPattern.P.string.startsWith("render")
666
715
  }))
667
716
  );
668
717
  }
669
718
  function isRenderFunctionLoose(node, context) {
670
719
  const { body, parent } = node;
671
- if (eff.O.exists(AST9__namespace.getFunctionIdentifier(node), (id2) => id2.name.startsWith("render"))) {
672
- 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");
720
+ if (eff.O.exists(AST8__namespace.getFunctionIdentifier(node), (id2) => id2.name.startsWith("render"))) {
721
+ return parent.type === types$1.AST_NODE_TYPES.JSXExpressionContainer && parent.parent.type === types$1.AST_NODE_TYPES.JSXAttribute && parent.parent.name.type === types$1.AST_NODE_TYPES.JSXIdentifier && parent.parent.name.name.startsWith("render");
673
722
  }
674
723
  return JSX4__namespace.isJSXValue(
675
724
  body,
676
725
  {
677
726
  getScope: (node2) => context.sourceCode.getScope(node2)
678
727
  },
679
- JSX4__namespace.JSXValueHint.SkipNullLiteral | JSX4__namespace.JSXValueHint.SkipUndefinedLiteral | JSX4__namespace.JSXValueHint.StrictLogical | JSX4__namespace.JSXValueHint.StrictConditional
728
+ JSX4__namespace.JSXValueHint.SkipNullLiteral | JSX4__namespace.JSXValueHint.SkipUndefined | JSX4__namespace.JSXValueHint.StrictLogical | JSX4__namespace.JSXValueHint.StrictConditional
680
729
  );
681
730
  }
682
731
  function isRenderPropLoose(node, context) {
683
- if (node.name.type !== types.AST_NODE_TYPES.JSXIdentifier) return false;
684
- 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);
732
+ if (node.name.type !== types$1.AST_NODE_TYPES.JSXIdentifier) {
733
+ return false;
734
+ }
735
+ return node.name.name.startsWith("render") && node.value?.type === types$1.AST_NODE_TYPES.JSXExpressionContainer && AST8__namespace.isFunction(node.value.expression) && isRenderFunctionLoose(node.value.expression, context);
685
736
  }
686
737
  function isThisSetState(node) {
687
738
  const { callee } = node;
688
- 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";
739
+ return callee.type === types$1.AST_NODE_TYPES.MemberExpression && AST8__namespace.isThisExpression(callee.object) && callee.property.type === types$1.AST_NODE_TYPES.Identifier && callee.property.name === "setState";
689
740
  }
690
741
 
691
742
  exports.DEFAULT_COMPONENT_HINT = DEFAULT_COMPONENT_HINT;
@@ -752,6 +803,7 @@ exports.isReactHookCallWithNameAlias = isReactHookCallWithNameAlias;
752
803
  exports.isReactHookCallWithNameLoose = isReactHookCallWithNameLoose;
753
804
  exports.isReactHookName = isReactHookName;
754
805
  exports.isRenderFunctionLoose = isRenderFunctionLoose;
806
+ exports.isRenderMethodLike = isRenderMethodLike;
755
807
  exports.isRenderPropLoose = isRenderPropLoose;
756
808
  exports.isSetupFunction = isSetupFunction;
757
809
  exports.isThisSetState = isThisSetState;