@eslint-react/core 1.28.0 → 1.28.1-beta.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 +39 -2067
- package/dist/index.d.ts +39 -2067
- package/dist/index.js +108 -123
- package/dist/index.mjs +104 -117
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var AST7 = require('@eslint-react/ast');
|
|
4
4
|
var eff = require('@eslint-react/eff');
|
|
5
5
|
var JSX3 = require('@eslint-react/jsx');
|
|
6
6
|
var shared = require('@eslint-react/shared');
|
|
@@ -29,7 +29,7 @@ function _interopNamespace(e) {
|
|
|
29
29
|
return Object.freeze(n);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
var
|
|
32
|
+
var AST7__namespace = /*#__PURE__*/_interopNamespace(AST7);
|
|
33
33
|
var JSX3__namespace = /*#__PURE__*/_interopNamespace(JSX3);
|
|
34
34
|
var VAR__namespace = /*#__PURE__*/_interopNamespace(VAR);
|
|
35
35
|
var birecord__default = /*#__PURE__*/_interopDefault(birecord);
|
|
@@ -508,6 +508,17 @@ var ESLintReactSettingsSchema = object({
|
|
|
508
508
|
var DEFAULT_ESLINT_REACT_SETTINGS = {
|
|
509
509
|
...parse(ESLintReactSettingsSchema, {}),
|
|
510
510
|
importSource: "react"};
|
|
511
|
+
var DISPLAY_NAME_ASSIGNMENT_SELECTOR = [
|
|
512
|
+
"AssignmentExpression",
|
|
513
|
+
"[type]",
|
|
514
|
+
"[operator='=']",
|
|
515
|
+
"[left.type='MemberExpression']",
|
|
516
|
+
"[left.property.name='displayName']"
|
|
517
|
+
].join("");
|
|
518
|
+
function isDisplayNameAssignment(node) {
|
|
519
|
+
if (node == null) return false;
|
|
520
|
+
return node.type === types.AST_NODE_TYPES.AssignmentExpression && node.operator === "=" && node.left.type === types.AST_NODE_TYPES.MemberExpression && node.left.property.type === types.AST_NODE_TYPES.Identifier && node.left.property.name === "displayName";
|
|
521
|
+
}
|
|
511
522
|
function getRequireExpressionArguments(node) {
|
|
512
523
|
return tsPattern.match(node).with({ type: types.AST_NODE_TYPES.CallExpression, arguments: tsPattern.P.select(), callee: { type: types.AST_NODE_TYPES.Identifier, name: "require" } }, eff.identity).with({ type: types.AST_NODE_TYPES.MemberExpression, object: tsPattern.P.select() }, getRequireExpressionArguments).otherwise(() => eff._);
|
|
513
524
|
}
|
|
@@ -526,7 +537,7 @@ function isInitializedFromReact(name, importSource, initialScope) {
|
|
|
526
537
|
}
|
|
527
538
|
const args = getRequireExpressionArguments(init);
|
|
528
539
|
const arg0 = args?.[0];
|
|
529
|
-
if (arg0 == null || !
|
|
540
|
+
if (arg0 == null || !AST7__namespace.isKindOfLiteral(arg0, "string")) {
|
|
530
541
|
return false;
|
|
531
542
|
}
|
|
532
543
|
return arg0.value === importSource || arg0.value.startsWith(`${importSource}/`);
|
|
@@ -537,113 +548,89 @@ function isInitializedFromReact(name, importSource, initialScope) {
|
|
|
537
548
|
// src/utils/is-from-react.ts
|
|
538
549
|
var defaultImportSource = shared.DEFAULT_ESLINT_REACT_SETTINGS.importSource;
|
|
539
550
|
function isFromReactLoose(node, name) {
|
|
540
|
-
|
|
541
|
-
|
|
551
|
+
switch (node?.type) {
|
|
552
|
+
case types.AST_NODE_TYPES.Identifier:
|
|
553
|
+
return node.name === name;
|
|
554
|
+
case types.AST_NODE_TYPES.MemberExpression:
|
|
555
|
+
return node.object.type === types.AST_NODE_TYPES.Identifier && node.property.type === types.AST_NODE_TYPES.Identifier && node.property.name === name;
|
|
556
|
+
default:
|
|
557
|
+
return false;
|
|
542
558
|
}
|
|
543
|
-
return node.name === name;
|
|
544
559
|
}
|
|
545
560
|
function isFromReactStrict(node, name, importSource, initialScope) {
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
561
|
+
switch (node?.type) {
|
|
562
|
+
case types.AST_NODE_TYPES.Identifier:
|
|
563
|
+
return node.name === name && isInitializedFromReact(name, importSource, initialScope);
|
|
564
|
+
case types.AST_NODE_TYPES.MemberExpression:
|
|
565
|
+
return node.object.type === types.AST_NODE_TYPES.Identifier && node.property.type === types.AST_NODE_TYPES.Identifier && node.property.name === name && isInitializedFromReact(node.object.name, importSource, initialScope);
|
|
566
|
+
default:
|
|
567
|
+
return false;
|
|
551
568
|
}
|
|
552
|
-
return false;
|
|
553
569
|
}
|
|
554
570
|
function isFromReact(name) {
|
|
555
|
-
return (context, node) => {
|
|
571
|
+
return eff.dual(2, (context, node) => {
|
|
572
|
+
if (node == null) return false;
|
|
556
573
|
const { importSource = defaultImportSource, skipImportCheck = true } = shared.unsafeDecodeSettings(context.settings);
|
|
557
574
|
if (skipImportCheck) return isFromReactLoose(node, name);
|
|
558
575
|
return isFromReactStrict(node, name, importSource, context.sourceCode.getScope(node));
|
|
559
|
-
};
|
|
560
|
-
}
|
|
561
|
-
function isFromReactMemberLoose(node, memberName, name) {
|
|
562
|
-
const { object: object2, property } = node;
|
|
563
|
-
if (property.type !== types.AST_NODE_TYPES.Identifier || property.name !== name) return false;
|
|
564
|
-
if (object2.type === types.AST_NODE_TYPES.Identifier && object2.name === memberName) return true;
|
|
565
|
-
if (object2.type === types.AST_NODE_TYPES.MemberExpression && object2.object.type === types.AST_NODE_TYPES.Identifier && object2.property.type === types.AST_NODE_TYPES.Identifier) {
|
|
566
|
-
return object2.property.name === memberName;
|
|
567
|
-
}
|
|
568
|
-
return false;
|
|
569
|
-
}
|
|
570
|
-
function isFromReactMemberStrict(node, memberName, name, importSource, initialScope) {
|
|
571
|
-
const { object: object2, property } = node;
|
|
572
|
-
if (property.type !== types.AST_NODE_TYPES.Identifier || property.name !== name) {
|
|
573
|
-
return false;
|
|
574
|
-
}
|
|
575
|
-
if (object2.type === types.AST_NODE_TYPES.Identifier && object2.name === memberName) {
|
|
576
|
-
return isInitializedFromReact(object2.name, importSource, initialScope);
|
|
577
|
-
}
|
|
578
|
-
if (object2.type === types.AST_NODE_TYPES.MemberExpression && object2.object.type === types.AST_NODE_TYPES.Identifier && isInitializedFromReact(object2.object.name, importSource, initialScope) && object2.property.type === types.AST_NODE_TYPES.Identifier) {
|
|
579
|
-
return object2.property.name === memberName;
|
|
580
|
-
}
|
|
581
|
-
return false;
|
|
576
|
+
});
|
|
582
577
|
}
|
|
583
|
-
function
|
|
584
|
-
return (context, node) => {
|
|
578
|
+
function isFromReactObject(objectName, propertyName) {
|
|
579
|
+
return eff.dual(2, (context, node) => {
|
|
580
|
+
if (node?.type !== types.AST_NODE_TYPES.MemberExpression) return false;
|
|
585
581
|
const { importSource = defaultImportSource, skipImportCheck = true } = shared.unsafeDecodeSettings(context.settings);
|
|
586
|
-
|
|
587
|
-
return
|
|
588
|
-
|
|
582
|
+
const { object: object2, property } = node;
|
|
583
|
+
if (skipImportCheck) return isFromReactLoose(object2, objectName) && isFromReactLoose(property, propertyName);
|
|
584
|
+
return isFromReactStrict(
|
|
585
|
+
object2,
|
|
586
|
+
objectName,
|
|
587
|
+
importSource,
|
|
588
|
+
context.sourceCode.getScope(object2)
|
|
589
|
+
) && isFromReactLoose(property, propertyName);
|
|
590
|
+
});
|
|
589
591
|
}
|
|
590
|
-
|
|
591
|
-
// src/utils/is-call-from-react.ts
|
|
592
592
|
function isCallFromReact(name) {
|
|
593
593
|
return eff.dual(2, (context, node) => {
|
|
594
594
|
if (node.type !== types.AST_NODE_TYPES.CallExpression) return false;
|
|
595
|
-
if (!AST8__namespace.isOneOf([types.AST_NODE_TYPES.Identifier, types.AST_NODE_TYPES.MemberExpression])(node.callee)) return false;
|
|
596
595
|
return isFromReact(name)(context, node.callee);
|
|
597
596
|
});
|
|
598
597
|
}
|
|
599
|
-
function
|
|
598
|
+
function isCallFromReactObject(objectName, propertyName) {
|
|
600
599
|
return eff.dual(2, (context, node) => {
|
|
601
600
|
if (node.type !== types.AST_NODE_TYPES.CallExpression) return false;
|
|
602
|
-
|
|
603
|
-
return isFromReactMember(pragmaMemberName, name)(context, node.callee);
|
|
601
|
+
return isFromReactObject(objectName, propertyName)(context, node.callee);
|
|
604
602
|
});
|
|
605
603
|
}
|
|
606
|
-
var DISPLAY_NAME_ASSIGNMENT_SELECTOR = [
|
|
607
|
-
"AssignmentExpression",
|
|
608
|
-
"[type]",
|
|
609
|
-
"[operator='=']",
|
|
610
|
-
"[left.type='MemberExpression']",
|
|
611
|
-
"[left.property.name='displayName']"
|
|
612
|
-
].join("");
|
|
613
|
-
function isDisplayNameAssignment(node) {
|
|
614
|
-
if (node == null) return false;
|
|
615
|
-
return node.type === types.AST_NODE_TYPES.AssignmentExpression && node.operator === "=" && node.left.type === types.AST_NODE_TYPES.MemberExpression && node.left.property.type === types.AST_NODE_TYPES.Identifier && node.left.property.name === "displayName";
|
|
616
|
-
}
|
|
617
604
|
|
|
618
605
|
// src/utils/is-react-api.ts
|
|
619
|
-
function
|
|
620
|
-
return
|
|
621
|
-
}
|
|
622
|
-
function
|
|
623
|
-
return
|
|
624
|
-
}
|
|
625
|
-
var isChildrenCount =
|
|
626
|
-
var isChildrenForEach =
|
|
627
|
-
var isChildrenMap =
|
|
628
|
-
var isChildrenOnly =
|
|
629
|
-
var isChildrenToArray =
|
|
630
|
-
var isCloneElement =
|
|
631
|
-
var isCreateContext =
|
|
632
|
-
var isCreateElement =
|
|
633
|
-
var isCreateRef =
|
|
634
|
-
var isForwardRef =
|
|
635
|
-
var isMemo =
|
|
636
|
-
var isChildrenCountCall =
|
|
637
|
-
var isChildrenForEachCall =
|
|
638
|
-
var isChildrenMapCall =
|
|
639
|
-
var isChildrenOnlyCall =
|
|
640
|
-
var isChildrenToArrayCall =
|
|
641
|
-
var isCloneElementCall =
|
|
642
|
-
var isCreateContextCall =
|
|
643
|
-
var isCreateElementCall =
|
|
644
|
-
var isCreateRefCall =
|
|
645
|
-
var isForwardRefCall =
|
|
646
|
-
var isMemoCall =
|
|
606
|
+
function isReactAPI(arg0, arg1) {
|
|
607
|
+
return arg1 == null ? isFromReact(arg0) : isFromReactObject(arg0, arg1);
|
|
608
|
+
}
|
|
609
|
+
function isReactAPICall(arg0, arg1) {
|
|
610
|
+
return arg1 == null ? isCallFromReact(arg0) : isCallFromReactObject(arg0, arg1);
|
|
611
|
+
}
|
|
612
|
+
var isChildrenCount = isReactAPI("Children", "count");
|
|
613
|
+
var isChildrenForEach = isReactAPI("Children", "forEach");
|
|
614
|
+
var isChildrenMap = isReactAPI("Children", "map");
|
|
615
|
+
var isChildrenOnly = isReactAPI("Children", "only");
|
|
616
|
+
var isChildrenToArray = isReactAPI("Children", "toArray");
|
|
617
|
+
var isCloneElement = isReactAPI("cloneElement");
|
|
618
|
+
var isCreateContext = isReactAPI("createContext");
|
|
619
|
+
var isCreateElement = isReactAPI("createElement");
|
|
620
|
+
var isCreateRef = isReactAPI("createRef");
|
|
621
|
+
var isForwardRef = isReactAPI("forwardRef");
|
|
622
|
+
var isMemo = isReactAPI("memo");
|
|
623
|
+
var isChildrenCountCall = isReactAPICall("Children", "count");
|
|
624
|
+
var isChildrenForEachCall = isReactAPICall("Children", "forEach");
|
|
625
|
+
var isChildrenMapCall = isReactAPICall("Children", "map");
|
|
626
|
+
var isChildrenOnlyCall = isReactAPICall("Children", "only");
|
|
627
|
+
var isChildrenToArrayCall = isReactAPICall("Children", "toArray");
|
|
628
|
+
var isCloneElementCall = isReactAPICall("cloneElement");
|
|
629
|
+
var isCreateContextCall = isReactAPICall("createContext");
|
|
630
|
+
var isCreateElementCall = isReactAPICall("createElement");
|
|
631
|
+
var isCreateRefCall = isReactAPICall("createRef");
|
|
632
|
+
var isForwardRefCall = isReactAPICall("forwardRef");
|
|
633
|
+
var isMemoCall = isReactAPICall("memo");
|
|
647
634
|
|
|
648
635
|
// src/hook/hook-name.ts
|
|
649
636
|
var RE_HOOK_NAME = /^use[A-Z\d]/u;
|
|
@@ -654,7 +641,7 @@ function isReactHookName(name) {
|
|
|
654
641
|
// src/hook/is.ts
|
|
655
642
|
function isReactHook(node) {
|
|
656
643
|
if (node == null) return eff._;
|
|
657
|
-
const id =
|
|
644
|
+
const id = AST7__namespace.getFunctionIdentifier(node);
|
|
658
645
|
return id?.name != null && isReactHookName(id.name);
|
|
659
646
|
}
|
|
660
647
|
function isReactHookCall(node) {
|
|
@@ -750,13 +737,13 @@ var isUseTransitionCall = eff.flip(isReactHookCallWithName)("useTransition");
|
|
|
750
737
|
|
|
751
738
|
// src/hook/hierarchy.ts
|
|
752
739
|
function isInsideReactHook(node) {
|
|
753
|
-
return isReactHook(
|
|
740
|
+
return isReactHook(AST7__namespace.findParentNode(node, AST7__namespace.isFunction));
|
|
754
741
|
}
|
|
755
742
|
function useHookCollector() {
|
|
756
743
|
const hooks = /* @__PURE__ */ new Map();
|
|
757
744
|
const functionEntries = [];
|
|
758
745
|
const onFunctionEnter = (node) => {
|
|
759
|
-
const id =
|
|
746
|
+
const id = AST7__namespace.getFunctionIdentifier(node);
|
|
760
747
|
const key = shared.getId();
|
|
761
748
|
const name = id?.name;
|
|
762
749
|
if (name != null && isReactHookName(name)) {
|
|
@@ -852,7 +839,7 @@ function isComponentWrapperCall(context, node) {
|
|
|
852
839
|
return isMemoCall(context, node) || isForwardRefCall(context, node) || isReactHookCallWithNameLoose(node)("useCallback");
|
|
853
840
|
}
|
|
854
841
|
function getFunctionComponentIdentifier(context, node) {
|
|
855
|
-
const functionId =
|
|
842
|
+
const functionId = AST7__namespace.getFunctionIdentifier(node);
|
|
856
843
|
if (functionId != null) {
|
|
857
844
|
return functionId;
|
|
858
845
|
}
|
|
@@ -880,9 +867,9 @@ function hasNoneOrValidComponentName(context, node) {
|
|
|
880
867
|
return name != null && isComponentName(name);
|
|
881
868
|
}
|
|
882
869
|
function isInsideCreateElementProps(context, node) {
|
|
883
|
-
const call =
|
|
870
|
+
const call = AST7__namespace.findParentNode(node, isCreateElementCall(context));
|
|
884
871
|
if (call == null) return false;
|
|
885
|
-
const prop =
|
|
872
|
+
const prop = AST7__namespace.findParentNode(node, AST7__namespace.is(types.AST_NODE_TYPES.ObjectExpression));
|
|
886
873
|
if (prop == null) return false;
|
|
887
874
|
return prop === call.arguments[1];
|
|
888
875
|
}
|
|
@@ -919,28 +906,28 @@ function isPureComponent(node) {
|
|
|
919
906
|
|
|
920
907
|
// src/component/component-lifecycle.ts
|
|
921
908
|
function isComponentDidMount(node) {
|
|
922
|
-
return
|
|
909
|
+
return AST7__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentDidMount";
|
|
923
910
|
}
|
|
924
911
|
function isComponentWillUnmount(node) {
|
|
925
|
-
return
|
|
912
|
+
return AST7__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentWillUnmount";
|
|
926
913
|
}
|
|
927
914
|
function isComponentDidCatch(node) {
|
|
928
|
-
return
|
|
915
|
+
return AST7__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentDidCatch";
|
|
929
916
|
}
|
|
930
917
|
function isGetDerivedStateFromError(node) {
|
|
931
|
-
return
|
|
918
|
+
return AST7__namespace.isMethodOrProperty(node) && node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromError";
|
|
932
919
|
}
|
|
933
920
|
function isGetDerivedStateFromProps(node) {
|
|
934
|
-
return
|
|
921
|
+
return AST7__namespace.isMethodOrProperty(node) && node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromProps";
|
|
935
922
|
}
|
|
936
923
|
function isFunctionOfComponentDidMount(node) {
|
|
937
|
-
return
|
|
924
|
+
return AST7__namespace.isFunction(node) && isComponentDidMount(node.parent) && node.parent.value === node;
|
|
938
925
|
}
|
|
939
926
|
function isFunctionOfComponentWillUnmount(node) {
|
|
940
|
-
return
|
|
927
|
+
return AST7__namespace.isFunction(node) && isComponentWillUnmount(node.parent) && node.parent.value === node;
|
|
941
928
|
}
|
|
942
929
|
function isRenderMethodLike(node) {
|
|
943
|
-
return
|
|
930
|
+
return AST7__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "render" && node.parent.parent.type === types.AST_NODE_TYPES.ClassDeclaration;
|
|
944
931
|
}
|
|
945
932
|
function isFunctionOfRenderMethod(node) {
|
|
946
933
|
if (!isRenderMethodLike(node.parent)) {
|
|
@@ -949,7 +936,7 @@ function isFunctionOfRenderMethod(node) {
|
|
|
949
936
|
return isClassComponent(node.parent.parent.parent);
|
|
950
937
|
}
|
|
951
938
|
function isInsideRenderMethod(node) {
|
|
952
|
-
return
|
|
939
|
+
return AST7__namespace.findParentNode(node, (node2) => isRenderMethodLike(node2) && isClassComponent(node2.parent.parent)) != null;
|
|
953
940
|
}
|
|
954
941
|
|
|
955
942
|
// src/component/hierarchy.ts
|
|
@@ -957,7 +944,7 @@ function hasValidHierarchy(context, node, hint) {
|
|
|
957
944
|
if (isChildrenOfCreateElement(context, node) || isFunctionOfRenderMethod(node)) {
|
|
958
945
|
return false;
|
|
959
946
|
}
|
|
960
|
-
if (hint & ERComponentHint.SkipMapCallback &&
|
|
947
|
+
if (hint & ERComponentHint.SkipMapCallback && AST7__namespace.isMapCallLoose(node.parent)) {
|
|
961
948
|
return false;
|
|
962
949
|
}
|
|
963
950
|
if (hint & ERComponentHint.SkipObjectMethod && isFunctionOfObjectMethod(node.parent)) {
|
|
@@ -969,9 +956,9 @@ function hasValidHierarchy(context, node, hint) {
|
|
|
969
956
|
if (hint & ERComponentHint.SkipClassProperty && isFunctionOfClassProperty(node.parent)) {
|
|
970
957
|
return false;
|
|
971
958
|
}
|
|
972
|
-
const boundaryNode =
|
|
959
|
+
const boundaryNode = AST7__namespace.findParentNode(
|
|
973
960
|
node,
|
|
974
|
-
|
|
961
|
+
AST7__namespace.isOneOf([
|
|
975
962
|
types.AST_NODE_TYPES.JSXExpressionContainer,
|
|
976
963
|
types.AST_NODE_TYPES.ArrowFunctionExpression,
|
|
977
964
|
types.AST_NODE_TYPES.FunctionExpression,
|
|
@@ -1006,7 +993,7 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT, options =
|
|
|
1006
993
|
const entry = functionEntries.at(-1);
|
|
1007
994
|
if (entry == null) return;
|
|
1008
995
|
if (!entry.isComponent) return functionEntries.pop();
|
|
1009
|
-
const shouldDrop =
|
|
996
|
+
const shouldDrop = AST7__namespace.getNestedReturnStatements(entry.node.body).slice().reverse().some((r) => {
|
|
1010
997
|
return context.sourceCode.getScope(r).block === entry.node && r.argument != null && !JSX3__namespace.isJSXValue(r.argument, jsxCtx, hint);
|
|
1011
998
|
});
|
|
1012
999
|
if (shouldDrop) {
|
|
@@ -1033,7 +1020,7 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT, options =
|
|
|
1033
1020
|
const { body } = entry.node;
|
|
1034
1021
|
const isComponent = hasNoneOrValidComponentName(context, entry.node) && JSX3__namespace.isJSXValue(body, jsxCtx, hint) && hasValidHierarchy(context, entry.node, hint);
|
|
1035
1022
|
if (!isComponent) return;
|
|
1036
|
-
const initPath =
|
|
1023
|
+
const initPath = AST7__namespace.getFunctionInitPath(entry.node);
|
|
1037
1024
|
const id = getFunctionComponentIdentifier(context, entry.node);
|
|
1038
1025
|
const name = getComponentNameFromIdentifier(id);
|
|
1039
1026
|
const key = shared.getId();
|
|
@@ -1074,7 +1061,7 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT, options =
|
|
|
1074
1061
|
const isComponent = hasNoneOrValidComponentName(context, entry.node) && JSX3__namespace.isJSXValue(node.argument, jsxCtx, hint) && hasValidHierarchy(context, entry.node, hint);
|
|
1075
1062
|
if (!isComponent) return;
|
|
1076
1063
|
entry.isComponent = true;
|
|
1077
|
-
const initPath =
|
|
1064
|
+
const initPath = AST7__namespace.getFunctionInitPath(entry.node);
|
|
1078
1065
|
const id = getFunctionComponentIdentifier(context, entry.node);
|
|
1079
1066
|
const name = getComponentNameFromIdentifier(id);
|
|
1080
1067
|
components.set(entry.key, {
|
|
@@ -1095,10 +1082,10 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT, options =
|
|
|
1095
1082
|
}
|
|
1096
1083
|
function getComponentFlag(initPath) {
|
|
1097
1084
|
let flag = ERComponentFlag.None;
|
|
1098
|
-
if (initPath != null &&
|
|
1085
|
+
if (initPath != null && AST7__namespace.hasCallInFunctionInitPath("memo", initPath)) {
|
|
1099
1086
|
flag |= ERComponentFlag.Memo;
|
|
1100
1087
|
}
|
|
1101
|
-
if (initPath != null &&
|
|
1088
|
+
if (initPath != null && AST7__namespace.hasCallInFunctionInitPath("forwardRef", initPath)) {
|
|
1102
1089
|
flag |= ERComponentFlag.ForwardRef;
|
|
1103
1090
|
}
|
|
1104
1091
|
return flag;
|
|
@@ -1115,7 +1102,7 @@ function useComponentCollectorLegacy() {
|
|
|
1115
1102
|
if (!isClassComponent(node)) {
|
|
1116
1103
|
return;
|
|
1117
1104
|
}
|
|
1118
|
-
const id =
|
|
1105
|
+
const id = AST7__namespace.getClassIdentifier(node);
|
|
1119
1106
|
const key = shared.getId();
|
|
1120
1107
|
const flag = isPureComponent(node) ? ERComponentFlag.PureComponent : ERComponentFlag.None;
|
|
1121
1108
|
components.set(
|
|
@@ -1148,7 +1135,7 @@ var ERPhaseRelevance = birecord__default.default({
|
|
|
1148
1135
|
var isInversePhase = eff.dual(2, (a, b) => ERPhaseRelevance.get(a) === b);
|
|
1149
1136
|
function isRenderFunctionLoose(context, node) {
|
|
1150
1137
|
const { body, parent } = node;
|
|
1151
|
-
if (
|
|
1138
|
+
if (AST7__namespace.getFunctionIdentifier(node)?.name.startsWith("render")) {
|
|
1152
1139
|
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");
|
|
1153
1140
|
}
|
|
1154
1141
|
return JSX3__namespace.isJSXValue(
|
|
@@ -1163,7 +1150,7 @@ function isRenderPropLoose(context, node) {
|
|
|
1163
1150
|
if (node.name.type !== types.AST_NODE_TYPES.JSXIdentifier) {
|
|
1164
1151
|
return false;
|
|
1165
1152
|
}
|
|
1166
|
-
return node.name.name.startsWith("render") && node.value?.type === types.AST_NODE_TYPES.JSXExpressionContainer &&
|
|
1153
|
+
return node.name.name.startsWith("render") && node.value?.type === types.AST_NODE_TYPES.JSXExpressionContainer && AST7__namespace.isFunction(node.value.expression) && isRenderFunctionLoose(context, node.value.expression);
|
|
1167
1154
|
}
|
|
1168
1155
|
function isDirectValueOfRenderPropertyLoose(node) {
|
|
1169
1156
|
const matching = (node2) => {
|
|
@@ -1175,7 +1162,7 @@ function isDeclaredInRenderPropLoose(node) {
|
|
|
1175
1162
|
if (isDirectValueOfRenderPropertyLoose(node)) {
|
|
1176
1163
|
return true;
|
|
1177
1164
|
}
|
|
1178
|
-
const parent =
|
|
1165
|
+
const parent = AST7__namespace.findParentNode(node, AST7__namespace.is(types.AST_NODE_TYPES.JSXExpressionContainer))?.parent;
|
|
1179
1166
|
if (parent?.type !== types.AST_NODE_TYPES.JSXAttribute) {
|
|
1180
1167
|
return false;
|
|
1181
1168
|
}
|
|
@@ -1183,16 +1170,16 @@ function isDeclaredInRenderPropLoose(node) {
|
|
|
1183
1170
|
}
|
|
1184
1171
|
function isThisSetState(node) {
|
|
1185
1172
|
const { callee } = node;
|
|
1186
|
-
return callee.type === types.AST_NODE_TYPES.MemberExpression &&
|
|
1173
|
+
return callee.type === types.AST_NODE_TYPES.MemberExpression && AST7__namespace.isThisExpression(callee.object) && callee.property.type === types.AST_NODE_TYPES.Identifier && callee.property.name === "setState";
|
|
1187
1174
|
}
|
|
1188
1175
|
function isFunctionOfUseEffectSetup(node) {
|
|
1189
1176
|
if (node == null) return eff._;
|
|
1190
1177
|
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);
|
|
1191
1178
|
}
|
|
1192
1179
|
function isFunctionOfUseEffectCleanup(node) {
|
|
1193
|
-
const nearReturn =
|
|
1194
|
-
const nearFunction =
|
|
1195
|
-
const nearFunctionOfReturn =
|
|
1180
|
+
const nearReturn = AST7__namespace.findParentNode(node, AST7__namespace.is(types.AST_NODE_TYPES.ReturnStatement));
|
|
1181
|
+
const nearFunction = AST7__namespace.findParentNode(node, AST7__namespace.isFunction);
|
|
1182
|
+
const nearFunctionOfReturn = AST7__namespace.findParentNode(nearReturn, AST7__namespace.isFunction);
|
|
1196
1183
|
return nearFunction === nearFunctionOfReturn && isFunctionOfUseEffectSetup(nearFunction);
|
|
1197
1184
|
}
|
|
1198
1185
|
|
|
@@ -1208,7 +1195,7 @@ exports.getFunctionComponentIdentifier = getFunctionComponentIdentifier;
|
|
|
1208
1195
|
exports.hasNoneOrValidComponentName = hasNoneOrValidComponentName;
|
|
1209
1196
|
exports.hasValidHierarchy = hasValidHierarchy;
|
|
1210
1197
|
exports.isCallFromReact = isCallFromReact;
|
|
1211
|
-
exports.
|
|
1198
|
+
exports.isCallFromReactObject = isCallFromReactObject;
|
|
1212
1199
|
exports.isChildrenCount = isChildrenCount;
|
|
1213
1200
|
exports.isChildrenCountCall = isChildrenCountCall;
|
|
1214
1201
|
exports.isChildrenForEach = isChildrenForEach;
|
|
@@ -1240,9 +1227,7 @@ exports.isForwardRef = isForwardRef;
|
|
|
1240
1227
|
exports.isForwardRefCall = isForwardRefCall;
|
|
1241
1228
|
exports.isFromReact = isFromReact;
|
|
1242
1229
|
exports.isFromReactLoose = isFromReactLoose;
|
|
1243
|
-
exports.
|
|
1244
|
-
exports.isFromReactMemberLoose = isFromReactMemberLoose;
|
|
1245
|
-
exports.isFromReactMemberStrict = isFromReactMemberStrict;
|
|
1230
|
+
exports.isFromReactObject = isFromReactObject;
|
|
1246
1231
|
exports.isFromReactStrict = isFromReactStrict;
|
|
1247
1232
|
exports.isFunctionOfComponentDidMount = isFunctionOfComponentDidMount;
|
|
1248
1233
|
exports.isFunctionOfComponentWillUnmount = isFunctionOfComponentWillUnmount;
|
|
@@ -1259,8 +1244,8 @@ exports.isInversePhase = isInversePhase;
|
|
|
1259
1244
|
exports.isMemo = isMemo;
|
|
1260
1245
|
exports.isMemoCall = isMemoCall;
|
|
1261
1246
|
exports.isPureComponent = isPureComponent;
|
|
1262
|
-
exports.
|
|
1263
|
-
exports.
|
|
1247
|
+
exports.isReactAPI = isReactAPI;
|
|
1248
|
+
exports.isReactAPICall = isReactAPICall;
|
|
1264
1249
|
exports.isReactHook = isReactHook;
|
|
1265
1250
|
exports.isReactHookCall = isReactHookCall;
|
|
1266
1251
|
exports.isReactHookCallWithName = isReactHookCallWithName;
|