@eslint-react/core 1.24.0-next.0 → 1.24.0-next.1
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 +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +33 -34
- package/dist/index.mjs +33 -34
- package/package.json +7 -7
package/dist/index.d.mts
CHANGED
|
@@ -130,7 +130,7 @@ type EREffectMethodKind = "useEffect" | "useInsertionEffect" | "useLayoutEffect"
|
|
|
130
130
|
type ERLifecycleMethodKind = "componentDidMount" | "componentWillUnmount";
|
|
131
131
|
|
|
132
132
|
declare const RE_COMPONENT_NAME: RegExp;
|
|
133
|
-
declare function getComponentNameFromIdentifier(node: TSESTree.Identifier | TSESTree.Identifier[]): string;
|
|
133
|
+
declare function getComponentNameFromIdentifier(node: TSESTree.Identifier | TSESTree.Identifier[] | _): string | undefined;
|
|
134
134
|
declare function isComponentName(name: string): boolean;
|
|
135
135
|
|
|
136
136
|
declare function isRenderMethodLike(node: TSESTree$1.Node): node is TSESTree$1.MethodDefinition | TSESTree$1.PropertyDefinition;
|
package/dist/index.d.ts
CHANGED
|
@@ -130,7 +130,7 @@ type EREffectMethodKind = "useEffect" | "useInsertionEffect" | "useLayoutEffect"
|
|
|
130
130
|
type ERLifecycleMethodKind = "componentDidMount" | "componentWillUnmount";
|
|
131
131
|
|
|
132
132
|
declare const RE_COMPONENT_NAME: RegExp;
|
|
133
|
-
declare function getComponentNameFromIdentifier(node: TSESTree.Identifier | TSESTree.Identifier[]): string;
|
|
133
|
+
declare function getComponentNameFromIdentifier(node: TSESTree.Identifier | TSESTree.Identifier[] | _): string | undefined;
|
|
134
134
|
declare function isComponentName(name: string): boolean;
|
|
135
135
|
|
|
136
136
|
declare function isRenderMethodLike(node: TSESTree$1.Node): node is TSESTree$1.MethodDefinition | TSESTree$1.PropertyDefinition;
|
package/dist/index.js
CHANGED
|
@@ -34,7 +34,7 @@ function getElementNameAndRepresentName(node, context, polymorphicPropName, addi
|
|
|
34
34
|
const name = JSX4__namespace.getElementName(node);
|
|
35
35
|
if (name === name.toLowerCase()) return [name, name];
|
|
36
36
|
const component = additionalComponents.findLast((c) => c.name === name || c.re.test(name));
|
|
37
|
-
if (component
|
|
37
|
+
if (component != null) return [name, component.as];
|
|
38
38
|
if (polymorphicPropName == null) return [name, name];
|
|
39
39
|
const initialScope = context.sourceCode.getScope(node);
|
|
40
40
|
const polymorphicProp = JSX4__namespace.findPropInAttributes(
|
|
@@ -42,7 +42,7 @@ function getElementNameAndRepresentName(node, context, polymorphicPropName, addi
|
|
|
42
42
|
initialScope,
|
|
43
43
|
node.attributes
|
|
44
44
|
);
|
|
45
|
-
if (polymorphicProp
|
|
45
|
+
if (polymorphicProp == null) return [name, name];
|
|
46
46
|
const polymorphicName = VAR__namespace.toResolved(JSX4__namespace.getPropValue(polymorphicProp, initialScope)).value;
|
|
47
47
|
if (typeof polymorphicName === "string") {
|
|
48
48
|
return [name, polymorphicName];
|
|
@@ -165,14 +165,14 @@ var isMemoCall = isReactAPICallWithName("memo");
|
|
|
165
165
|
// src/element/hierarchy.ts
|
|
166
166
|
function isInsideCreateElementProps(node, context) {
|
|
167
167
|
const call = AST8__namespace.findParentNodeGuard(node, isCreateElementCall(context));
|
|
168
|
-
if (
|
|
168
|
+
if (call == null) return false;
|
|
169
169
|
const prop = AST8__namespace.findParentNodeGuard(node, AST8__namespace.is(types.AST_NODE_TYPES.ObjectExpression));
|
|
170
|
-
if (
|
|
170
|
+
if (prop == null) return false;
|
|
171
171
|
return prop === call.arguments[1];
|
|
172
172
|
}
|
|
173
173
|
function isChildrenOfCreateElement(node, context) {
|
|
174
174
|
const parent = node.parent;
|
|
175
|
-
if (
|
|
175
|
+
if (parent == null || parent.type !== types.AST_NODE_TYPES.CallExpression) return false;
|
|
176
176
|
if (!isCreateElementCall(parent, context)) return false;
|
|
177
177
|
return parent.arguments.slice(2).some((arg) => arg === node);
|
|
178
178
|
}
|
|
@@ -185,12 +185,12 @@ function isReactHookName(name) {
|
|
|
185
185
|
|
|
186
186
|
// src/hook/is.ts
|
|
187
187
|
function isReactHook(node) {
|
|
188
|
-
if (node
|
|
188
|
+
if (node == null) return eff._;
|
|
189
189
|
const id2 = AST8__namespace.getFunctionIdentifier(node);
|
|
190
|
-
return id2?.name
|
|
190
|
+
return id2?.name != null && isReactHookName(id2.name);
|
|
191
191
|
}
|
|
192
192
|
function isReactHookCall(node) {
|
|
193
|
-
if (node
|
|
193
|
+
if (node == null) return false;
|
|
194
194
|
if (node.type !== types.AST_NODE_TYPES.CallExpression) {
|
|
195
195
|
return false;
|
|
196
196
|
}
|
|
@@ -203,7 +203,7 @@ function isReactHookCall(node) {
|
|
|
203
203
|
return false;
|
|
204
204
|
}
|
|
205
205
|
function isReactHookCallWithName(node, context) {
|
|
206
|
-
if (node
|
|
206
|
+
if (node == null) return eff.returnFalse;
|
|
207
207
|
const settings = shared.unsafeDecodeSettings(context.settings);
|
|
208
208
|
return (name) => {
|
|
209
209
|
const initialScope = context.sourceCode.getScope(node);
|
|
@@ -218,7 +218,7 @@ function isReactHookCallWithName(node, context) {
|
|
|
218
218
|
};
|
|
219
219
|
}
|
|
220
220
|
function isReactHookCallWithNameLoose(node) {
|
|
221
|
-
if (node
|
|
221
|
+
if (node == null) return eff.returnFalse;
|
|
222
222
|
return (name) => {
|
|
223
223
|
switch (node.callee.type) {
|
|
224
224
|
case types.AST_NODE_TYPES.Identifier:
|
|
@@ -245,7 +245,7 @@ function isReactHookCallWithNameAlias(name, context, alias) {
|
|
|
245
245
|
};
|
|
246
246
|
}
|
|
247
247
|
function isUseEffectCallLoose(node) {
|
|
248
|
-
if (node
|
|
248
|
+
if (node == null) return false;
|
|
249
249
|
if (node.type !== types.AST_NODE_TYPES.CallExpression) {
|
|
250
250
|
return false;
|
|
251
251
|
}
|
|
@@ -284,7 +284,7 @@ function useHookCollector() {
|
|
|
284
284
|
const onFunctionEnter = (node) => {
|
|
285
285
|
const id2 = AST8__namespace.getFunctionIdentifier(node);
|
|
286
286
|
const name = id2?.name;
|
|
287
|
-
if (name
|
|
287
|
+
if (name != null && isReactHookName(name)) {
|
|
288
288
|
const key = getId();
|
|
289
289
|
fEntries.push({ key, node });
|
|
290
290
|
hooks.set(key, {
|
|
@@ -321,11 +321,11 @@ function useHookCollector() {
|
|
|
321
321
|
return;
|
|
322
322
|
}
|
|
323
323
|
const fEntry = fEntries.at(-1);
|
|
324
|
-
if (fEntry?.key
|
|
324
|
+
if (fEntry?.key == null) {
|
|
325
325
|
return;
|
|
326
326
|
}
|
|
327
327
|
const hook = hooks.get(fEntry.key);
|
|
328
|
-
if (hook
|
|
328
|
+
if (hook == null) {
|
|
329
329
|
return;
|
|
330
330
|
}
|
|
331
331
|
hooks.set(hook._, {
|
|
@@ -383,7 +383,7 @@ function isComponentWrapperCall(node, context) {
|
|
|
383
383
|
}
|
|
384
384
|
function getFunctionComponentIdentifier(node, context) {
|
|
385
385
|
const functionId = AST8__namespace.getFunctionIdentifier(node);
|
|
386
|
-
if (functionId) {
|
|
386
|
+
if (functionId != null) {
|
|
387
387
|
return functionId;
|
|
388
388
|
}
|
|
389
389
|
const { parent } = node;
|
|
@@ -395,17 +395,16 @@ function getFunctionComponentIdentifier(node, context) {
|
|
|
395
395
|
}
|
|
396
396
|
return eff._;
|
|
397
397
|
}
|
|
398
|
-
|
|
399
|
-
// src/component/component-name.ts
|
|
400
398
|
var RE_COMPONENT_NAME = /^_?[A-Z]/u;
|
|
401
399
|
function getComponentNameFromIdentifier(node) {
|
|
400
|
+
if (node == null) return eff._;
|
|
402
401
|
return Array.isArray(node) ? node.map((n) => n.name).join(".") : node.name;
|
|
403
402
|
}
|
|
404
403
|
function isComponentName(name) {
|
|
405
404
|
return RE_COMPONENT_NAME.test(name);
|
|
406
405
|
}
|
|
407
406
|
function isClassComponent(node) {
|
|
408
|
-
if ("superClass" in node && node.superClass) {
|
|
407
|
+
if ("superClass" in node && node.superClass != null) {
|
|
409
408
|
const re = /^(?:Pure)?Component$/u;
|
|
410
409
|
switch (true) {
|
|
411
410
|
case node.superClass.type === types.AST_NODE_TYPES.Identifier:
|
|
@@ -417,7 +416,7 @@ function isClassComponent(node) {
|
|
|
417
416
|
return false;
|
|
418
417
|
}
|
|
419
418
|
function isPureComponent(node) {
|
|
420
|
-
if ("superClass" in node && node.superClass) {
|
|
419
|
+
if ("superClass" in node && node.superClass != null) {
|
|
421
420
|
const re = /^PureComponent$/u;
|
|
422
421
|
switch (true) {
|
|
423
422
|
case node.superClass.type === types.AST_NODE_TYPES.Identifier:
|
|
@@ -440,13 +439,13 @@ function isFunctionOfRenderMethod(node) {
|
|
|
440
439
|
return isClassComponent(node.parent.parent.parent);
|
|
441
440
|
}
|
|
442
441
|
function isInsideRenderMethod(node) {
|
|
443
|
-
return
|
|
442
|
+
return AST8__namespace.findParentNode(node, (node2) => isRenderMethodLike(node2) && isClassComponent(node2.parent.parent)) != null;
|
|
444
443
|
}
|
|
445
444
|
|
|
446
445
|
// src/component/misc.ts
|
|
447
446
|
function hasNoneOrValidComponentName(node, context) {
|
|
448
447
|
const id2 = getFunctionComponentIdentifier(node, context);
|
|
449
|
-
if (
|
|
448
|
+
if (id2 == null) return true;
|
|
450
449
|
const name = Array.isArray(id2) ? id2.at(-1)?.name : id2.name;
|
|
451
450
|
return name != null && isComponentName(name);
|
|
452
451
|
}
|
|
@@ -478,14 +477,14 @@ function hasValidHierarchy(node, context, hint) {
|
|
|
478
477
|
types.AST_NODE_TYPES.ClassBody
|
|
479
478
|
])
|
|
480
479
|
);
|
|
481
|
-
return
|
|
480
|
+
return boundaryNode == null || boundaryNode.type !== types.AST_NODE_TYPES.JSXExpressionContainer;
|
|
482
481
|
}
|
|
483
482
|
function getComponentFlag(initPath) {
|
|
484
483
|
let flag = ERFunctionComponentFlag.None;
|
|
485
|
-
if (initPath && AST8__namespace.hasCallInFunctionInitPath("memo")(initPath)) {
|
|
484
|
+
if (initPath != null && AST8__namespace.hasCallInFunctionInitPath("memo")(initPath)) {
|
|
486
485
|
flag |= ERFunctionComponentFlag.Memo;
|
|
487
486
|
}
|
|
488
|
-
if (initPath && AST8__namespace.hasCallInFunctionInitPath("forwardRef")(initPath)) {
|
|
487
|
+
if (initPath != null && AST8__namespace.hasCallInFunctionInitPath("forwardRef")(initPath)) {
|
|
489
488
|
flag |= ERFunctionComponentFlag.ForwardRef;
|
|
490
489
|
}
|
|
491
490
|
return flag;
|
|
@@ -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 && !JSX4__namespace.isJSXValue(r.argument, jsxCtx, hint);
|
|
510
509
|
});
|
|
511
510
|
if (shouldDrop) {
|
|
512
511
|
components.delete(entry.key);
|
|
@@ -528,7 +527,7 @@ 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;
|
|
@@ -538,7 +537,7 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT) {
|
|
|
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
543
|
_: key,
|
|
@@ -557,7 +556,7 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT) {
|
|
|
557
556
|
const { left, right } = node;
|
|
558
557
|
const componentName = left.object.type === types.AST_NODE_TYPES.Identifier ? left.object.name : eff._;
|
|
559
558
|
const component = [...components.values()].findLast(({ name }) => name != null && name === componentName);
|
|
560
|
-
if (
|
|
559
|
+
if (component == null) {
|
|
561
560
|
return;
|
|
562
561
|
}
|
|
563
562
|
components.set(component._, {
|
|
@@ -570,7 +569,7 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT) {
|
|
|
570
569
|
return;
|
|
571
570
|
}
|
|
572
571
|
const entry = getCurrentEntry();
|
|
573
|
-
if (
|
|
572
|
+
if (entry == null) {
|
|
574
573
|
return;
|
|
575
574
|
}
|
|
576
575
|
functionEntries.pop();
|
|
@@ -578,7 +577,7 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT) {
|
|
|
578
577
|
},
|
|
579
578
|
"ReturnStatement[type]"(node) {
|
|
580
579
|
const entry = getCurrentEntry();
|
|
581
|
-
if (
|
|
580
|
+
if (entry == null) {
|
|
582
581
|
return;
|
|
583
582
|
}
|
|
584
583
|
const isComponent = hasNoneOrValidComponentName(entry.node, context) && JSX4__namespace.isJSXValue(node.argument, jsxCtx, hint) && hasValidHierarchy(entry.node, context, hint);
|
|
@@ -589,7 +588,7 @@ 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
593
|
_: entry.key,
|
|
595
594
|
id: id2,
|
|
@@ -645,7 +644,7 @@ function useComponentCollectorLegacy() {
|
|
|
645
644
|
return { ctx, listeners };
|
|
646
645
|
}
|
|
647
646
|
function isSetupFunction(node) {
|
|
648
|
-
if (node
|
|
647
|
+
if (node == null) return eff._;
|
|
649
648
|
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
649
|
}
|
|
651
650
|
function isCleanupFunction(node) {
|
|
@@ -675,7 +674,7 @@ function isDirectValueOfRenderPropertyLoose(node) {
|
|
|
675
674
|
const matching = (node2) => {
|
|
676
675
|
return node2.type === types.AST_NODE_TYPES.Property && node2.key.type === types.AST_NODE_TYPES.Identifier && node2.key.name.startsWith("render");
|
|
677
676
|
};
|
|
678
|
-
return matching(node) ||
|
|
677
|
+
return matching(node) || node.parent != null && matching(node.parent);
|
|
679
678
|
}
|
|
680
679
|
function isDeclaredInRenderPropLoose(node) {
|
|
681
680
|
if (isDirectValueOfRenderPropertyLoose(node)) {
|
package/dist/index.mjs
CHANGED
|
@@ -10,7 +10,7 @@ function getElementNameAndRepresentName(node, context, polymorphicPropName, addi
|
|
|
10
10
|
const name = JSX4.getElementName(node);
|
|
11
11
|
if (name === name.toLowerCase()) return [name, name];
|
|
12
12
|
const component = additionalComponents.findLast((c) => c.name === name || c.re.test(name));
|
|
13
|
-
if (component
|
|
13
|
+
if (component != null) return [name, component.as];
|
|
14
14
|
if (polymorphicPropName == null) return [name, name];
|
|
15
15
|
const initialScope = context.sourceCode.getScope(node);
|
|
16
16
|
const polymorphicProp = JSX4.findPropInAttributes(
|
|
@@ -18,7 +18,7 @@ function getElementNameAndRepresentName(node, context, polymorphicPropName, addi
|
|
|
18
18
|
initialScope,
|
|
19
19
|
node.attributes
|
|
20
20
|
);
|
|
21
|
-
if (polymorphicProp
|
|
21
|
+
if (polymorphicProp == null) return [name, name];
|
|
22
22
|
const polymorphicName = VAR.toResolved(JSX4.getPropValue(polymorphicProp, initialScope)).value;
|
|
23
23
|
if (typeof polymorphicName === "string") {
|
|
24
24
|
return [name, polymorphicName];
|
|
@@ -141,14 +141,14 @@ var isMemoCall = isReactAPICallWithName("memo");
|
|
|
141
141
|
// src/element/hierarchy.ts
|
|
142
142
|
function isInsideCreateElementProps(node, context) {
|
|
143
143
|
const call = AST8.findParentNodeGuard(node, isCreateElementCall(context));
|
|
144
|
-
if (
|
|
144
|
+
if (call == null) return false;
|
|
145
145
|
const prop = AST8.findParentNodeGuard(node, AST8.is(AST_NODE_TYPES.ObjectExpression));
|
|
146
|
-
if (
|
|
146
|
+
if (prop == null) return false;
|
|
147
147
|
return prop === call.arguments[1];
|
|
148
148
|
}
|
|
149
149
|
function isChildrenOfCreateElement(node, context) {
|
|
150
150
|
const parent = node.parent;
|
|
151
|
-
if (
|
|
151
|
+
if (parent == null || parent.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
152
152
|
if (!isCreateElementCall(parent, context)) return false;
|
|
153
153
|
return parent.arguments.slice(2).some((arg) => arg === node);
|
|
154
154
|
}
|
|
@@ -161,12 +161,12 @@ function isReactHookName(name) {
|
|
|
161
161
|
|
|
162
162
|
// src/hook/is.ts
|
|
163
163
|
function isReactHook(node) {
|
|
164
|
-
if (node
|
|
164
|
+
if (node == null) return _;
|
|
165
165
|
const id2 = AST8.getFunctionIdentifier(node);
|
|
166
|
-
return id2?.name
|
|
166
|
+
return id2?.name != null && isReactHookName(id2.name);
|
|
167
167
|
}
|
|
168
168
|
function isReactHookCall(node) {
|
|
169
|
-
if (node
|
|
169
|
+
if (node == null) return false;
|
|
170
170
|
if (node.type !== AST_NODE_TYPES.CallExpression) {
|
|
171
171
|
return false;
|
|
172
172
|
}
|
|
@@ -179,7 +179,7 @@ function isReactHookCall(node) {
|
|
|
179
179
|
return false;
|
|
180
180
|
}
|
|
181
181
|
function isReactHookCallWithName(node, context) {
|
|
182
|
-
if (node
|
|
182
|
+
if (node == null) return returnFalse;
|
|
183
183
|
const settings = unsafeDecodeSettings(context.settings);
|
|
184
184
|
return (name) => {
|
|
185
185
|
const initialScope = context.sourceCode.getScope(node);
|
|
@@ -194,7 +194,7 @@ function isReactHookCallWithName(node, context) {
|
|
|
194
194
|
};
|
|
195
195
|
}
|
|
196
196
|
function isReactHookCallWithNameLoose(node) {
|
|
197
|
-
if (node
|
|
197
|
+
if (node == null) return returnFalse;
|
|
198
198
|
return (name) => {
|
|
199
199
|
switch (node.callee.type) {
|
|
200
200
|
case AST_NODE_TYPES.Identifier:
|
|
@@ -221,7 +221,7 @@ function isReactHookCallWithNameAlias(name, context, alias) {
|
|
|
221
221
|
};
|
|
222
222
|
}
|
|
223
223
|
function isUseEffectCallLoose(node) {
|
|
224
|
-
if (node
|
|
224
|
+
if (node == null) return false;
|
|
225
225
|
if (node.type !== AST_NODE_TYPES.CallExpression) {
|
|
226
226
|
return false;
|
|
227
227
|
}
|
|
@@ -260,7 +260,7 @@ function useHookCollector() {
|
|
|
260
260
|
const onFunctionEnter = (node) => {
|
|
261
261
|
const id2 = AST8.getFunctionIdentifier(node);
|
|
262
262
|
const name = id2?.name;
|
|
263
|
-
if (name
|
|
263
|
+
if (name != null && isReactHookName(name)) {
|
|
264
264
|
const key = getId();
|
|
265
265
|
fEntries.push({ key, node });
|
|
266
266
|
hooks.set(key, {
|
|
@@ -297,11 +297,11 @@ function useHookCollector() {
|
|
|
297
297
|
return;
|
|
298
298
|
}
|
|
299
299
|
const fEntry = fEntries.at(-1);
|
|
300
|
-
if (fEntry?.key
|
|
300
|
+
if (fEntry?.key == null) {
|
|
301
301
|
return;
|
|
302
302
|
}
|
|
303
303
|
const hook = hooks.get(fEntry.key);
|
|
304
|
-
if (hook
|
|
304
|
+
if (hook == null) {
|
|
305
305
|
return;
|
|
306
306
|
}
|
|
307
307
|
hooks.set(hook._, {
|
|
@@ -359,7 +359,7 @@ function isComponentWrapperCall(node, context) {
|
|
|
359
359
|
}
|
|
360
360
|
function getFunctionComponentIdentifier(node, context) {
|
|
361
361
|
const functionId = AST8.getFunctionIdentifier(node);
|
|
362
|
-
if (functionId) {
|
|
362
|
+
if (functionId != null) {
|
|
363
363
|
return functionId;
|
|
364
364
|
}
|
|
365
365
|
const { parent } = node;
|
|
@@ -371,17 +371,16 @@ function getFunctionComponentIdentifier(node, context) {
|
|
|
371
371
|
}
|
|
372
372
|
return _;
|
|
373
373
|
}
|
|
374
|
-
|
|
375
|
-
// src/component/component-name.ts
|
|
376
374
|
var RE_COMPONENT_NAME = /^_?[A-Z]/u;
|
|
377
375
|
function getComponentNameFromIdentifier(node) {
|
|
376
|
+
if (node == null) return _;
|
|
378
377
|
return Array.isArray(node) ? node.map((n) => n.name).join(".") : node.name;
|
|
379
378
|
}
|
|
380
379
|
function isComponentName(name) {
|
|
381
380
|
return RE_COMPONENT_NAME.test(name);
|
|
382
381
|
}
|
|
383
382
|
function isClassComponent(node) {
|
|
384
|
-
if ("superClass" in node && node.superClass) {
|
|
383
|
+
if ("superClass" in node && node.superClass != null) {
|
|
385
384
|
const re = /^(?:Pure)?Component$/u;
|
|
386
385
|
switch (true) {
|
|
387
386
|
case node.superClass.type === AST_NODE_TYPES.Identifier:
|
|
@@ -393,7 +392,7 @@ function isClassComponent(node) {
|
|
|
393
392
|
return false;
|
|
394
393
|
}
|
|
395
394
|
function isPureComponent(node) {
|
|
396
|
-
if ("superClass" in node && node.superClass) {
|
|
395
|
+
if ("superClass" in node && node.superClass != null) {
|
|
397
396
|
const re = /^PureComponent$/u;
|
|
398
397
|
switch (true) {
|
|
399
398
|
case node.superClass.type === AST_NODE_TYPES.Identifier:
|
|
@@ -416,13 +415,13 @@ function isFunctionOfRenderMethod(node) {
|
|
|
416
415
|
return isClassComponent(node.parent.parent.parent);
|
|
417
416
|
}
|
|
418
417
|
function isInsideRenderMethod(node) {
|
|
419
|
-
return
|
|
418
|
+
return AST8.findParentNode(node, (node2) => isRenderMethodLike(node2) && isClassComponent(node2.parent.parent)) != null;
|
|
420
419
|
}
|
|
421
420
|
|
|
422
421
|
// src/component/misc.ts
|
|
423
422
|
function hasNoneOrValidComponentName(node, context) {
|
|
424
423
|
const id2 = getFunctionComponentIdentifier(node, context);
|
|
425
|
-
if (
|
|
424
|
+
if (id2 == null) return true;
|
|
426
425
|
const name = Array.isArray(id2) ? id2.at(-1)?.name : id2.name;
|
|
427
426
|
return name != null && isComponentName(name);
|
|
428
427
|
}
|
|
@@ -454,14 +453,14 @@ function hasValidHierarchy(node, context, hint) {
|
|
|
454
453
|
AST_NODE_TYPES.ClassBody
|
|
455
454
|
])
|
|
456
455
|
);
|
|
457
|
-
return
|
|
456
|
+
return boundaryNode == null || boundaryNode.type !== AST_NODE_TYPES.JSXExpressionContainer;
|
|
458
457
|
}
|
|
459
458
|
function getComponentFlag(initPath) {
|
|
460
459
|
let flag = ERFunctionComponentFlag.None;
|
|
461
|
-
if (initPath && AST8.hasCallInFunctionInitPath("memo")(initPath)) {
|
|
460
|
+
if (initPath != null && AST8.hasCallInFunctionInitPath("memo")(initPath)) {
|
|
462
461
|
flag |= ERFunctionComponentFlag.Memo;
|
|
463
462
|
}
|
|
464
|
-
if (initPath && AST8.hasCallInFunctionInitPath("forwardRef")(initPath)) {
|
|
463
|
+
if (initPath != null && AST8.hasCallInFunctionInitPath("forwardRef")(initPath)) {
|
|
465
464
|
flag |= ERFunctionComponentFlag.ForwardRef;
|
|
466
465
|
}
|
|
467
466
|
return flag;
|
|
@@ -477,12 +476,12 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT) {
|
|
|
477
476
|
};
|
|
478
477
|
const onFunctionExit = () => {
|
|
479
478
|
const entry = functionEntries.at(-1);
|
|
480
|
-
if (
|
|
479
|
+
if (entry == null) return;
|
|
481
480
|
if (!entry.isComponent) {
|
|
482
481
|
return functionEntries.pop();
|
|
483
482
|
}
|
|
484
483
|
const shouldDrop = AST8.getNestedReturnStatements(entry.node.body).slice().reverse().some((r) => {
|
|
485
|
-
return context.sourceCode.getScope(r).block === entry.node &&
|
|
484
|
+
return context.sourceCode.getScope(r).block === entry.node && r.argument != null && !JSX4.isJSXValue(r.argument, jsxCtx, hint);
|
|
486
485
|
});
|
|
487
486
|
if (shouldDrop) {
|
|
488
487
|
components.delete(entry.key);
|
|
@@ -504,7 +503,7 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT) {
|
|
|
504
503
|
":function[type]:exit": onFunctionExit,
|
|
505
504
|
"ArrowFunctionExpression[type][body.type!='BlockStatement']"() {
|
|
506
505
|
const entry = getCurrentEntry();
|
|
507
|
-
if (
|
|
506
|
+
if (entry == null) {
|
|
508
507
|
return;
|
|
509
508
|
}
|
|
510
509
|
const { body } = entry.node;
|
|
@@ -514,7 +513,7 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT) {
|
|
|
514
513
|
}
|
|
515
514
|
const initPath = AST8.getFunctionInitPath(entry.node);
|
|
516
515
|
const id2 = getFunctionComponentIdentifier(entry.node, context);
|
|
517
|
-
const name =
|
|
516
|
+
const name = getComponentNameFromIdentifier(id2);
|
|
518
517
|
const key = getId();
|
|
519
518
|
components.set(key, {
|
|
520
519
|
_: key,
|
|
@@ -533,7 +532,7 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT) {
|
|
|
533
532
|
const { left, right } = node;
|
|
534
533
|
const componentName = left.object.type === AST_NODE_TYPES.Identifier ? left.object.name : _;
|
|
535
534
|
const component = [...components.values()].findLast(({ name }) => name != null && name === componentName);
|
|
536
|
-
if (
|
|
535
|
+
if (component == null) {
|
|
537
536
|
return;
|
|
538
537
|
}
|
|
539
538
|
components.set(component._, {
|
|
@@ -546,7 +545,7 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT) {
|
|
|
546
545
|
return;
|
|
547
546
|
}
|
|
548
547
|
const entry = getCurrentEntry();
|
|
549
|
-
if (
|
|
548
|
+
if (entry == null) {
|
|
550
549
|
return;
|
|
551
550
|
}
|
|
552
551
|
functionEntries.pop();
|
|
@@ -554,7 +553,7 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT) {
|
|
|
554
553
|
},
|
|
555
554
|
"ReturnStatement[type]"(node) {
|
|
556
555
|
const entry = getCurrentEntry();
|
|
557
|
-
if (
|
|
556
|
+
if (entry == null) {
|
|
558
557
|
return;
|
|
559
558
|
}
|
|
560
559
|
const isComponent = hasNoneOrValidComponentName(entry.node, context) && JSX4.isJSXValue(node.argument, jsxCtx, hint) && hasValidHierarchy(entry.node, context, hint);
|
|
@@ -565,7 +564,7 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT) {
|
|
|
565
564
|
functionEntries.push({ ...entry, isComponent });
|
|
566
565
|
const initPath = AST8.getFunctionInitPath(entry.node);
|
|
567
566
|
const id2 = getFunctionComponentIdentifier(entry.node, context);
|
|
568
|
-
const name =
|
|
567
|
+
const name = getComponentNameFromIdentifier(id2);
|
|
569
568
|
components.set(entry.key, {
|
|
570
569
|
_: entry.key,
|
|
571
570
|
id: id2,
|
|
@@ -621,7 +620,7 @@ function useComponentCollectorLegacy() {
|
|
|
621
620
|
return { ctx, listeners };
|
|
622
621
|
}
|
|
623
622
|
function isSetupFunction(node) {
|
|
624
|
-
if (node
|
|
623
|
+
if (node == null) return _;
|
|
625
624
|
return node.parent?.type === AST_NODE_TYPES.CallExpression && node.parent.callee !== node && node.parent.callee.type === AST_NODE_TYPES.Identifier && node.parent.arguments.at(0) === node && isUseEffectCallLoose(node.parent);
|
|
626
625
|
}
|
|
627
626
|
function isCleanupFunction(node) {
|
|
@@ -651,7 +650,7 @@ function isDirectValueOfRenderPropertyLoose(node) {
|
|
|
651
650
|
const matching = (node2) => {
|
|
652
651
|
return node2.type === AST_NODE_TYPES.Property && node2.key.type === AST_NODE_TYPES.Identifier && node2.key.name.startsWith("render");
|
|
653
652
|
};
|
|
654
|
-
return matching(node) ||
|
|
653
|
+
return matching(node) || node.parent != null && matching(node.parent);
|
|
655
654
|
}
|
|
656
655
|
function isDeclaredInRenderPropLoose(node) {
|
|
657
656
|
if (isDirectValueOfRenderPropertyLoose(node)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/core",
|
|
3
|
-
"version": "1.24.0-next.
|
|
3
|
+
"version": "1.24.0-next.1",
|
|
4
4
|
"description": "ESLint React's ESLint utility module for static analysis of React core APIs and Patterns.",
|
|
5
5
|
"homepage": "https://github.com/Rel1cx/eslint-react",
|
|
6
6
|
"bugs": {
|
|
@@ -38,12 +38,12 @@
|
|
|
38
38
|
"@typescript-eslint/types": "^8.19.1",
|
|
39
39
|
"@typescript-eslint/utils": "^8.19.1",
|
|
40
40
|
"ts-pattern": "^5.6.0",
|
|
41
|
-
"@eslint-react/ast": "1.24.0-next.
|
|
42
|
-
"@eslint-react/
|
|
43
|
-
"@eslint-react/
|
|
44
|
-
"@eslint-react/
|
|
45
|
-
"@eslint-react/var": "1.24.0-next.
|
|
46
|
-
"@eslint-react/types": "1.24.0-next.
|
|
41
|
+
"@eslint-react/ast": "1.24.0-next.1",
|
|
42
|
+
"@eslint-react/jsx": "1.24.0-next.1",
|
|
43
|
+
"@eslint-react/eff": "1.24.0-next.1",
|
|
44
|
+
"@eslint-react/shared": "1.24.0-next.1",
|
|
45
|
+
"@eslint-react/var": "1.24.0-next.1",
|
|
46
|
+
"@eslint-react/types": "1.24.0-next.1"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"tsup": "^8.3.5",
|