@eslint-react/core 1.39.0-beta.0 → 1.39.0-beta.2
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 +75 -50
- package/dist/index.d.ts +75 -50
- package/dist/index.js +134 -117
- package/dist/index.mjs +128 -114
- package/package.json +7 -7
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as AST5 from '@eslint-react/ast';
|
|
2
2
|
import { flip, dual, constFalse, identity, _ } from '@eslint-react/eff';
|
|
3
3
|
import * as JSX3 from '@eslint-react/jsx';
|
|
4
4
|
import { DEFAULT_ESLINT_REACT_SETTINGS as DEFAULT_ESLINT_REACT_SETTINGS$1, unsafeDecodeSettings, getId } from '@eslint-react/shared';
|
|
5
5
|
import { AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
6
6
|
import * as VAR from '@eslint-react/var';
|
|
7
|
-
import {
|
|
7
|
+
import { isMatching, P, match } from 'ts-pattern';
|
|
8
8
|
import '@eslint-react/kit';
|
|
9
9
|
import birecord from 'birecord';
|
|
10
10
|
|
|
@@ -533,7 +533,7 @@ function isInitializedFromReact(name, importSource, initialScope) {
|
|
|
533
533
|
}
|
|
534
534
|
const args = getRequireExpressionArguments(init);
|
|
535
535
|
const arg0 = args?.[0];
|
|
536
|
-
if (arg0 == null || !
|
|
536
|
+
if (arg0 == null || !AST5.isKindOfLiteral(arg0, "string")) {
|
|
537
537
|
return false;
|
|
538
538
|
}
|
|
539
539
|
return arg0.value === importSource || arg0.value.startsWith(`${importSource}/`);
|
|
@@ -598,7 +598,7 @@ function isCallFromReactObject(objectName, propertyName) {
|
|
|
598
598
|
});
|
|
599
599
|
}
|
|
600
600
|
function isInstanceIdEqual(context, a, b) {
|
|
601
|
-
return
|
|
601
|
+
return AST5.isNodeEqual(a, b) || VAR.isNodeValueEqual(a, b, [
|
|
602
602
|
context.sourceCode.getScope(a),
|
|
603
603
|
context.sourceCode.getScope(b)
|
|
604
604
|
]);
|
|
@@ -637,7 +637,7 @@ var isMemoCall = isReactAPICall("memo");
|
|
|
637
637
|
// src/hook/is.ts
|
|
638
638
|
function isReactHook(node) {
|
|
639
639
|
if (node == null) return false;
|
|
640
|
-
const id =
|
|
640
|
+
const id = AST5.getFunctionIdentifier(node);
|
|
641
641
|
return id?.name != null && isReactHookName(id.name);
|
|
642
642
|
}
|
|
643
643
|
function isReactHookCall(node) {
|
|
@@ -740,7 +740,7 @@ function useHookCollector() {
|
|
|
740
740
|
const hooks = /* @__PURE__ */ new Map();
|
|
741
741
|
const functionEntries = [];
|
|
742
742
|
const onFunctionEnter = (node) => {
|
|
743
|
-
const id =
|
|
743
|
+
const id = AST5.getFunctionIdentifier(node);
|
|
744
744
|
const key = getId();
|
|
745
745
|
const name = id?.name;
|
|
746
746
|
if (name != null && isReactHookName(name)) {
|
|
@@ -788,7 +788,7 @@ function useHookCollector() {
|
|
|
788
788
|
};
|
|
789
789
|
return { ctx, listeners };
|
|
790
790
|
}
|
|
791
|
-
var
|
|
791
|
+
var ComponentCollectorHint = {
|
|
792
792
|
/**
|
|
793
793
|
* 1n << 0n - 1n << 63n are reserved for JSXValueHint
|
|
794
794
|
*/
|
|
@@ -818,55 +818,7 @@ var ERComponentHint = {
|
|
|
818
818
|
*/
|
|
819
819
|
SkipClassProperty: 1n << 69n
|
|
820
820
|
};
|
|
821
|
-
var DEFAULT_COMPONENT_HINT = 0n |
|
|
822
|
-
|
|
823
|
-
// src/component/component-flag.ts
|
|
824
|
-
var ERComponentFlag = {
|
|
825
|
-
None: 0n,
|
|
826
|
-
PureComponent: 1n << 0n,
|
|
827
|
-
CreateElement: 1n << 1n,
|
|
828
|
-
Memo: 1n << 2n,
|
|
829
|
-
ForwardRef: 1n << 3n,
|
|
830
|
-
Async: 1n << 4n
|
|
831
|
-
};
|
|
832
|
-
function isComponentWrapperCall(context, node) {
|
|
833
|
-
if (node.type !== AST_NODE_TYPES.CallExpression) {
|
|
834
|
-
return false;
|
|
835
|
-
}
|
|
836
|
-
return isMemoCall(context, node) || isForwardRefCall(context, node) || isReactHookCallWithNameLoose(node)("useCallback");
|
|
837
|
-
}
|
|
838
|
-
function getFunctionComponentId(context, node) {
|
|
839
|
-
const functionId = AST6.getFunctionIdentifier(node);
|
|
840
|
-
if (functionId != null) {
|
|
841
|
-
return functionId;
|
|
842
|
-
}
|
|
843
|
-
const { parent } = node;
|
|
844
|
-
if (parent.type === AST_NODE_TYPES.CallExpression && isComponentWrapperCall(context, parent) && parent.parent.type === AST_NODE_TYPES.VariableDeclarator && parent.parent.id.type === AST_NODE_TYPES.Identifier) {
|
|
845
|
-
return parent.parent.id;
|
|
846
|
-
}
|
|
847
|
-
if (parent.type === AST_NODE_TYPES.CallExpression && isComponentWrapperCall(context, parent) && parent.parent.type === AST_NODE_TYPES.CallExpression && isComponentWrapperCall(context, parent.parent) && parent.parent.parent.type === AST_NODE_TYPES.VariableDeclarator && parent.parent.parent.id.type === AST_NODE_TYPES.Identifier) {
|
|
848
|
-
return parent.parent.parent.id;
|
|
849
|
-
}
|
|
850
|
-
return _;
|
|
851
|
-
}
|
|
852
|
-
var RE_COMPONENT_NAME = /^[A-Z]/u;
|
|
853
|
-
var RE_COMPONENT_NAME_LOOSE = /^_?[A-Z]/u;
|
|
854
|
-
function isComponentName(name) {
|
|
855
|
-
return RE_COMPONENT_NAME.test(name);
|
|
856
|
-
}
|
|
857
|
-
function isComponentNameLoose(name) {
|
|
858
|
-
return RE_COMPONENT_NAME_LOOSE.test(name);
|
|
859
|
-
}
|
|
860
|
-
function getComponentNameFromId(id) {
|
|
861
|
-
if (id == null) return _;
|
|
862
|
-
return Array.isArray(id) ? id.map((n) => n.name).join(".") : id.name;
|
|
863
|
-
}
|
|
864
|
-
function hasNoneOrLooseComponentName(context, fn) {
|
|
865
|
-
const id = getFunctionComponentId(context, fn);
|
|
866
|
-
if (id == null) return true;
|
|
867
|
-
const name = Array.isArray(id) ? id.at(-1)?.name : id.name;
|
|
868
|
-
return name != null && isComponentNameLoose(name);
|
|
869
|
-
}
|
|
821
|
+
var DEFAULT_COMPONENT_HINT = 0n | ComponentCollectorHint.SkipBooleanLiteral | ComponentCollectorHint.SkipEmptyArray | ComponentCollectorHint.SkipArrayMapArgument | ComponentCollectorHint.SkipNumberLiteral | ComponentCollectorHint.SkipStringLiteral | ComponentCollectorHint.SkipUndefined | ComponentCollectorHint.StrictArray | ComponentCollectorHint.StrictConditional | ComponentCollectorHint.StrictLogical;
|
|
870
822
|
function isClassComponent(node) {
|
|
871
823
|
if ("superClass" in node && node.superClass != null) {
|
|
872
824
|
const re = /^(?:Pure)?Component$/u;
|
|
@@ -894,28 +846,28 @@ function isPureComponent(node) {
|
|
|
894
846
|
|
|
895
847
|
// src/component/component-lifecycle.ts
|
|
896
848
|
function isComponentDidMount(node) {
|
|
897
|
-
return
|
|
849
|
+
return AST5.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentDidMount";
|
|
898
850
|
}
|
|
899
851
|
function isComponentWillUnmount(node) {
|
|
900
|
-
return
|
|
852
|
+
return AST5.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentWillUnmount";
|
|
901
853
|
}
|
|
902
854
|
function isComponentDidCatch(node) {
|
|
903
|
-
return
|
|
855
|
+
return AST5.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentDidCatch";
|
|
904
856
|
}
|
|
905
857
|
function isGetDerivedStateFromError(node) {
|
|
906
|
-
return
|
|
858
|
+
return AST5.isMethodOrProperty(node) && node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromError";
|
|
907
859
|
}
|
|
908
860
|
function isGetDerivedStateFromProps(node) {
|
|
909
|
-
return
|
|
861
|
+
return AST5.isMethodOrProperty(node) && node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromProps";
|
|
910
862
|
}
|
|
911
863
|
function isFunctionOfComponentDidMount(node) {
|
|
912
|
-
return
|
|
864
|
+
return AST5.isFunction(node) && isComponentDidMount(node.parent) && node.parent.value === node;
|
|
913
865
|
}
|
|
914
866
|
function isFunctionOfComponentWillUnmount(node) {
|
|
915
|
-
return
|
|
867
|
+
return AST5.isFunction(node) && isComponentWillUnmount(node.parent) && node.parent.value === node;
|
|
916
868
|
}
|
|
917
869
|
function isRenderMethodLike(node) {
|
|
918
|
-
return
|
|
870
|
+
return AST5.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "render" && node.parent.parent.type === AST_NODE_TYPES.ClassDeclaration;
|
|
919
871
|
}
|
|
920
872
|
function isFunctionOfRenderMethod(node) {
|
|
921
873
|
if (!isRenderMethodLike(node.parent)) {
|
|
@@ -923,30 +875,53 @@ function isFunctionOfRenderMethod(node) {
|
|
|
923
875
|
}
|
|
924
876
|
return isClassComponent(node.parent.parent.parent);
|
|
925
877
|
}
|
|
878
|
+
function isChildrenOfCreateElement(context, node) {
|
|
879
|
+
const parent = node.parent;
|
|
880
|
+
if (parent == null || parent.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
881
|
+
if (!isCreateElementCall(context, parent)) return false;
|
|
882
|
+
return parent.arguments.slice(2).some((arg) => arg === node);
|
|
883
|
+
}
|
|
926
884
|
function isInsideRenderMethod(node) {
|
|
927
|
-
return
|
|
885
|
+
return AST5.findParentNode(node, (n) => isRenderMethodLike(n) && isClassComponent(n.parent.parent)) != null;
|
|
928
886
|
}
|
|
929
887
|
|
|
930
|
-
// src/component/
|
|
931
|
-
|
|
888
|
+
// src/component/component-definition.ts
|
|
889
|
+
var isFunctionOfClassMethod = isMatching({
|
|
890
|
+
type: P.union(AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression),
|
|
891
|
+
parent: AST_NODE_TYPES.MethodDefinition
|
|
892
|
+
});
|
|
893
|
+
var isFunctionOfClassProperty = isMatching({
|
|
894
|
+
type: P.union(AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression),
|
|
895
|
+
parent: AST_NODE_TYPES.Property
|
|
896
|
+
});
|
|
897
|
+
var isFunctionOfObjectMethod = isMatching({
|
|
898
|
+
type: P.union(AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression),
|
|
899
|
+
parent: {
|
|
900
|
+
type: AST_NODE_TYPES.Property,
|
|
901
|
+
parent: {
|
|
902
|
+
type: AST_NODE_TYPES.ObjectExpression
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
});
|
|
906
|
+
function isValidComponentDefinition(context, node, hint) {
|
|
932
907
|
if (isChildrenOfCreateElement(context, node) || isFunctionOfRenderMethod(node)) {
|
|
933
908
|
return false;
|
|
934
909
|
}
|
|
935
|
-
if (hint &
|
|
910
|
+
if (hint & ComponentCollectorHint.SkipObjectMethod && isFunctionOfObjectMethod(node.parent)) {
|
|
936
911
|
return false;
|
|
937
912
|
}
|
|
938
|
-
if (hint &
|
|
913
|
+
if (hint & ComponentCollectorHint.SkipClassMethod && isFunctionOfClassMethod(node.parent)) {
|
|
939
914
|
return false;
|
|
940
915
|
}
|
|
941
|
-
if (hint &
|
|
916
|
+
if (hint & ComponentCollectorHint.SkipClassProperty && isFunctionOfClassProperty(node.parent)) {
|
|
942
917
|
return false;
|
|
943
918
|
}
|
|
944
|
-
if (hint &
|
|
919
|
+
if (hint & ComponentCollectorHint.SkipArrayMapArgument && AST5.isArrayMapCallLoose(node.parent)) {
|
|
945
920
|
return false;
|
|
946
921
|
}
|
|
947
|
-
const boundaryNode =
|
|
922
|
+
const boundaryNode = AST5.findParentNode(
|
|
948
923
|
node,
|
|
949
|
-
|
|
924
|
+
AST5.isOneOf([
|
|
950
925
|
AST_NODE_TYPES.JSXExpressionContainer,
|
|
951
926
|
AST_NODE_TYPES.ArrowFunctionExpression,
|
|
952
927
|
AST_NODE_TYPES.FunctionExpression,
|
|
@@ -956,20 +931,69 @@ function hasValidHierarchy(context, node, hint) {
|
|
|
956
931
|
);
|
|
957
932
|
return boundaryNode == null || boundaryNode.type !== AST_NODE_TYPES.JSXExpressionContainer;
|
|
958
933
|
}
|
|
959
|
-
function
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
if (!isCreateElementCall(context, parent)) return false;
|
|
963
|
-
return parent.arguments.slice(2).some((arg) => arg === node);
|
|
934
|
+
function isComponentWrapperCall(context, node) {
|
|
935
|
+
if (node.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
936
|
+
return isMemoCall(context, node) || isForwardRefCall(context, node);
|
|
964
937
|
}
|
|
965
|
-
function
|
|
966
|
-
|
|
938
|
+
function isComponentWrapperCallLoose(context, node) {
|
|
939
|
+
if (node.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
940
|
+
return isComponentWrapperCall(context, node) || isUseCallbackCall(context, node);
|
|
967
941
|
}
|
|
968
|
-
|
|
969
|
-
|
|
942
|
+
|
|
943
|
+
// src/component/component-id.ts
|
|
944
|
+
function getFunctionComponentId(context, node) {
|
|
945
|
+
const functionId = AST5.getFunctionIdentifier(node);
|
|
946
|
+
if (functionId != null) {
|
|
947
|
+
return functionId;
|
|
948
|
+
}
|
|
949
|
+
const { parent } = node;
|
|
950
|
+
if (parent.type === AST_NODE_TYPES.CallExpression && isComponentWrapperCallLoose(context, parent) && parent.parent.type === AST_NODE_TYPES.VariableDeclarator && parent.parent.id.type === AST_NODE_TYPES.Identifier) {
|
|
951
|
+
return parent.parent.id;
|
|
952
|
+
}
|
|
953
|
+
if (parent.type === AST_NODE_TYPES.CallExpression && isComponentWrapperCallLoose(context, parent) && parent.parent.type === AST_NODE_TYPES.CallExpression && isComponentWrapperCallLoose(context, parent.parent) && parent.parent.parent.type === AST_NODE_TYPES.VariableDeclarator && parent.parent.parent.id.type === AST_NODE_TYPES.Identifier) {
|
|
954
|
+
return parent.parent.parent.id;
|
|
955
|
+
}
|
|
956
|
+
return _;
|
|
970
957
|
}
|
|
971
|
-
|
|
972
|
-
|
|
958
|
+
|
|
959
|
+
// src/component/component-flag.ts
|
|
960
|
+
var ComponentFlag = {
|
|
961
|
+
None: 0n,
|
|
962
|
+
PureComponent: 1n << 0n,
|
|
963
|
+
CreateElement: 1n << 1n,
|
|
964
|
+
Memo: 1n << 2n,
|
|
965
|
+
ForwardRef: 1n << 3n,
|
|
966
|
+
Async: 1n << 4n
|
|
967
|
+
};
|
|
968
|
+
|
|
969
|
+
// src/component/component-init-path.ts
|
|
970
|
+
function getComponentFlagFromInitPath(initPath) {
|
|
971
|
+
let flag = ComponentFlag.None;
|
|
972
|
+
if (initPath != null && AST5.hasCallInFunctionInitPath("memo", initPath)) {
|
|
973
|
+
flag |= ComponentFlag.Memo;
|
|
974
|
+
}
|
|
975
|
+
if (initPath != null && AST5.hasCallInFunctionInitPath("forwardRef", initPath)) {
|
|
976
|
+
flag |= ComponentFlag.ForwardRef;
|
|
977
|
+
}
|
|
978
|
+
return flag;
|
|
979
|
+
}
|
|
980
|
+
var RE_COMPONENT_NAME = /^[A-Z]/u;
|
|
981
|
+
var RE_COMPONENT_NAME_LOOSE = /^_?[A-Z]/u;
|
|
982
|
+
function isComponentName(name) {
|
|
983
|
+
return RE_COMPONENT_NAME.test(name);
|
|
984
|
+
}
|
|
985
|
+
function isComponentNameLoose(name) {
|
|
986
|
+
return RE_COMPONENT_NAME_LOOSE.test(name);
|
|
987
|
+
}
|
|
988
|
+
function getComponentNameFromId(id) {
|
|
989
|
+
if (id == null) return _;
|
|
990
|
+
return Array.isArray(id) ? id.map((n) => n.name).join(".") : id.name;
|
|
991
|
+
}
|
|
992
|
+
function hasNoneOrLooseComponentName(context, fn) {
|
|
993
|
+
const id = getFunctionComponentId(context, fn);
|
|
994
|
+
if (id == null) return true;
|
|
995
|
+
const name = Array.isArray(id) ? id.at(-1)?.name : id.name;
|
|
996
|
+
return name != null && isComponentNameLoose(name);
|
|
973
997
|
}
|
|
974
998
|
|
|
975
999
|
// src/component/component-collector.ts
|
|
@@ -991,7 +1015,7 @@ function useComponentCollector(context, options = {}) {
|
|
|
991
1015
|
const entry = functionEntries.at(-1);
|
|
992
1016
|
if (entry == null) return;
|
|
993
1017
|
if (!entry.isComponent) return functionEntries.pop();
|
|
994
|
-
const shouldDrop =
|
|
1018
|
+
const shouldDrop = AST5.getNestedReturnStatements(entry.node.body).slice().reverse().some((r) => {
|
|
995
1019
|
return context.sourceCode.getScope(r).block === entry.node && r.argument != null && !JSX3.isJSXValue(r.argument, jsxCtx, hint);
|
|
996
1020
|
});
|
|
997
1021
|
if (shouldDrop) {
|
|
@@ -1016,9 +1040,9 @@ function useComponentCollector(context, options = {}) {
|
|
|
1016
1040
|
const entry = getCurrentEntry();
|
|
1017
1041
|
if (entry == null) return;
|
|
1018
1042
|
const { body } = entry.node;
|
|
1019
|
-
const isComponent = hasNoneOrLooseComponentName(context, entry.node) && JSX3.isJSXValue(body, jsxCtx, hint) &&
|
|
1043
|
+
const isComponent = hasNoneOrLooseComponentName(context, entry.node) && JSX3.isJSXValue(body, jsxCtx, hint) && isValidComponentDefinition(context, entry.node, hint);
|
|
1020
1044
|
if (!isComponent) return;
|
|
1021
|
-
const initPath =
|
|
1045
|
+
const initPath = AST5.getFunctionInitPath(entry.node);
|
|
1022
1046
|
const id = getFunctionComponentId(context, entry.node);
|
|
1023
1047
|
const name = getComponentNameFromId(id);
|
|
1024
1048
|
const key = getId();
|
|
@@ -1029,7 +1053,7 @@ function useComponentCollector(context, options = {}) {
|
|
|
1029
1053
|
name,
|
|
1030
1054
|
node: entry.node,
|
|
1031
1055
|
displayName: _,
|
|
1032
|
-
flag:
|
|
1056
|
+
flag: getComponentFlagFromInitPath(initPath),
|
|
1033
1057
|
hint,
|
|
1034
1058
|
hookCalls: entry.hookCalls,
|
|
1035
1059
|
initPath
|
|
@@ -1056,10 +1080,10 @@ function useComponentCollector(context, options = {}) {
|
|
|
1056
1080
|
"ReturnStatement[type]"(node) {
|
|
1057
1081
|
const entry = getCurrentEntry();
|
|
1058
1082
|
if (entry == null) return;
|
|
1059
|
-
const isComponent = hasNoneOrLooseComponentName(context, entry.node) && JSX3.isJSXValue(node.argument, jsxCtx, hint) &&
|
|
1083
|
+
const isComponent = hasNoneOrLooseComponentName(context, entry.node) && JSX3.isJSXValue(node.argument, jsxCtx, hint) && isValidComponentDefinition(context, entry.node, hint);
|
|
1060
1084
|
if (!isComponent) return;
|
|
1061
1085
|
entry.isComponent = true;
|
|
1062
|
-
const initPath =
|
|
1086
|
+
const initPath = AST5.getFunctionInitPath(entry.node);
|
|
1063
1087
|
const id = getFunctionComponentId(context, entry.node);
|
|
1064
1088
|
const name = getComponentNameFromId(id);
|
|
1065
1089
|
components.set(entry.key, {
|
|
@@ -1069,7 +1093,7 @@ function useComponentCollector(context, options = {}) {
|
|
|
1069
1093
|
name,
|
|
1070
1094
|
node: entry.node,
|
|
1071
1095
|
displayName: _,
|
|
1072
|
-
flag:
|
|
1096
|
+
flag: getComponentFlagFromInitPath(initPath),
|
|
1073
1097
|
hint,
|
|
1074
1098
|
hookCalls: entry.hookCalls,
|
|
1075
1099
|
initPath
|
|
@@ -1078,16 +1102,6 @@ function useComponentCollector(context, options = {}) {
|
|
|
1078
1102
|
};
|
|
1079
1103
|
return { ctx, listeners };
|
|
1080
1104
|
}
|
|
1081
|
-
function getComponentFlag(initPath) {
|
|
1082
|
-
let flag = ERComponentFlag.None;
|
|
1083
|
-
if (initPath != null && AST6.hasCallInFunctionInitPath("memo", initPath)) {
|
|
1084
|
-
flag |= ERComponentFlag.Memo;
|
|
1085
|
-
}
|
|
1086
|
-
if (initPath != null && AST6.hasCallInFunctionInitPath("forwardRef", initPath)) {
|
|
1087
|
-
flag |= ERComponentFlag.ForwardRef;
|
|
1088
|
-
}
|
|
1089
|
-
return flag;
|
|
1090
|
-
}
|
|
1091
1105
|
function useComponentCollectorLegacy() {
|
|
1092
1106
|
const components = /* @__PURE__ */ new Map();
|
|
1093
1107
|
const ctx = {
|
|
@@ -1100,9 +1114,9 @@ function useComponentCollectorLegacy() {
|
|
|
1100
1114
|
if (!isClassComponent(node)) {
|
|
1101
1115
|
return;
|
|
1102
1116
|
}
|
|
1103
|
-
const id =
|
|
1117
|
+
const id = AST5.getClassIdentifier(node);
|
|
1104
1118
|
const key = getId();
|
|
1105
|
-
const flag = isPureComponent(node) ?
|
|
1119
|
+
const flag = isPureComponent(node) ? ComponentFlag.PureComponent : ComponentFlag.None;
|
|
1106
1120
|
components.set(
|
|
1107
1121
|
key,
|
|
1108
1122
|
{
|
|
@@ -1126,14 +1140,14 @@ function useComponentCollectorLegacy() {
|
|
|
1126
1140
|
};
|
|
1127
1141
|
return { ctx, listeners };
|
|
1128
1142
|
}
|
|
1129
|
-
var
|
|
1143
|
+
var ComponentPhaseRelevance = birecord({
|
|
1130
1144
|
mount: "unmount",
|
|
1131
1145
|
setup: "cleanup"
|
|
1132
1146
|
});
|
|
1133
|
-
var isInversePhase = dual(2, (a, b) =>
|
|
1147
|
+
var isInversePhase = dual(2, (a, b) => ComponentPhaseRelevance.get(a) === b);
|
|
1134
1148
|
function isRenderFunctionLoose(context, node) {
|
|
1135
1149
|
const { body, parent } = node;
|
|
1136
|
-
if (
|
|
1150
|
+
if (AST5.getFunctionIdentifier(node)?.name.startsWith("render")) {
|
|
1137
1151
|
return parent.type === AST_NODE_TYPES.JSXExpressionContainer && parent.parent.type === AST_NODE_TYPES.JSXAttribute && parent.parent.name.type === AST_NODE_TYPES.JSXIdentifier && parent.parent.name.name.startsWith("render");
|
|
1138
1152
|
}
|
|
1139
1153
|
return JSX3.isJSXValue(
|
|
@@ -1148,7 +1162,7 @@ function isRenderPropLoose(context, node) {
|
|
|
1148
1162
|
if (node.name.type !== AST_NODE_TYPES.JSXIdentifier) {
|
|
1149
1163
|
return false;
|
|
1150
1164
|
}
|
|
1151
|
-
return node.name.name.startsWith("render") && node.value?.type === AST_NODE_TYPES.JSXExpressionContainer &&
|
|
1165
|
+
return node.name.name.startsWith("render") && node.value?.type === AST_NODE_TYPES.JSXExpressionContainer && AST5.isFunction(node.value.expression) && isRenderFunctionLoose(context, node.value.expression);
|
|
1152
1166
|
}
|
|
1153
1167
|
function isDirectValueOfRenderPropertyLoose(node) {
|
|
1154
1168
|
const matching = (node2) => {
|
|
@@ -1160,7 +1174,7 @@ function isDeclaredInRenderPropLoose(node) {
|
|
|
1160
1174
|
if (isDirectValueOfRenderPropertyLoose(node)) {
|
|
1161
1175
|
return true;
|
|
1162
1176
|
}
|
|
1163
|
-
const parent =
|
|
1177
|
+
const parent = AST5.findParentNode(node, AST5.is(AST_NODE_TYPES.JSXExpressionContainer))?.parent;
|
|
1164
1178
|
if (parent?.type !== AST_NODE_TYPES.JSXAttribute) {
|
|
1165
1179
|
return false;
|
|
1166
1180
|
}
|
|
@@ -1168,11 +1182,11 @@ function isDeclaredInRenderPropLoose(node) {
|
|
|
1168
1182
|
}
|
|
1169
1183
|
function isThisSetState(node) {
|
|
1170
1184
|
const { callee } = node;
|
|
1171
|
-
return callee.type === AST_NODE_TYPES.MemberExpression &&
|
|
1185
|
+
return callee.type === AST_NODE_TYPES.MemberExpression && AST5.isThisExpression(callee.object) && callee.property.type === AST_NODE_TYPES.Identifier && callee.property.name === "setState";
|
|
1172
1186
|
}
|
|
1173
1187
|
function isAssignmentToThisState(node) {
|
|
1174
1188
|
const { left } = node;
|
|
1175
|
-
return left.type === AST_NODE_TYPES.MemberExpression &&
|
|
1189
|
+
return left.type === AST_NODE_TYPES.MemberExpression && AST5.isThisExpression(left.object) && AST5.getPropertyName(left.property) === "state";
|
|
1176
1190
|
}
|
|
1177
1191
|
function isFunctionOfUseEffectSetup(node) {
|
|
1178
1192
|
if (node == null) return false;
|
|
@@ -1180,10 +1194,10 @@ function isFunctionOfUseEffectSetup(node) {
|
|
|
1180
1194
|
}
|
|
1181
1195
|
function isFunctionOfUseEffectCleanup(node) {
|
|
1182
1196
|
if (node == null) return false;
|
|
1183
|
-
const returnStatement =
|
|
1184
|
-
const enclosingFunction =
|
|
1185
|
-
const functionOfReturnStatement =
|
|
1197
|
+
const returnStatement = AST5.findParentNode(node, AST5.is(AST_NODE_TYPES.ReturnStatement));
|
|
1198
|
+
const enclosingFunction = AST5.findParentNode(node, AST5.isFunction);
|
|
1199
|
+
const functionOfReturnStatement = AST5.findParentNode(returnStatement, AST5.isFunction);
|
|
1186
1200
|
return enclosingFunction === functionOfReturnStatement && isFunctionOfUseEffectSetup(enclosingFunction);
|
|
1187
1201
|
}
|
|
1188
1202
|
|
|
1189
|
-
export {
|
|
1203
|
+
export { ComponentCollectorHint, ComponentFlag, ComponentPhaseRelevance, DEFAULT_COMPONENT_HINT, DISPLAY_NAME_ASSIGNMENT_SELECTOR, RE_COMPONENT_NAME, RE_COMPONENT_NAME_LOOSE, RE_HOOK_NAME, getComponentFlagFromInitPath, getComponentNameFromId, getFunctionComponentId, getInstanceId, hasNoneOrLooseComponentName, isAssignmentToThisState, isCallFromReact, isCallFromReactObject, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDidCatch, isComponentDidMount, isComponentName, isComponentNameLoose, isComponentWillUnmount, isComponentWrapperCall, isComponentWrapperCallLoose, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFromReact, isFromReactLoose, isFromReactObject, isFromReactStrict, isFunctionOfComponentDidMount, isFunctionOfComponentWillUnmount, isFunctionOfRenderMethod, isFunctionOfUseEffectCleanup, isFunctionOfUseEffectSetup, isGetDerivedStateFromError, isGetDerivedStateFromProps, isInitializedFromReact, isInsideRenderMethod, isInstanceIdEqual, isInversePhase, isMemo, isMemoCall, isPureComponent, isReactAPI, isReactAPICall, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isReactHookNameLoose, isRenderFunctionLoose, isRenderMethodLike, isRenderPropLoose, isThisSetState, isUseActionStateCall, isUseCall, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseFormStatusCall, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseOptimisticCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/core",
|
|
3
|
-
"version": "1.39.0-beta.
|
|
3
|
+
"version": "1.39.0-beta.2",
|
|
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": {
|
|
@@ -41,12 +41,12 @@
|
|
|
41
41
|
"@typescript-eslint/utils": "^8.28.0",
|
|
42
42
|
"birecord": "^0.1.1",
|
|
43
43
|
"ts-pattern": "^5.7.0",
|
|
44
|
-
"@eslint-react/ast": "1.39.0-beta.
|
|
45
|
-
"@eslint-react/
|
|
46
|
-
"@eslint-react/
|
|
47
|
-
"@eslint-react/
|
|
48
|
-
"@eslint-react/
|
|
49
|
-
"@eslint-react/
|
|
44
|
+
"@eslint-react/ast": "1.39.0-beta.2",
|
|
45
|
+
"@eslint-react/eff": "1.39.0-beta.2",
|
|
46
|
+
"@eslint-react/jsx": "1.39.0-beta.2",
|
|
47
|
+
"@eslint-react/kit": "1.39.0-beta.2",
|
|
48
|
+
"@eslint-react/var": "1.39.0-beta.2",
|
|
49
|
+
"@eslint-react/shared": "1.39.0-beta.2"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"tsup": "^8.4.0",
|