@eslint-react/core 1.24.0-next.0 → 1.24.0-next.11
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.mts +134 -136
- package/dist/index.d.ts +134 -136
- package/dist/index.js +135 -146
- package/dist/index.mjs +125 -141
- package/package.json +11 -11
package/dist/index.js
CHANGED
|
@@ -2,10 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
var AST8 = require('@eslint-react/ast');
|
|
4
4
|
var eff = require('@eslint-react/eff');
|
|
5
|
-
var
|
|
5
|
+
var JSX3 = require('@eslint-react/jsx');
|
|
6
6
|
var types = require('@typescript-eslint/types');
|
|
7
|
-
var VAR = require('@eslint-react/var');
|
|
8
7
|
var shared = require('@eslint-react/shared');
|
|
8
|
+
var VAR = require('@eslint-react/var');
|
|
9
|
+
var birecord = require('birecord');
|
|
10
|
+
|
|
11
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
12
|
|
|
10
13
|
function _interopNamespace(e) {
|
|
11
14
|
if (e && e.__esModule) return e;
|
|
@@ -26,29 +29,11 @@ function _interopNamespace(e) {
|
|
|
26
29
|
}
|
|
27
30
|
|
|
28
31
|
var AST8__namespace = /*#__PURE__*/_interopNamespace(AST8);
|
|
29
|
-
var
|
|
32
|
+
var JSX3__namespace = /*#__PURE__*/_interopNamespace(JSX3);
|
|
30
33
|
var VAR__namespace = /*#__PURE__*/_interopNamespace(VAR);
|
|
34
|
+
var birecord__default = /*#__PURE__*/_interopDefault(birecord);
|
|
31
35
|
|
|
32
36
|
// src/component/component-collector.ts
|
|
33
|
-
function getElementNameAndRepresentName(node, context, polymorphicPropName, additionalComponents = []) {
|
|
34
|
-
const name = JSX4__namespace.getElementName(node);
|
|
35
|
-
if (name === name.toLowerCase()) return [name, name];
|
|
36
|
-
const component = additionalComponents.findLast((c) => c.name === name || c.re.test(name));
|
|
37
|
-
if (component !== eff._) return [name, component.as];
|
|
38
|
-
if (polymorphicPropName == null) return [name, name];
|
|
39
|
-
const initialScope = context.sourceCode.getScope(node);
|
|
40
|
-
const polymorphicProp = JSX4__namespace.findPropInAttributes(
|
|
41
|
-
polymorphicPropName,
|
|
42
|
-
initialScope,
|
|
43
|
-
node.attributes
|
|
44
|
-
);
|
|
45
|
-
if (polymorphicProp === eff._) return [name, name];
|
|
46
|
-
const polymorphicName = VAR__namespace.toResolved(JSX4__namespace.getPropValue(polymorphicProp, initialScope)).value;
|
|
47
|
-
if (typeof polymorphicName === "string") {
|
|
48
|
-
return [name, polymorphicName];
|
|
49
|
-
}
|
|
50
|
-
return [name, name];
|
|
51
|
-
}
|
|
52
37
|
|
|
53
38
|
// src/utils/get-id.ts
|
|
54
39
|
var id = 0n;
|
|
@@ -164,15 +149,15 @@ var isMemoCall = isReactAPICallWithName("memo");
|
|
|
164
149
|
|
|
165
150
|
// src/element/hierarchy.ts
|
|
166
151
|
function isInsideCreateElementProps(node, context) {
|
|
167
|
-
const call = AST8__namespace.
|
|
168
|
-
if (
|
|
169
|
-
const prop = AST8__namespace.
|
|
170
|
-
if (
|
|
152
|
+
const call = AST8__namespace.findParentNode(node, isCreateElementCall(context));
|
|
153
|
+
if (call == null) return false;
|
|
154
|
+
const prop = AST8__namespace.findParentNode(node, AST8__namespace.is(types.AST_NODE_TYPES.ObjectExpression));
|
|
155
|
+
if (prop == null) return false;
|
|
171
156
|
return prop === call.arguments[1];
|
|
172
157
|
}
|
|
173
158
|
function isChildrenOfCreateElement(node, context) {
|
|
174
159
|
const parent = node.parent;
|
|
175
|
-
if (
|
|
160
|
+
if (parent == null || parent.type !== types.AST_NODE_TYPES.CallExpression) return false;
|
|
176
161
|
if (!isCreateElementCall(parent, context)) return false;
|
|
177
162
|
return parent.arguments.slice(2).some((arg) => arg === node);
|
|
178
163
|
}
|
|
@@ -185,12 +170,12 @@ function isReactHookName(name) {
|
|
|
185
170
|
|
|
186
171
|
// src/hook/is.ts
|
|
187
172
|
function isReactHook(node) {
|
|
188
|
-
if (node
|
|
173
|
+
if (node == null) return eff._;
|
|
189
174
|
const id2 = AST8__namespace.getFunctionIdentifier(node);
|
|
190
|
-
return id2?.name
|
|
175
|
+
return id2?.name != null && isReactHookName(id2.name);
|
|
191
176
|
}
|
|
192
177
|
function isReactHookCall(node) {
|
|
193
|
-
if (node
|
|
178
|
+
if (node == null) return false;
|
|
194
179
|
if (node.type !== types.AST_NODE_TYPES.CallExpression) {
|
|
195
180
|
return false;
|
|
196
181
|
}
|
|
@@ -203,7 +188,7 @@ function isReactHookCall(node) {
|
|
|
203
188
|
return false;
|
|
204
189
|
}
|
|
205
190
|
function isReactHookCallWithName(node, context) {
|
|
206
|
-
if (node
|
|
191
|
+
if (node == null) return eff.returnFalse;
|
|
207
192
|
const settings = shared.unsafeDecodeSettings(context.settings);
|
|
208
193
|
return (name) => {
|
|
209
194
|
const initialScope = context.sourceCode.getScope(node);
|
|
@@ -218,7 +203,7 @@ function isReactHookCallWithName(node, context) {
|
|
|
218
203
|
};
|
|
219
204
|
}
|
|
220
205
|
function isReactHookCallWithNameLoose(node) {
|
|
221
|
-
if (node
|
|
206
|
+
if (node == null) return eff.returnFalse;
|
|
222
207
|
return (name) => {
|
|
223
208
|
switch (node.callee.type) {
|
|
224
209
|
case types.AST_NODE_TYPES.Identifier:
|
|
@@ -245,7 +230,7 @@ function isReactHookCallWithNameAlias(name, context, alias) {
|
|
|
245
230
|
};
|
|
246
231
|
}
|
|
247
232
|
function isUseEffectCallLoose(node) {
|
|
248
|
-
if (node
|
|
233
|
+
if (node == null) return false;
|
|
249
234
|
if (node.type !== types.AST_NODE_TYPES.CallExpression) {
|
|
250
235
|
return false;
|
|
251
236
|
}
|
|
@@ -276,7 +261,7 @@ var isUseTransitionCall = eff.flip(isReactHookCallWithName)("useTransition");
|
|
|
276
261
|
|
|
277
262
|
// src/hook/hierarchy.ts
|
|
278
263
|
function isInsideReactHook(node) {
|
|
279
|
-
return isReactHook(AST8__namespace.
|
|
264
|
+
return isReactHook(AST8__namespace.findParentNode(node, AST8__namespace.isFunction));
|
|
280
265
|
}
|
|
281
266
|
function useHookCollector() {
|
|
282
267
|
const hooks = /* @__PURE__ */ new Map();
|
|
@@ -284,12 +269,12 @@ function useHookCollector() {
|
|
|
284
269
|
const onFunctionEnter = (node) => {
|
|
285
270
|
const id2 = AST8__namespace.getFunctionIdentifier(node);
|
|
286
271
|
const name = id2?.name;
|
|
287
|
-
if (name
|
|
272
|
+
if (name != null && isReactHookName(name)) {
|
|
288
273
|
const key = getId();
|
|
289
274
|
fEntries.push({ key, node });
|
|
290
275
|
hooks.set(key, {
|
|
291
|
-
_: key,
|
|
292
276
|
id: id2,
|
|
277
|
+
key,
|
|
293
278
|
kind: "function",
|
|
294
279
|
name,
|
|
295
280
|
node,
|
|
@@ -321,26 +306,20 @@ function useHookCollector() {
|
|
|
321
306
|
return;
|
|
322
307
|
}
|
|
323
308
|
const fEntry = fEntries.at(-1);
|
|
324
|
-
if (fEntry?.key
|
|
309
|
+
if (fEntry?.key == null) {
|
|
325
310
|
return;
|
|
326
311
|
}
|
|
327
312
|
const hook = hooks.get(fEntry.key);
|
|
328
|
-
if (hook
|
|
313
|
+
if (hook == null) {
|
|
329
314
|
return;
|
|
330
315
|
}
|
|
331
|
-
|
|
332
|
-
...hook,
|
|
333
|
-
hookCalls: [
|
|
334
|
-
...hook.hookCalls,
|
|
335
|
-
node
|
|
336
|
-
]
|
|
337
|
-
});
|
|
316
|
+
hook.hookCalls.push(node);
|
|
338
317
|
}
|
|
339
318
|
};
|
|
340
319
|
return { ctx, listeners };
|
|
341
320
|
}
|
|
342
321
|
var ERComponentHint = {
|
|
343
|
-
...
|
|
322
|
+
...JSX3__namespace.JSXValueHint,
|
|
344
323
|
// 1n << 0n - 1n << 63n are reserved for JSXValueHint
|
|
345
324
|
// Skip function component created by React.memo
|
|
346
325
|
SkipMemo: 1n << 64n,
|
|
@@ -383,7 +362,7 @@ function isComponentWrapperCall(node, context) {
|
|
|
383
362
|
}
|
|
384
363
|
function getFunctionComponentIdentifier(node, context) {
|
|
385
364
|
const functionId = AST8__namespace.getFunctionIdentifier(node);
|
|
386
|
-
if (functionId) {
|
|
365
|
+
if (functionId != null) {
|
|
387
366
|
return functionId;
|
|
388
367
|
}
|
|
389
368
|
const { parent } = node;
|
|
@@ -395,17 +374,8 @@ function getFunctionComponentIdentifier(node, context) {
|
|
|
395
374
|
}
|
|
396
375
|
return eff._;
|
|
397
376
|
}
|
|
398
|
-
|
|
399
|
-
// src/component/component-name.ts
|
|
400
|
-
var RE_COMPONENT_NAME = /^_?[A-Z]/u;
|
|
401
|
-
function getComponentNameFromIdentifier(node) {
|
|
402
|
-
return Array.isArray(node) ? node.map((n) => n.name).join(".") : node.name;
|
|
403
|
-
}
|
|
404
|
-
function isComponentName(name) {
|
|
405
|
-
return RE_COMPONENT_NAME.test(name);
|
|
406
|
-
}
|
|
407
377
|
function isClassComponent(node) {
|
|
408
|
-
if ("superClass" in node && node.superClass) {
|
|
378
|
+
if ("superClass" in node && node.superClass != null) {
|
|
409
379
|
const re = /^(?:Pure)?Component$/u;
|
|
410
380
|
switch (true) {
|
|
411
381
|
case node.superClass.type === types.AST_NODE_TYPES.Identifier:
|
|
@@ -417,7 +387,7 @@ function isClassComponent(node) {
|
|
|
417
387
|
return false;
|
|
418
388
|
}
|
|
419
389
|
function isPureComponent(node) {
|
|
420
|
-
if ("superClass" in node && node.superClass) {
|
|
390
|
+
if ("superClass" in node && node.superClass != null) {
|
|
421
391
|
const re = /^PureComponent$/u;
|
|
422
392
|
switch (true) {
|
|
423
393
|
case node.superClass.type === types.AST_NODE_TYPES.Identifier:
|
|
@@ -429,9 +399,30 @@ function isPureComponent(node) {
|
|
|
429
399
|
return false;
|
|
430
400
|
}
|
|
431
401
|
|
|
432
|
-
// src/component/component-
|
|
402
|
+
// src/component/component-lifecycle.ts
|
|
403
|
+
function isComponentDidMount(node) {
|
|
404
|
+
return AST8__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentDidMount";
|
|
405
|
+
}
|
|
406
|
+
function isComponentWillUnmount(node) {
|
|
407
|
+
return AST8__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentWillUnmount";
|
|
408
|
+
}
|
|
409
|
+
function isComponentDidCatch(node) {
|
|
410
|
+
return AST8__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentDidCatch";
|
|
411
|
+
}
|
|
412
|
+
function isGetDerivedStateFromError(node) {
|
|
413
|
+
return AST8__namespace.isMethodOrProperty(node) && node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromError";
|
|
414
|
+
}
|
|
415
|
+
function isGetDerivedStateFromProps(node) {
|
|
416
|
+
return AST8__namespace.isMethodOrProperty(node) && node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromProps";
|
|
417
|
+
}
|
|
418
|
+
function isFunctionOfComponentDidMount(node) {
|
|
419
|
+
return AST8__namespace.isFunction(node) && isComponentDidMount(node.parent) && node.parent.value === node;
|
|
420
|
+
}
|
|
421
|
+
function isFunctionOfComponentWillUnmount(node) {
|
|
422
|
+
return AST8__namespace.isFunction(node) && isComponentWillUnmount(node.parent) && node.parent.value === node;
|
|
423
|
+
}
|
|
433
424
|
function isRenderMethodLike(node) {
|
|
434
|
-
return (node
|
|
425
|
+
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;
|
|
435
426
|
}
|
|
436
427
|
function isFunctionOfRenderMethod(node) {
|
|
437
428
|
if (!isRenderMethodLike(node.parent)) {
|
|
@@ -440,13 +431,19 @@ function isFunctionOfRenderMethod(node) {
|
|
|
440
431
|
return isClassComponent(node.parent.parent.parent);
|
|
441
432
|
}
|
|
442
433
|
function isInsideRenderMethod(node) {
|
|
443
|
-
return
|
|
434
|
+
return AST8__namespace.findParentNode(node, (node2) => isRenderMethodLike(node2) && isClassComponent(node2.parent.parent)) != null;
|
|
435
|
+
}
|
|
436
|
+
var RE_COMPONENT_NAME = /^_?[A-Z]/u;
|
|
437
|
+
function getComponentNameFromIdentifier(node) {
|
|
438
|
+
if (node == null) return eff._;
|
|
439
|
+
return Array.isArray(node) ? node.map((n) => n.name).join(".") : node.name;
|
|
440
|
+
}
|
|
441
|
+
function isComponentName(name) {
|
|
442
|
+
return RE_COMPONENT_NAME.test(name);
|
|
444
443
|
}
|
|
445
|
-
|
|
446
|
-
// src/component/misc.ts
|
|
447
444
|
function hasNoneOrValidComponentName(node, context) {
|
|
448
445
|
const id2 = getFunctionComponentIdentifier(node, context);
|
|
449
|
-
if (
|
|
446
|
+
if (id2 == null) return true;
|
|
450
447
|
const name = Array.isArray(id2) ? id2.at(-1)?.name : id2.name;
|
|
451
448
|
return name != null && isComponentName(name);
|
|
452
449
|
}
|
|
@@ -478,19 +475,21 @@ function hasValidHierarchy(node, context, hint) {
|
|
|
478
475
|
types.AST_NODE_TYPES.ClassBody
|
|
479
476
|
])
|
|
480
477
|
);
|
|
481
|
-
return
|
|
478
|
+
return boundaryNode == null || boundaryNode.type !== types.AST_NODE_TYPES.JSXExpressionContainer;
|
|
482
479
|
}
|
|
483
480
|
function getComponentFlag(initPath) {
|
|
484
481
|
let flag = ERFunctionComponentFlag.None;
|
|
485
|
-
if (initPath && AST8__namespace.hasCallInFunctionInitPath("memo"
|
|
482
|
+
if (initPath != null && AST8__namespace.hasCallInFunctionInitPath("memo", initPath)) {
|
|
486
483
|
flag |= ERFunctionComponentFlag.Memo;
|
|
487
484
|
}
|
|
488
|
-
if (initPath && AST8__namespace.hasCallInFunctionInitPath("forwardRef"
|
|
485
|
+
if (initPath != null && AST8__namespace.hasCallInFunctionInitPath("forwardRef", initPath)) {
|
|
489
486
|
flag |= ERFunctionComponentFlag.ForwardRef;
|
|
490
487
|
}
|
|
491
488
|
return flag;
|
|
492
489
|
}
|
|
493
|
-
|
|
490
|
+
var displayNameAssignmentSelector = "AssignmentExpression[type][operator='='][left.type='MemberExpression'][left.property.name='displayName']";
|
|
491
|
+
function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT, options = {}) {
|
|
492
|
+
const { collectDisplayName = false, collectHookCalls = false } = options;
|
|
494
493
|
const jsxCtx = { getScope: (node) => context.sourceCode.getScope(node) };
|
|
495
494
|
const components = /* @__PURE__ */ new Map();
|
|
496
495
|
const functionEntries = [];
|
|
@@ -501,12 +500,12 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT) {
|
|
|
501
500
|
};
|
|
502
501
|
const onFunctionExit = () => {
|
|
503
502
|
const entry = functionEntries.at(-1);
|
|
504
|
-
if (
|
|
503
|
+
if (entry == null) return;
|
|
505
504
|
if (!entry.isComponent) {
|
|
506
505
|
return functionEntries.pop();
|
|
507
506
|
}
|
|
508
507
|
const shouldDrop = AST8__namespace.getNestedReturnStatements(entry.node.body).slice().reverse().some((r) => {
|
|
509
|
-
return context.sourceCode.getScope(r).block === entry.node &&
|
|
508
|
+
return context.sourceCode.getScope(r).block === entry.node && r.argument != null && !JSX3__namespace.isJSXValue(r.argument, jsxCtx, hint);
|
|
510
509
|
});
|
|
511
510
|
if (shouldDrop) {
|
|
512
511
|
components.delete(entry.key);
|
|
@@ -528,21 +527,21 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT) {
|
|
|
528
527
|
":function[type]:exit": onFunctionExit,
|
|
529
528
|
"ArrowFunctionExpression[type][body.type!='BlockStatement']"() {
|
|
530
529
|
const entry = getCurrentEntry();
|
|
531
|
-
if (
|
|
530
|
+
if (entry == null) {
|
|
532
531
|
return;
|
|
533
532
|
}
|
|
534
533
|
const { body } = entry.node;
|
|
535
|
-
const isComponent = hasNoneOrValidComponentName(entry.node, context) &&
|
|
534
|
+
const isComponent = hasNoneOrValidComponentName(entry.node, context) && JSX3__namespace.isJSXValue(body, jsxCtx, hint) && hasValidHierarchy(entry.node, context, hint);
|
|
536
535
|
if (!isComponent) {
|
|
537
536
|
return;
|
|
538
537
|
}
|
|
539
538
|
const initPath = AST8__namespace.getFunctionInitPath(entry.node);
|
|
540
539
|
const id2 = getFunctionComponentIdentifier(entry.node, context);
|
|
541
|
-
const name =
|
|
540
|
+
const name = getComponentNameFromIdentifier(id2);
|
|
542
541
|
const key = getId();
|
|
543
542
|
components.set(key, {
|
|
544
|
-
_: key,
|
|
545
543
|
id: id2,
|
|
544
|
+
key,
|
|
546
545
|
kind: "function",
|
|
547
546
|
name,
|
|
548
547
|
node: entry.node,
|
|
@@ -553,35 +552,35 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT) {
|
|
|
553
552
|
initPath
|
|
554
553
|
});
|
|
555
554
|
},
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
displayName: right
|
|
566
|
-
});
|
|
567
|
-
},
|
|
568
|
-
"CallExpression[type]:exit"(node) {
|
|
569
|
-
if (!isReactHookCall(node)) {
|
|
570
|
-
return;
|
|
555
|
+
...collectDisplayName ? {
|
|
556
|
+
[displayNameAssignmentSelector](node) {
|
|
557
|
+
const { left, right } = node;
|
|
558
|
+
const componentName = left.object.type === types.AST_NODE_TYPES.Identifier ? left.object.name : eff._;
|
|
559
|
+
const component = [...components.values()].findLast(({ name }) => name != null && name === componentName);
|
|
560
|
+
if (component == null) {
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
component.displayName = right;
|
|
571
564
|
}
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
565
|
+
} : {},
|
|
566
|
+
...collectHookCalls ? {
|
|
567
|
+
"CallExpression[type]:exit"(node) {
|
|
568
|
+
if (!isReactHookCall(node)) {
|
|
569
|
+
return;
|
|
570
|
+
}
|
|
571
|
+
const entry = getCurrentEntry();
|
|
572
|
+
if (entry == null) {
|
|
573
|
+
return;
|
|
574
|
+
}
|
|
575
|
+
entry.hookCalls.push(node);
|
|
575
576
|
}
|
|
576
|
-
|
|
577
|
-
functionEntries.push({ ...entry, hookCalls: [...entry.hookCalls, node] });
|
|
578
|
-
},
|
|
577
|
+
} : {},
|
|
579
578
|
"ReturnStatement[type]"(node) {
|
|
580
579
|
const entry = getCurrentEntry();
|
|
581
|
-
if (
|
|
580
|
+
if (entry == null) {
|
|
582
581
|
return;
|
|
583
582
|
}
|
|
584
|
-
const isComponent = hasNoneOrValidComponentName(entry.node, context) &&
|
|
583
|
+
const isComponent = hasNoneOrValidComponentName(entry.node, context) && JSX3__namespace.isJSXValue(node.argument, jsxCtx, hint) && hasValidHierarchy(entry.node, context, hint);
|
|
585
584
|
if (!isComponent) {
|
|
586
585
|
return;
|
|
587
586
|
}
|
|
@@ -589,10 +588,10 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT) {
|
|
|
589
588
|
functionEntries.push({ ...entry, isComponent });
|
|
590
589
|
const initPath = AST8__namespace.getFunctionInitPath(entry.node);
|
|
591
590
|
const id2 = getFunctionComponentIdentifier(entry.node, context);
|
|
592
|
-
const name =
|
|
591
|
+
const name = getComponentNameFromIdentifier(id2);
|
|
593
592
|
components.set(entry.key, {
|
|
594
|
-
_: entry.key,
|
|
595
593
|
id: id2,
|
|
594
|
+
key: entry.key,
|
|
596
595
|
kind: "function",
|
|
597
596
|
name,
|
|
598
597
|
node: entry.node,
|
|
@@ -624,8 +623,8 @@ function useComponentCollectorLegacy() {
|
|
|
624
623
|
components.set(
|
|
625
624
|
key,
|
|
626
625
|
{
|
|
627
|
-
_: key,
|
|
628
626
|
id: id2,
|
|
627
|
+
key,
|
|
629
628
|
kind: "class",
|
|
630
629
|
name: id2?.name,
|
|
631
630
|
node,
|
|
@@ -644,60 +643,22 @@ function useComponentCollectorLegacy() {
|
|
|
644
643
|
};
|
|
645
644
|
return { ctx, listeners };
|
|
646
645
|
}
|
|
647
|
-
|
|
648
|
-
if (node === eff._) return eff._;
|
|
649
|
-
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);
|
|
650
|
-
}
|
|
651
|
-
function isCleanupFunction(node) {
|
|
652
|
-
const nearReturn = AST8__namespace.findParentNodeGuard(node, AST8__namespace.is(types.AST_NODE_TYPES.ReturnStatement));
|
|
653
|
-
const nearFunction = AST8__namespace.findParentNodeGuard(node, AST8__namespace.isFunction);
|
|
654
|
-
const nearFunctionOfReturn = AST8__namespace.findParentNodeGuard(nearReturn, AST8__namespace.isFunction);
|
|
655
|
-
return nearFunction === nearFunctionOfReturn && isSetupFunction(nearFunction);
|
|
656
|
-
}
|
|
657
|
-
function isComponentDidMount(node) {
|
|
658
|
-
return AST8__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";
|
|
659
|
-
}
|
|
660
|
-
function isComponentWillUnmount(node) {
|
|
661
|
-
return AST8__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";
|
|
662
|
-
}
|
|
663
|
-
function isComponentDidMountFunction(node) {
|
|
664
|
-
return AST8__namespace.isFunction(node) && isComponentDidMount(node.parent) && node.parent.value === node;
|
|
665
|
-
}
|
|
666
|
-
function isComponentWillUnmountFunction(node) {
|
|
667
|
-
return AST8__namespace.isFunction(node) && isComponentWillUnmount(node.parent) && node.parent.value === node;
|
|
668
|
-
}
|
|
669
|
-
var ERPhaseRelevance = eff.birecord({
|
|
646
|
+
var ERPhaseRelevance = birecord__default.default({
|
|
670
647
|
mount: "unmount",
|
|
671
648
|
setup: "cleanup"
|
|
672
649
|
});
|
|
673
650
|
var isInversePhase = eff.dual(2, (a, b) => ERPhaseRelevance.get(a) === b);
|
|
674
|
-
function isDirectValueOfRenderPropertyLoose(node) {
|
|
675
|
-
const matching = (node2) => {
|
|
676
|
-
return node2.type === types.AST_NODE_TYPES.Property && node2.key.type === types.AST_NODE_TYPES.Identifier && node2.key.name.startsWith("render");
|
|
677
|
-
};
|
|
678
|
-
return matching(node) || !!node.parent && matching(node.parent);
|
|
679
|
-
}
|
|
680
|
-
function isDeclaredInRenderPropLoose(node) {
|
|
681
|
-
if (isDirectValueOfRenderPropertyLoose(node)) {
|
|
682
|
-
return true;
|
|
683
|
-
}
|
|
684
|
-
const parent = AST8__namespace.findParentNodeGuard(node, AST8__namespace.is(types.AST_NODE_TYPES.JSXExpressionContainer))?.parent;
|
|
685
|
-
if (parent?.type !== types.AST_NODE_TYPES.JSXAttribute) {
|
|
686
|
-
return false;
|
|
687
|
-
}
|
|
688
|
-
return parent.name.type === types.AST_NODE_TYPES.JSXIdentifier && parent.name.name.startsWith("render");
|
|
689
|
-
}
|
|
690
651
|
function isRenderFunctionLoose(node, context) {
|
|
691
652
|
const { body, parent } = node;
|
|
692
653
|
if (AST8__namespace.getFunctionIdentifier(node)?.name.startsWith("render")) {
|
|
693
654
|
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");
|
|
694
655
|
}
|
|
695
|
-
return
|
|
656
|
+
return JSX3__namespace.isJSXValue(
|
|
696
657
|
body,
|
|
697
658
|
{
|
|
698
659
|
getScope: (node2) => context.sourceCode.getScope(node2)
|
|
699
660
|
},
|
|
700
|
-
|
|
661
|
+
JSX3__namespace.JSXValueHint.SkipNullLiteral | JSX3__namespace.JSXValueHint.SkipUndefined | JSX3__namespace.JSXValueHint.StrictLogical | JSX3__namespace.JSXValueHint.StrictConditional
|
|
701
662
|
);
|
|
702
663
|
}
|
|
703
664
|
function isRenderPropLoose(node, context) {
|
|
@@ -706,10 +667,36 @@ function isRenderPropLoose(node, context) {
|
|
|
706
667
|
}
|
|
707
668
|
return node.name.name.startsWith("render") && node.value?.type === types.AST_NODE_TYPES.JSXExpressionContainer && AST8__namespace.isFunction(node.value.expression) && isRenderFunctionLoose(node.value.expression, context);
|
|
708
669
|
}
|
|
670
|
+
function isDirectValueOfRenderPropertyLoose(node) {
|
|
671
|
+
const matching = (node2) => {
|
|
672
|
+
return node2.type === types.AST_NODE_TYPES.Property && node2.key.type === types.AST_NODE_TYPES.Identifier && node2.key.name.startsWith("render");
|
|
673
|
+
};
|
|
674
|
+
return matching(node) || node.parent != null && matching(node.parent);
|
|
675
|
+
}
|
|
676
|
+
function isDeclaredInRenderPropLoose(node) {
|
|
677
|
+
if (isDirectValueOfRenderPropertyLoose(node)) {
|
|
678
|
+
return true;
|
|
679
|
+
}
|
|
680
|
+
const parent = AST8__namespace.findParentNode(node, AST8__namespace.is(types.AST_NODE_TYPES.JSXExpressionContainer))?.parent;
|
|
681
|
+
if (parent?.type !== types.AST_NODE_TYPES.JSXAttribute) {
|
|
682
|
+
return false;
|
|
683
|
+
}
|
|
684
|
+
return parent.name.type === types.AST_NODE_TYPES.JSXIdentifier && parent.name.name.startsWith("render");
|
|
685
|
+
}
|
|
709
686
|
function isThisSetState(node) {
|
|
710
687
|
const { callee } = node;
|
|
711
688
|
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";
|
|
712
689
|
}
|
|
690
|
+
function isFunctionOfUseEffectSetup(node) {
|
|
691
|
+
if (node == null) return eff._;
|
|
692
|
+
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);
|
|
693
|
+
}
|
|
694
|
+
function isFunctionOfUseEffectCleanup(node) {
|
|
695
|
+
const nearReturn = AST8__namespace.findParentNode(node, AST8__namespace.is(types.AST_NODE_TYPES.ReturnStatement));
|
|
696
|
+
const nearFunction = AST8__namespace.findParentNode(node, AST8__namespace.isFunction);
|
|
697
|
+
const nearFunctionOfReturn = AST8__namespace.findParentNode(nearReturn, AST8__namespace.isFunction);
|
|
698
|
+
return nearFunction === nearFunctionOfReturn && isFunctionOfUseEffectSetup(nearFunction);
|
|
699
|
+
}
|
|
713
700
|
|
|
714
701
|
exports.DEFAULT_COMPONENT_HINT = DEFAULT_COMPONENT_HINT;
|
|
715
702
|
exports.ERClassComponentFlag = ERClassComponentFlag;
|
|
@@ -719,7 +706,6 @@ exports.ERPhaseRelevance = ERPhaseRelevance;
|
|
|
719
706
|
exports.RE_COMPONENT_NAME = RE_COMPONENT_NAME;
|
|
720
707
|
exports.RE_HOOK_NAME = RE_HOOK_NAME;
|
|
721
708
|
exports.getComponentNameFromIdentifier = getComponentNameFromIdentifier;
|
|
722
|
-
exports.getElementNameAndRepresentName = getElementNameAndRepresentName;
|
|
723
709
|
exports.getFunctionComponentIdentifier = getFunctionComponentIdentifier;
|
|
724
710
|
exports.getId = getId;
|
|
725
711
|
exports.hasNoneOrValidComponentName = hasNoneOrValidComponentName;
|
|
@@ -737,14 +723,12 @@ exports.isChildrenOnlyCall = isChildrenOnlyCall;
|
|
|
737
723
|
exports.isChildrenToArray = isChildrenToArray;
|
|
738
724
|
exports.isChildrenToArrayCall = isChildrenToArrayCall;
|
|
739
725
|
exports.isClassComponent = isClassComponent;
|
|
740
|
-
exports.isCleanupFunction = isCleanupFunction;
|
|
741
726
|
exports.isCloneElement = isCloneElement;
|
|
742
727
|
exports.isCloneElementCall = isCloneElementCall;
|
|
728
|
+
exports.isComponentDidCatch = isComponentDidCatch;
|
|
743
729
|
exports.isComponentDidMount = isComponentDidMount;
|
|
744
|
-
exports.isComponentDidMountFunction = isComponentDidMountFunction;
|
|
745
730
|
exports.isComponentName = isComponentName;
|
|
746
731
|
exports.isComponentWillUnmount = isComponentWillUnmount;
|
|
747
|
-
exports.isComponentWillUnmountFunction = isComponentWillUnmountFunction;
|
|
748
732
|
exports.isCreateContext = isCreateContext;
|
|
749
733
|
exports.isCreateContextCall = isCreateContextCall;
|
|
750
734
|
exports.isCreateElement = isCreateElement;
|
|
@@ -757,7 +741,13 @@ exports.isForwardRef = isForwardRef;
|
|
|
757
741
|
exports.isForwardRefCall = isForwardRefCall;
|
|
758
742
|
exports.isFromReact = isFromReact;
|
|
759
743
|
exports.isFromReactMember = isFromReactMember;
|
|
744
|
+
exports.isFunctionOfComponentDidMount = isFunctionOfComponentDidMount;
|
|
745
|
+
exports.isFunctionOfComponentWillUnmount = isFunctionOfComponentWillUnmount;
|
|
760
746
|
exports.isFunctionOfRenderMethod = isFunctionOfRenderMethod;
|
|
747
|
+
exports.isFunctionOfUseEffectCleanup = isFunctionOfUseEffectCleanup;
|
|
748
|
+
exports.isFunctionOfUseEffectSetup = isFunctionOfUseEffectSetup;
|
|
749
|
+
exports.isGetDerivedStateFromError = isGetDerivedStateFromError;
|
|
750
|
+
exports.isGetDerivedStateFromProps = isGetDerivedStateFromProps;
|
|
761
751
|
exports.isInitializedFromReact = isInitializedFromReact;
|
|
762
752
|
exports.isInsideCreateElementProps = isInsideCreateElementProps;
|
|
763
753
|
exports.isInsideReactHook = isInsideReactHook;
|
|
@@ -777,7 +767,6 @@ exports.isReactHookName = isReactHookName;
|
|
|
777
767
|
exports.isRenderFunctionLoose = isRenderFunctionLoose;
|
|
778
768
|
exports.isRenderMethodLike = isRenderMethodLike;
|
|
779
769
|
exports.isRenderPropLoose = isRenderPropLoose;
|
|
780
|
-
exports.isSetupFunction = isSetupFunction;
|
|
781
770
|
exports.isThisSetState = isThisSetState;
|
|
782
771
|
exports.isUseCallbackCall = isUseCallbackCall;
|
|
783
772
|
exports.isUseContextCall = isUseContextCall;
|