@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.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var AST5 = 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');
|
|
@@ -30,7 +30,7 @@ function _interopNamespace(e) {
|
|
|
30
30
|
return Object.freeze(n);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
var
|
|
33
|
+
var AST5__namespace = /*#__PURE__*/_interopNamespace(AST5);
|
|
34
34
|
var JSX3__namespace = /*#__PURE__*/_interopNamespace(JSX3);
|
|
35
35
|
var VAR__namespace = /*#__PURE__*/_interopNamespace(VAR);
|
|
36
36
|
var birecord__default = /*#__PURE__*/_interopDefault(birecord);
|
|
@@ -560,7 +560,7 @@ function isInitializedFromReact(name, importSource, initialScope) {
|
|
|
560
560
|
}
|
|
561
561
|
const args = getRequireExpressionArguments(init);
|
|
562
562
|
const arg0 = args?.[0];
|
|
563
|
-
if (arg0 == null || !
|
|
563
|
+
if (arg0 == null || !AST5__namespace.isKindOfLiteral(arg0, "string")) {
|
|
564
564
|
return false;
|
|
565
565
|
}
|
|
566
566
|
return arg0.value === importSource || arg0.value.startsWith(`${importSource}/`);
|
|
@@ -625,7 +625,7 @@ function isCallFromReactObject(objectName, propertyName) {
|
|
|
625
625
|
});
|
|
626
626
|
}
|
|
627
627
|
function isInstanceIdEqual(context, a, b) {
|
|
628
|
-
return
|
|
628
|
+
return AST5__namespace.isNodeEqual(a, b) || VAR__namespace.isNodeValueEqual(a, b, [
|
|
629
629
|
context.sourceCode.getScope(a),
|
|
630
630
|
context.sourceCode.getScope(b)
|
|
631
631
|
]);
|
|
@@ -664,7 +664,7 @@ var isMemoCall = isReactAPICall("memo");
|
|
|
664
664
|
// src/hook/is.ts
|
|
665
665
|
function isReactHook(node) {
|
|
666
666
|
if (node == null) return false;
|
|
667
|
-
const id =
|
|
667
|
+
const id = AST5__namespace.getFunctionIdentifier(node);
|
|
668
668
|
return id?.name != null && isReactHookName(id.name);
|
|
669
669
|
}
|
|
670
670
|
function isReactHookCall(node) {
|
|
@@ -767,7 +767,7 @@ function useHookCollector() {
|
|
|
767
767
|
const hooks = /* @__PURE__ */ new Map();
|
|
768
768
|
const functionEntries = [];
|
|
769
769
|
const onFunctionEnter = (node) => {
|
|
770
|
-
const id =
|
|
770
|
+
const id = AST5__namespace.getFunctionIdentifier(node);
|
|
771
771
|
const key = shared.getId();
|
|
772
772
|
const name = id?.name;
|
|
773
773
|
if (name != null && isReactHookName(name)) {
|
|
@@ -815,7 +815,7 @@ function useHookCollector() {
|
|
|
815
815
|
};
|
|
816
816
|
return { ctx, listeners };
|
|
817
817
|
}
|
|
818
|
-
var
|
|
818
|
+
var ComponentCollectorHint = {
|
|
819
819
|
/**
|
|
820
820
|
* 1n << 0n - 1n << 63n are reserved for JSXValueHint
|
|
821
821
|
*/
|
|
@@ -845,55 +845,7 @@ var ERComponentHint = {
|
|
|
845
845
|
*/
|
|
846
846
|
SkipClassProperty: 1n << 69n
|
|
847
847
|
};
|
|
848
|
-
var DEFAULT_COMPONENT_HINT = 0n |
|
|
849
|
-
|
|
850
|
-
// src/component/component-flag.ts
|
|
851
|
-
var ERComponentFlag = {
|
|
852
|
-
None: 0n,
|
|
853
|
-
PureComponent: 1n << 0n,
|
|
854
|
-
CreateElement: 1n << 1n,
|
|
855
|
-
Memo: 1n << 2n,
|
|
856
|
-
ForwardRef: 1n << 3n,
|
|
857
|
-
Async: 1n << 4n
|
|
858
|
-
};
|
|
859
|
-
function isComponentWrapperCall(context, node) {
|
|
860
|
-
if (node.type !== types.AST_NODE_TYPES.CallExpression) {
|
|
861
|
-
return false;
|
|
862
|
-
}
|
|
863
|
-
return isMemoCall(context, node) || isForwardRefCall(context, node) || isReactHookCallWithNameLoose(node)("useCallback");
|
|
864
|
-
}
|
|
865
|
-
function getFunctionComponentId(context, node) {
|
|
866
|
-
const functionId = AST6__namespace.getFunctionIdentifier(node);
|
|
867
|
-
if (functionId != null) {
|
|
868
|
-
return functionId;
|
|
869
|
-
}
|
|
870
|
-
const { parent } = node;
|
|
871
|
-
if (parent.type === types.AST_NODE_TYPES.CallExpression && isComponentWrapperCall(context, parent) && parent.parent.type === types.AST_NODE_TYPES.VariableDeclarator && parent.parent.id.type === types.AST_NODE_TYPES.Identifier) {
|
|
872
|
-
return parent.parent.id;
|
|
873
|
-
}
|
|
874
|
-
if (parent.type === types.AST_NODE_TYPES.CallExpression && isComponentWrapperCall(context, parent) && parent.parent.type === types.AST_NODE_TYPES.CallExpression && isComponentWrapperCall(context, parent.parent) && parent.parent.parent.type === types.AST_NODE_TYPES.VariableDeclarator && parent.parent.parent.id.type === types.AST_NODE_TYPES.Identifier) {
|
|
875
|
-
return parent.parent.parent.id;
|
|
876
|
-
}
|
|
877
|
-
return eff._;
|
|
878
|
-
}
|
|
879
|
-
var RE_COMPONENT_NAME = /^[A-Z]/u;
|
|
880
|
-
var RE_COMPONENT_NAME_LOOSE = /^_?[A-Z]/u;
|
|
881
|
-
function isComponentName(name) {
|
|
882
|
-
return RE_COMPONENT_NAME.test(name);
|
|
883
|
-
}
|
|
884
|
-
function isComponentNameLoose(name) {
|
|
885
|
-
return RE_COMPONENT_NAME_LOOSE.test(name);
|
|
886
|
-
}
|
|
887
|
-
function getComponentNameFromId(id) {
|
|
888
|
-
if (id == null) return eff._;
|
|
889
|
-
return Array.isArray(id) ? id.map((n) => n.name).join(".") : id.name;
|
|
890
|
-
}
|
|
891
|
-
function hasNoneOrLooseComponentName(context, fn) {
|
|
892
|
-
const id = getFunctionComponentId(context, fn);
|
|
893
|
-
if (id == null) return true;
|
|
894
|
-
const name = Array.isArray(id) ? id.at(-1)?.name : id.name;
|
|
895
|
-
return name != null && isComponentNameLoose(name);
|
|
896
|
-
}
|
|
848
|
+
var DEFAULT_COMPONENT_HINT = 0n | ComponentCollectorHint.SkipBooleanLiteral | ComponentCollectorHint.SkipEmptyArray | ComponentCollectorHint.SkipArrayMapArgument | ComponentCollectorHint.SkipNumberLiteral | ComponentCollectorHint.SkipStringLiteral | ComponentCollectorHint.SkipUndefined | ComponentCollectorHint.StrictArray | ComponentCollectorHint.StrictConditional | ComponentCollectorHint.StrictLogical;
|
|
897
849
|
function isClassComponent(node) {
|
|
898
850
|
if ("superClass" in node && node.superClass != null) {
|
|
899
851
|
const re = /^(?:Pure)?Component$/u;
|
|
@@ -921,28 +873,28 @@ function isPureComponent(node) {
|
|
|
921
873
|
|
|
922
874
|
// src/component/component-lifecycle.ts
|
|
923
875
|
function isComponentDidMount(node) {
|
|
924
|
-
return
|
|
876
|
+
return AST5__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentDidMount";
|
|
925
877
|
}
|
|
926
878
|
function isComponentWillUnmount(node) {
|
|
927
|
-
return
|
|
879
|
+
return AST5__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentWillUnmount";
|
|
928
880
|
}
|
|
929
881
|
function isComponentDidCatch(node) {
|
|
930
|
-
return
|
|
882
|
+
return AST5__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentDidCatch";
|
|
931
883
|
}
|
|
932
884
|
function isGetDerivedStateFromError(node) {
|
|
933
|
-
return
|
|
885
|
+
return AST5__namespace.isMethodOrProperty(node) && node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromError";
|
|
934
886
|
}
|
|
935
887
|
function isGetDerivedStateFromProps(node) {
|
|
936
|
-
return
|
|
888
|
+
return AST5__namespace.isMethodOrProperty(node) && node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromProps";
|
|
937
889
|
}
|
|
938
890
|
function isFunctionOfComponentDidMount(node) {
|
|
939
|
-
return
|
|
891
|
+
return AST5__namespace.isFunction(node) && isComponentDidMount(node.parent) && node.parent.value === node;
|
|
940
892
|
}
|
|
941
893
|
function isFunctionOfComponentWillUnmount(node) {
|
|
942
|
-
return
|
|
894
|
+
return AST5__namespace.isFunction(node) && isComponentWillUnmount(node.parent) && node.parent.value === node;
|
|
943
895
|
}
|
|
944
896
|
function isRenderMethodLike(node) {
|
|
945
|
-
return
|
|
897
|
+
return AST5__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "render" && node.parent.parent.type === types.AST_NODE_TYPES.ClassDeclaration;
|
|
946
898
|
}
|
|
947
899
|
function isFunctionOfRenderMethod(node) {
|
|
948
900
|
if (!isRenderMethodLike(node.parent)) {
|
|
@@ -950,30 +902,53 @@ function isFunctionOfRenderMethod(node) {
|
|
|
950
902
|
}
|
|
951
903
|
return isClassComponent(node.parent.parent.parent);
|
|
952
904
|
}
|
|
905
|
+
function isChildrenOfCreateElement(context, node) {
|
|
906
|
+
const parent = node.parent;
|
|
907
|
+
if (parent == null || parent.type !== types.AST_NODE_TYPES.CallExpression) return false;
|
|
908
|
+
if (!isCreateElementCall(context, parent)) return false;
|
|
909
|
+
return parent.arguments.slice(2).some((arg) => arg === node);
|
|
910
|
+
}
|
|
953
911
|
function isInsideRenderMethod(node) {
|
|
954
|
-
return
|
|
912
|
+
return AST5__namespace.findParentNode(node, (n) => isRenderMethodLike(n) && isClassComponent(n.parent.parent)) != null;
|
|
955
913
|
}
|
|
956
914
|
|
|
957
|
-
// src/component/
|
|
958
|
-
|
|
915
|
+
// src/component/component-definition.ts
|
|
916
|
+
var isFunctionOfClassMethod = tsPattern.isMatching({
|
|
917
|
+
type: tsPattern.P.union(types.AST_NODE_TYPES.ArrowFunctionExpression, types.AST_NODE_TYPES.FunctionExpression),
|
|
918
|
+
parent: types.AST_NODE_TYPES.MethodDefinition
|
|
919
|
+
});
|
|
920
|
+
var isFunctionOfClassProperty = tsPattern.isMatching({
|
|
921
|
+
type: tsPattern.P.union(types.AST_NODE_TYPES.ArrowFunctionExpression, types.AST_NODE_TYPES.FunctionExpression),
|
|
922
|
+
parent: types.AST_NODE_TYPES.Property
|
|
923
|
+
});
|
|
924
|
+
var isFunctionOfObjectMethod = tsPattern.isMatching({
|
|
925
|
+
type: tsPattern.P.union(types.AST_NODE_TYPES.ArrowFunctionExpression, types.AST_NODE_TYPES.FunctionExpression),
|
|
926
|
+
parent: {
|
|
927
|
+
type: types.AST_NODE_TYPES.Property,
|
|
928
|
+
parent: {
|
|
929
|
+
type: types.AST_NODE_TYPES.ObjectExpression
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
});
|
|
933
|
+
function isValidComponentDefinition(context, node, hint) {
|
|
959
934
|
if (isChildrenOfCreateElement(context, node) || isFunctionOfRenderMethod(node)) {
|
|
960
935
|
return false;
|
|
961
936
|
}
|
|
962
|
-
if (hint &
|
|
937
|
+
if (hint & ComponentCollectorHint.SkipObjectMethod && isFunctionOfObjectMethod(node.parent)) {
|
|
963
938
|
return false;
|
|
964
939
|
}
|
|
965
|
-
if (hint &
|
|
940
|
+
if (hint & ComponentCollectorHint.SkipClassMethod && isFunctionOfClassMethod(node.parent)) {
|
|
966
941
|
return false;
|
|
967
942
|
}
|
|
968
|
-
if (hint &
|
|
943
|
+
if (hint & ComponentCollectorHint.SkipClassProperty && isFunctionOfClassProperty(node.parent)) {
|
|
969
944
|
return false;
|
|
970
945
|
}
|
|
971
|
-
if (hint &
|
|
946
|
+
if (hint & ComponentCollectorHint.SkipArrayMapArgument && AST5__namespace.isArrayMapCallLoose(node.parent)) {
|
|
972
947
|
return false;
|
|
973
948
|
}
|
|
974
|
-
const boundaryNode =
|
|
949
|
+
const boundaryNode = AST5__namespace.findParentNode(
|
|
975
950
|
node,
|
|
976
|
-
|
|
951
|
+
AST5__namespace.isOneOf([
|
|
977
952
|
types.AST_NODE_TYPES.JSXExpressionContainer,
|
|
978
953
|
types.AST_NODE_TYPES.ArrowFunctionExpression,
|
|
979
954
|
types.AST_NODE_TYPES.FunctionExpression,
|
|
@@ -983,20 +958,69 @@ function hasValidHierarchy(context, node, hint) {
|
|
|
983
958
|
);
|
|
984
959
|
return boundaryNode == null || boundaryNode.type !== types.AST_NODE_TYPES.JSXExpressionContainer;
|
|
985
960
|
}
|
|
986
|
-
function
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
if (!isCreateElementCall(context, parent)) return false;
|
|
990
|
-
return parent.arguments.slice(2).some((arg) => arg === node);
|
|
961
|
+
function isComponentWrapperCall(context, node) {
|
|
962
|
+
if (node.type !== types.AST_NODE_TYPES.CallExpression) return false;
|
|
963
|
+
return isMemoCall(context, node) || isForwardRefCall(context, node);
|
|
991
964
|
}
|
|
992
|
-
function
|
|
993
|
-
|
|
965
|
+
function isComponentWrapperCallLoose(context, node) {
|
|
966
|
+
if (node.type !== types.AST_NODE_TYPES.CallExpression) return false;
|
|
967
|
+
return isComponentWrapperCall(context, node) || isUseCallbackCall(context, node);
|
|
994
968
|
}
|
|
995
|
-
|
|
996
|
-
|
|
969
|
+
|
|
970
|
+
// src/component/component-id.ts
|
|
971
|
+
function getFunctionComponentId(context, node) {
|
|
972
|
+
const functionId = AST5__namespace.getFunctionIdentifier(node);
|
|
973
|
+
if (functionId != null) {
|
|
974
|
+
return functionId;
|
|
975
|
+
}
|
|
976
|
+
const { parent } = node;
|
|
977
|
+
if (parent.type === types.AST_NODE_TYPES.CallExpression && isComponentWrapperCallLoose(context, parent) && parent.parent.type === types.AST_NODE_TYPES.VariableDeclarator && parent.parent.id.type === types.AST_NODE_TYPES.Identifier) {
|
|
978
|
+
return parent.parent.id;
|
|
979
|
+
}
|
|
980
|
+
if (parent.type === types.AST_NODE_TYPES.CallExpression && isComponentWrapperCallLoose(context, parent) && parent.parent.type === types.AST_NODE_TYPES.CallExpression && isComponentWrapperCallLoose(context, parent.parent) && parent.parent.parent.type === types.AST_NODE_TYPES.VariableDeclarator && parent.parent.parent.id.type === types.AST_NODE_TYPES.Identifier) {
|
|
981
|
+
return parent.parent.parent.id;
|
|
982
|
+
}
|
|
983
|
+
return eff._;
|
|
997
984
|
}
|
|
998
|
-
|
|
999
|
-
|
|
985
|
+
|
|
986
|
+
// src/component/component-flag.ts
|
|
987
|
+
var ComponentFlag = {
|
|
988
|
+
None: 0n,
|
|
989
|
+
PureComponent: 1n << 0n,
|
|
990
|
+
CreateElement: 1n << 1n,
|
|
991
|
+
Memo: 1n << 2n,
|
|
992
|
+
ForwardRef: 1n << 3n,
|
|
993
|
+
Async: 1n << 4n
|
|
994
|
+
};
|
|
995
|
+
|
|
996
|
+
// src/component/component-init-path.ts
|
|
997
|
+
function getComponentFlagFromInitPath(initPath) {
|
|
998
|
+
let flag = ComponentFlag.None;
|
|
999
|
+
if (initPath != null && AST5__namespace.hasCallInFunctionInitPath("memo", initPath)) {
|
|
1000
|
+
flag |= ComponentFlag.Memo;
|
|
1001
|
+
}
|
|
1002
|
+
if (initPath != null && AST5__namespace.hasCallInFunctionInitPath("forwardRef", initPath)) {
|
|
1003
|
+
flag |= ComponentFlag.ForwardRef;
|
|
1004
|
+
}
|
|
1005
|
+
return flag;
|
|
1006
|
+
}
|
|
1007
|
+
var RE_COMPONENT_NAME = /^[A-Z]/u;
|
|
1008
|
+
var RE_COMPONENT_NAME_LOOSE = /^_?[A-Z]/u;
|
|
1009
|
+
function isComponentName(name) {
|
|
1010
|
+
return RE_COMPONENT_NAME.test(name);
|
|
1011
|
+
}
|
|
1012
|
+
function isComponentNameLoose(name) {
|
|
1013
|
+
return RE_COMPONENT_NAME_LOOSE.test(name);
|
|
1014
|
+
}
|
|
1015
|
+
function getComponentNameFromId(id) {
|
|
1016
|
+
if (id == null) return eff._;
|
|
1017
|
+
return Array.isArray(id) ? id.map((n) => n.name).join(".") : id.name;
|
|
1018
|
+
}
|
|
1019
|
+
function hasNoneOrLooseComponentName(context, fn) {
|
|
1020
|
+
const id = getFunctionComponentId(context, fn);
|
|
1021
|
+
if (id == null) return true;
|
|
1022
|
+
const name = Array.isArray(id) ? id.at(-1)?.name : id.name;
|
|
1023
|
+
return name != null && isComponentNameLoose(name);
|
|
1000
1024
|
}
|
|
1001
1025
|
|
|
1002
1026
|
// src/component/component-collector.ts
|
|
@@ -1018,7 +1042,7 @@ function useComponentCollector(context, options = {}) {
|
|
|
1018
1042
|
const entry = functionEntries.at(-1);
|
|
1019
1043
|
if (entry == null) return;
|
|
1020
1044
|
if (!entry.isComponent) return functionEntries.pop();
|
|
1021
|
-
const shouldDrop =
|
|
1045
|
+
const shouldDrop = AST5__namespace.getNestedReturnStatements(entry.node.body).slice().reverse().some((r) => {
|
|
1022
1046
|
return context.sourceCode.getScope(r).block === entry.node && r.argument != null && !JSX3__namespace.isJSXValue(r.argument, jsxCtx, hint);
|
|
1023
1047
|
});
|
|
1024
1048
|
if (shouldDrop) {
|
|
@@ -1043,9 +1067,9 @@ function useComponentCollector(context, options = {}) {
|
|
|
1043
1067
|
const entry = getCurrentEntry();
|
|
1044
1068
|
if (entry == null) return;
|
|
1045
1069
|
const { body } = entry.node;
|
|
1046
|
-
const isComponent = hasNoneOrLooseComponentName(context, entry.node) && JSX3__namespace.isJSXValue(body, jsxCtx, hint) &&
|
|
1070
|
+
const isComponent = hasNoneOrLooseComponentName(context, entry.node) && JSX3__namespace.isJSXValue(body, jsxCtx, hint) && isValidComponentDefinition(context, entry.node, hint);
|
|
1047
1071
|
if (!isComponent) return;
|
|
1048
|
-
const initPath =
|
|
1072
|
+
const initPath = AST5__namespace.getFunctionInitPath(entry.node);
|
|
1049
1073
|
const id = getFunctionComponentId(context, entry.node);
|
|
1050
1074
|
const name = getComponentNameFromId(id);
|
|
1051
1075
|
const key = shared.getId();
|
|
@@ -1056,7 +1080,7 @@ function useComponentCollector(context, options = {}) {
|
|
|
1056
1080
|
name,
|
|
1057
1081
|
node: entry.node,
|
|
1058
1082
|
displayName: eff._,
|
|
1059
|
-
flag:
|
|
1083
|
+
flag: getComponentFlagFromInitPath(initPath),
|
|
1060
1084
|
hint,
|
|
1061
1085
|
hookCalls: entry.hookCalls,
|
|
1062
1086
|
initPath
|
|
@@ -1083,10 +1107,10 @@ function useComponentCollector(context, options = {}) {
|
|
|
1083
1107
|
"ReturnStatement[type]"(node) {
|
|
1084
1108
|
const entry = getCurrentEntry();
|
|
1085
1109
|
if (entry == null) return;
|
|
1086
|
-
const isComponent = hasNoneOrLooseComponentName(context, entry.node) && JSX3__namespace.isJSXValue(node.argument, jsxCtx, hint) &&
|
|
1110
|
+
const isComponent = hasNoneOrLooseComponentName(context, entry.node) && JSX3__namespace.isJSXValue(node.argument, jsxCtx, hint) && isValidComponentDefinition(context, entry.node, hint);
|
|
1087
1111
|
if (!isComponent) return;
|
|
1088
1112
|
entry.isComponent = true;
|
|
1089
|
-
const initPath =
|
|
1113
|
+
const initPath = AST5__namespace.getFunctionInitPath(entry.node);
|
|
1090
1114
|
const id = getFunctionComponentId(context, entry.node);
|
|
1091
1115
|
const name = getComponentNameFromId(id);
|
|
1092
1116
|
components.set(entry.key, {
|
|
@@ -1096,7 +1120,7 @@ function useComponentCollector(context, options = {}) {
|
|
|
1096
1120
|
name,
|
|
1097
1121
|
node: entry.node,
|
|
1098
1122
|
displayName: eff._,
|
|
1099
|
-
flag:
|
|
1123
|
+
flag: getComponentFlagFromInitPath(initPath),
|
|
1100
1124
|
hint,
|
|
1101
1125
|
hookCalls: entry.hookCalls,
|
|
1102
1126
|
initPath
|
|
@@ -1105,16 +1129,6 @@ function useComponentCollector(context, options = {}) {
|
|
|
1105
1129
|
};
|
|
1106
1130
|
return { ctx, listeners };
|
|
1107
1131
|
}
|
|
1108
|
-
function getComponentFlag(initPath) {
|
|
1109
|
-
let flag = ERComponentFlag.None;
|
|
1110
|
-
if (initPath != null && AST6__namespace.hasCallInFunctionInitPath("memo", initPath)) {
|
|
1111
|
-
flag |= ERComponentFlag.Memo;
|
|
1112
|
-
}
|
|
1113
|
-
if (initPath != null && AST6__namespace.hasCallInFunctionInitPath("forwardRef", initPath)) {
|
|
1114
|
-
flag |= ERComponentFlag.ForwardRef;
|
|
1115
|
-
}
|
|
1116
|
-
return flag;
|
|
1117
|
-
}
|
|
1118
1132
|
function useComponentCollectorLegacy() {
|
|
1119
1133
|
const components = /* @__PURE__ */ new Map();
|
|
1120
1134
|
const ctx = {
|
|
@@ -1127,9 +1141,9 @@ function useComponentCollectorLegacy() {
|
|
|
1127
1141
|
if (!isClassComponent(node)) {
|
|
1128
1142
|
return;
|
|
1129
1143
|
}
|
|
1130
|
-
const id =
|
|
1144
|
+
const id = AST5__namespace.getClassIdentifier(node);
|
|
1131
1145
|
const key = shared.getId();
|
|
1132
|
-
const flag = isPureComponent(node) ?
|
|
1146
|
+
const flag = isPureComponent(node) ? ComponentFlag.PureComponent : ComponentFlag.None;
|
|
1133
1147
|
components.set(
|
|
1134
1148
|
key,
|
|
1135
1149
|
{
|
|
@@ -1153,14 +1167,14 @@ function useComponentCollectorLegacy() {
|
|
|
1153
1167
|
};
|
|
1154
1168
|
return { ctx, listeners };
|
|
1155
1169
|
}
|
|
1156
|
-
var
|
|
1170
|
+
var ComponentPhaseRelevance = birecord__default.default({
|
|
1157
1171
|
mount: "unmount",
|
|
1158
1172
|
setup: "cleanup"
|
|
1159
1173
|
});
|
|
1160
|
-
var isInversePhase = eff.dual(2, (a, b) =>
|
|
1174
|
+
var isInversePhase = eff.dual(2, (a, b) => ComponentPhaseRelevance.get(a) === b);
|
|
1161
1175
|
function isRenderFunctionLoose(context, node) {
|
|
1162
1176
|
const { body, parent } = node;
|
|
1163
|
-
if (
|
|
1177
|
+
if (AST5__namespace.getFunctionIdentifier(node)?.name.startsWith("render")) {
|
|
1164
1178
|
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");
|
|
1165
1179
|
}
|
|
1166
1180
|
return JSX3__namespace.isJSXValue(
|
|
@@ -1175,7 +1189,7 @@ function isRenderPropLoose(context, node) {
|
|
|
1175
1189
|
if (node.name.type !== types.AST_NODE_TYPES.JSXIdentifier) {
|
|
1176
1190
|
return false;
|
|
1177
1191
|
}
|
|
1178
|
-
return node.name.name.startsWith("render") && node.value?.type === types.AST_NODE_TYPES.JSXExpressionContainer &&
|
|
1192
|
+
return node.name.name.startsWith("render") && node.value?.type === types.AST_NODE_TYPES.JSXExpressionContainer && AST5__namespace.isFunction(node.value.expression) && isRenderFunctionLoose(context, node.value.expression);
|
|
1179
1193
|
}
|
|
1180
1194
|
function isDirectValueOfRenderPropertyLoose(node) {
|
|
1181
1195
|
const matching = (node2) => {
|
|
@@ -1187,7 +1201,7 @@ function isDeclaredInRenderPropLoose(node) {
|
|
|
1187
1201
|
if (isDirectValueOfRenderPropertyLoose(node)) {
|
|
1188
1202
|
return true;
|
|
1189
1203
|
}
|
|
1190
|
-
const parent =
|
|
1204
|
+
const parent = AST5__namespace.findParentNode(node, AST5__namespace.is(types.AST_NODE_TYPES.JSXExpressionContainer))?.parent;
|
|
1191
1205
|
if (parent?.type !== types.AST_NODE_TYPES.JSXAttribute) {
|
|
1192
1206
|
return false;
|
|
1193
1207
|
}
|
|
@@ -1195,11 +1209,11 @@ function isDeclaredInRenderPropLoose(node) {
|
|
|
1195
1209
|
}
|
|
1196
1210
|
function isThisSetState(node) {
|
|
1197
1211
|
const { callee } = node;
|
|
1198
|
-
return callee.type === types.AST_NODE_TYPES.MemberExpression &&
|
|
1212
|
+
return callee.type === types.AST_NODE_TYPES.MemberExpression && AST5__namespace.isThisExpression(callee.object) && callee.property.type === types.AST_NODE_TYPES.Identifier && callee.property.name === "setState";
|
|
1199
1213
|
}
|
|
1200
1214
|
function isAssignmentToThisState(node) {
|
|
1201
1215
|
const { left } = node;
|
|
1202
|
-
return left.type === types.AST_NODE_TYPES.MemberExpression &&
|
|
1216
|
+
return left.type === types.AST_NODE_TYPES.MemberExpression && AST5__namespace.isThisExpression(left.object) && AST5__namespace.getPropertyName(left.property) === "state";
|
|
1203
1217
|
}
|
|
1204
1218
|
function isFunctionOfUseEffectSetup(node) {
|
|
1205
1219
|
if (node == null) return false;
|
|
@@ -1207,25 +1221,25 @@ function isFunctionOfUseEffectSetup(node) {
|
|
|
1207
1221
|
}
|
|
1208
1222
|
function isFunctionOfUseEffectCleanup(node) {
|
|
1209
1223
|
if (node == null) return false;
|
|
1210
|
-
const returnStatement =
|
|
1211
|
-
const enclosingFunction =
|
|
1212
|
-
const functionOfReturnStatement =
|
|
1224
|
+
const returnStatement = AST5__namespace.findParentNode(node, AST5__namespace.is(types.AST_NODE_TYPES.ReturnStatement));
|
|
1225
|
+
const enclosingFunction = AST5__namespace.findParentNode(node, AST5__namespace.isFunction);
|
|
1226
|
+
const functionOfReturnStatement = AST5__namespace.findParentNode(returnStatement, AST5__namespace.isFunction);
|
|
1213
1227
|
return enclosingFunction === functionOfReturnStatement && isFunctionOfUseEffectSetup(enclosingFunction);
|
|
1214
1228
|
}
|
|
1215
1229
|
|
|
1230
|
+
exports.ComponentCollectorHint = ComponentCollectorHint;
|
|
1231
|
+
exports.ComponentFlag = ComponentFlag;
|
|
1232
|
+
exports.ComponentPhaseRelevance = ComponentPhaseRelevance;
|
|
1216
1233
|
exports.DEFAULT_COMPONENT_HINT = DEFAULT_COMPONENT_HINT;
|
|
1217
1234
|
exports.DISPLAY_NAME_ASSIGNMENT_SELECTOR = DISPLAY_NAME_ASSIGNMENT_SELECTOR;
|
|
1218
|
-
exports.ERComponentFlag = ERComponentFlag;
|
|
1219
|
-
exports.ERComponentHint = ERComponentHint;
|
|
1220
|
-
exports.ERPhaseRelevance = ERPhaseRelevance;
|
|
1221
1235
|
exports.RE_COMPONENT_NAME = RE_COMPONENT_NAME;
|
|
1222
1236
|
exports.RE_COMPONENT_NAME_LOOSE = RE_COMPONENT_NAME_LOOSE;
|
|
1223
1237
|
exports.RE_HOOK_NAME = RE_HOOK_NAME;
|
|
1238
|
+
exports.getComponentFlagFromInitPath = getComponentFlagFromInitPath;
|
|
1224
1239
|
exports.getComponentNameFromId = getComponentNameFromId;
|
|
1225
1240
|
exports.getFunctionComponentId = getFunctionComponentId;
|
|
1226
1241
|
exports.getInstanceId = getInstanceId;
|
|
1227
1242
|
exports.hasNoneOrLooseComponentName = hasNoneOrLooseComponentName;
|
|
1228
|
-
exports.hasValidHierarchy = hasValidHierarchy;
|
|
1229
1243
|
exports.isAssignmentToThisState = isAssignmentToThisState;
|
|
1230
1244
|
exports.isCallFromReact = isCallFromReact;
|
|
1231
1245
|
exports.isCallFromReactObject = isCallFromReactObject;
|
|
@@ -1235,6 +1249,7 @@ exports.isChildrenForEach = isChildrenForEach;
|
|
|
1235
1249
|
exports.isChildrenForEachCall = isChildrenForEachCall;
|
|
1236
1250
|
exports.isChildrenMap = isChildrenMap;
|
|
1237
1251
|
exports.isChildrenMapCall = isChildrenMapCall;
|
|
1252
|
+
exports.isChildrenOfCreateElement = isChildrenOfCreateElement;
|
|
1238
1253
|
exports.isChildrenOnly = isChildrenOnly;
|
|
1239
1254
|
exports.isChildrenOnlyCall = isChildrenOnlyCall;
|
|
1240
1255
|
exports.isChildrenToArray = isChildrenToArray;
|
|
@@ -1247,6 +1262,8 @@ exports.isComponentDidMount = isComponentDidMount;
|
|
|
1247
1262
|
exports.isComponentName = isComponentName;
|
|
1248
1263
|
exports.isComponentNameLoose = isComponentNameLoose;
|
|
1249
1264
|
exports.isComponentWillUnmount = isComponentWillUnmount;
|
|
1265
|
+
exports.isComponentWrapperCall = isComponentWrapperCall;
|
|
1266
|
+
exports.isComponentWrapperCallLoose = isComponentWrapperCallLoose;
|
|
1250
1267
|
exports.isCreateContext = isCreateContext;
|
|
1251
1268
|
exports.isCreateContextCall = isCreateContextCall;
|
|
1252
1269
|
exports.isCreateElement = isCreateElement;
|