@eslint-react/core 1.47.5-next.0 → 1.48.2-beta.0
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 +42 -59
- package/dist/index.d.ts +42 -59
- package/dist/index.js +99 -136
- package/dist/index.mjs +100 -131
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var AST9 = require('@eslint-react/ast');
|
|
4
4
|
var eff = require('@eslint-react/eff');
|
|
5
5
|
var kit = require('@eslint-react/kit');
|
|
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 AST9__namespace = /*#__PURE__*/_interopNamespace(AST9);
|
|
33
33
|
var VAR3__namespace = /*#__PURE__*/_interopNamespace(VAR3);
|
|
34
34
|
var birecord__default = /*#__PURE__*/_interopDefault(birecord);
|
|
35
35
|
|
|
@@ -427,6 +427,10 @@ var $ZodBoolean = /* @__PURE__ */ $constructor("$ZodBoolean", (inst, def) => {
|
|
|
427
427
|
return payload;
|
|
428
428
|
};
|
|
429
429
|
});
|
|
430
|
+
var $ZodUnknown = /* @__PURE__ */ $constructor("$ZodUnknown", (inst, def) => {
|
|
431
|
+
$ZodType.init(inst, def);
|
|
432
|
+
inst._zod.parse = (payload) => payload;
|
|
433
|
+
});
|
|
430
434
|
function handleArrayResult(result, final, index) {
|
|
431
435
|
if (result.issues.length) {
|
|
432
436
|
final.issues.push(...prefixIssues(index, result.issues));
|
|
@@ -688,6 +692,12 @@ function _boolean(Class, params) {
|
|
|
688
692
|
...normalizeParams(params)
|
|
689
693
|
});
|
|
690
694
|
}
|
|
695
|
+
function _unknown(Class, params) {
|
|
696
|
+
return new Class({
|
|
697
|
+
type: "unknown",
|
|
698
|
+
...normalizeParams(params)
|
|
699
|
+
});
|
|
700
|
+
}
|
|
691
701
|
|
|
692
702
|
// ../../node_modules/.pnpm/@zod+mini@4.0.0-beta.0/node_modules/@zod/mini/dist/esm/parse.js
|
|
693
703
|
var parse2 = /* @__PURE__ */ _parse.bind({ Error: $ZodError });
|
|
@@ -737,6 +747,13 @@ var ZodMiniBoolean = /* @__PURE__ */ $constructor("ZodMiniBoolean", (inst, def)
|
|
|
737
747
|
function boolean2(params) {
|
|
738
748
|
return _boolean(ZodMiniBoolean, params);
|
|
739
749
|
}
|
|
750
|
+
var ZodMiniUnknown = /* @__PURE__ */ $constructor("ZodMiniUnknown", (inst, def) => {
|
|
751
|
+
$ZodUnknown.init(inst, def);
|
|
752
|
+
ZodMiniType.init(inst, def);
|
|
753
|
+
});
|
|
754
|
+
function unknown(params) {
|
|
755
|
+
return _unknown(ZodMiniUnknown, params);
|
|
756
|
+
}
|
|
740
757
|
var ZodMiniArray = /* @__PURE__ */ $constructor("ZodMiniArray", (inst, def) => {
|
|
741
758
|
$ZodArray.init(inst, def);
|
|
742
759
|
ZodMiniType.init(inst, def);
|
|
@@ -854,7 +871,7 @@ var CustomHooksSchema = object({
|
|
|
854
871
|
useSyncExternalStore: optional(array(string2())),
|
|
855
872
|
useTransition: optional(array(string2()))
|
|
856
873
|
});
|
|
857
|
-
|
|
874
|
+
object({
|
|
858
875
|
/**
|
|
859
876
|
* The source where React is imported from.
|
|
860
877
|
* @description This allows to specify a custom import location for React when not using the official distribution.
|
|
@@ -882,13 +899,14 @@ var ESLintReactSettingsSchema = object({
|
|
|
882
899
|
*/
|
|
883
900
|
polymorphicPropName: optional(string2()),
|
|
884
901
|
/**
|
|
902
|
+
* @default `true`
|
|
885
903
|
* @internal
|
|
886
904
|
*/
|
|
887
905
|
strict: optional(boolean2()),
|
|
888
906
|
/**
|
|
889
907
|
* Check both the shape and the import to determine if an API is from React.
|
|
890
|
-
* @description This can prevent false positives when using a irrelevant third-party library that has similar APIs to React.
|
|
891
908
|
* @default `true`
|
|
909
|
+
* @internal
|
|
892
910
|
*/
|
|
893
911
|
skipImportCheck: optional(boolean2()),
|
|
894
912
|
/**
|
|
@@ -913,14 +931,11 @@ var ESLintReactSettingsSchema = object({
|
|
|
913
931
|
});
|
|
914
932
|
optional(
|
|
915
933
|
object({
|
|
916
|
-
"react-x": optional(
|
|
917
|
-
/** @deprecated Use `react-x` instead */
|
|
918
|
-
reactOptions: optional(ESLintReactSettingsSchema)
|
|
934
|
+
"react-x": optional(unknown())
|
|
919
935
|
}),
|
|
920
936
|
{}
|
|
921
937
|
);
|
|
922
938
|
var DEFAULT_ESLINT_REACT_SETTINGS = {
|
|
923
|
-
...parse2(ESLintReactSettingsSchema, {}),
|
|
924
939
|
importSource: "react"};
|
|
925
940
|
function getInstanceId(node, prev) {
|
|
926
941
|
switch (true) {
|
|
@@ -954,90 +969,44 @@ function isInitializedFromReact(name, importSource, initialScope) {
|
|
|
954
969
|
}
|
|
955
970
|
const args = getRequireExpressionArguments(init);
|
|
956
971
|
const arg0 = args?.[0];
|
|
957
|
-
if (arg0 == null || !
|
|
972
|
+
if (arg0 == null || !AST9__namespace.isLiteral(arg0, "string")) {
|
|
958
973
|
return false;
|
|
959
974
|
}
|
|
960
975
|
return arg0.value === importSource || arg0.value.startsWith(`${importSource}/`);
|
|
961
976
|
}
|
|
962
977
|
return parent?.type === types.AST_NODE_TYPES.ImportDeclaration && parent.source.value === importSource;
|
|
963
978
|
}
|
|
964
|
-
|
|
965
|
-
// src/utils/is-from-react.ts
|
|
966
|
-
var defaultImportSource = shared.DEFAULT_ESLINT_REACT_SETTINGS.importSource;
|
|
967
|
-
function isFromReactLoose(node, name) {
|
|
968
|
-
switch (node?.type) {
|
|
969
|
-
case types.AST_NODE_TYPES.Identifier:
|
|
970
|
-
return node.name === name;
|
|
971
|
-
case types.AST_NODE_TYPES.MemberExpression:
|
|
972
|
-
return node.object.type === types.AST_NODE_TYPES.Identifier && node.property.type === types.AST_NODE_TYPES.Identifier && node.property.name === name;
|
|
973
|
-
default:
|
|
974
|
-
return false;
|
|
975
|
-
}
|
|
976
|
-
}
|
|
977
|
-
function isFromReactStrict(node, name, importSource, initialScope) {
|
|
978
|
-
switch (node?.type) {
|
|
979
|
-
case types.AST_NODE_TYPES.Identifier:
|
|
980
|
-
return node.name === name && isInitializedFromReact(name, importSource, initialScope);
|
|
981
|
-
case types.AST_NODE_TYPES.MemberExpression:
|
|
982
|
-
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);
|
|
983
|
-
default:
|
|
984
|
-
return false;
|
|
985
|
-
}
|
|
986
|
-
}
|
|
987
|
-
function isFromReact(name) {
|
|
988
|
-
return eff.dual(2, (context, node) => {
|
|
989
|
-
if (node == null) return false;
|
|
990
|
-
const { importSource = defaultImportSource, skipImportCheck = true } = shared.unsafeDecodeSettings(context.settings);
|
|
991
|
-
if (skipImportCheck) return isFromReactLoose(node, name);
|
|
992
|
-
return isFromReactStrict(node, name, importSource, context.sourceCode.getScope(node));
|
|
993
|
-
});
|
|
994
|
-
}
|
|
995
|
-
function isFromReactObject(objectName, propertyName) {
|
|
996
|
-
return eff.dual(2, (context, node) => {
|
|
997
|
-
if (node?.type !== types.AST_NODE_TYPES.MemberExpression) return false;
|
|
998
|
-
const { importSource = defaultImportSource, skipImportCheck = true } = shared.unsafeDecodeSettings(context.settings);
|
|
999
|
-
const { object: object2, property } = node;
|
|
1000
|
-
if (skipImportCheck) return isFromReactLoose(object2, objectName) && isFromReactLoose(property, propertyName);
|
|
1001
|
-
return isFromReactStrict(
|
|
1002
|
-
object2,
|
|
1003
|
-
objectName,
|
|
1004
|
-
importSource,
|
|
1005
|
-
context.sourceCode.getScope(object2)
|
|
1006
|
-
) && isFromReactLoose(property, propertyName);
|
|
1007
|
-
});
|
|
1008
|
-
}
|
|
1009
|
-
function isCallFromReact(name) {
|
|
1010
|
-
return eff.dual(2, (context, node) => {
|
|
1011
|
-
if (node.type !== types.AST_NODE_TYPES.CallExpression) return false;
|
|
1012
|
-
return isFromReact(name)(context, node.callee);
|
|
1013
|
-
});
|
|
1014
|
-
}
|
|
1015
|
-
function isCallFromReactObject(objectName, propertyName) {
|
|
1016
|
-
return eff.dual(2, (context, node) => {
|
|
1017
|
-
if (node.type !== types.AST_NODE_TYPES.CallExpression) return false;
|
|
1018
|
-
return isFromReactObject(objectName, propertyName)(context, node.callee);
|
|
1019
|
-
});
|
|
1020
|
-
}
|
|
1021
979
|
function isInstanceIdEqual(context, a, b) {
|
|
1022
|
-
return
|
|
980
|
+
return AST9__namespace.isNodeEqual(a, b) || VAR3__namespace.isNodeValueEqual(a, b, [
|
|
1023
981
|
context.sourceCode.getScope(a),
|
|
1024
982
|
context.sourceCode.getScope(b)
|
|
1025
983
|
]);
|
|
1026
984
|
}
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
985
|
+
function isReactAPI(api) {
|
|
986
|
+
const func = (context, node) => {
|
|
987
|
+
if (node == null) return false;
|
|
988
|
+
const getText = (n) => context.sourceCode.getText(n);
|
|
989
|
+
const name = AST9__namespace.toString(node, getText);
|
|
990
|
+
if (name === api) return true;
|
|
991
|
+
if (name.substring(name.indexOf(".") + 1) === api) return true;
|
|
992
|
+
return false;
|
|
993
|
+
};
|
|
994
|
+
return eff.dual(2, func);
|
|
1031
995
|
}
|
|
1032
|
-
function isReactAPICall(
|
|
1033
|
-
|
|
996
|
+
function isReactAPICall(api) {
|
|
997
|
+
const func = (context, node) => {
|
|
998
|
+
if (node == null) return false;
|
|
999
|
+
if (node.type !== types.AST_NODE_TYPES.CallExpression) return false;
|
|
1000
|
+
return isReactAPI(api)(context, node.callee);
|
|
1001
|
+
};
|
|
1002
|
+
return eff.dual(2, func);
|
|
1034
1003
|
}
|
|
1035
1004
|
var isCaptureOwnerStack = isReactAPI("captureOwnerStack");
|
|
1036
|
-
var isChildrenCount = isReactAPI("Children
|
|
1037
|
-
var isChildrenForEach = isReactAPI("Children
|
|
1038
|
-
var isChildrenMap = isReactAPI("Children
|
|
1039
|
-
var isChildrenOnly = isReactAPI("Children
|
|
1040
|
-
var isChildrenToArray = isReactAPI("Children
|
|
1005
|
+
var isChildrenCount = isReactAPI("Children.count");
|
|
1006
|
+
var isChildrenForEach = isReactAPI("Children.forEach");
|
|
1007
|
+
var isChildrenMap = isReactAPI("Children.map");
|
|
1008
|
+
var isChildrenOnly = isReactAPI("Children.only");
|
|
1009
|
+
var isChildrenToArray = isReactAPI("Children.toArray");
|
|
1041
1010
|
var isCloneElement = isReactAPI("cloneElement");
|
|
1042
1011
|
var isCreateContext = isReactAPI("createContext");
|
|
1043
1012
|
var isCreateElement = isReactAPI("createElement");
|
|
@@ -1046,11 +1015,11 @@ var isForwardRef = isReactAPI("forwardRef");
|
|
|
1046
1015
|
var isMemo = isReactAPI("memo");
|
|
1047
1016
|
var isLazy = isReactAPI("lazy");
|
|
1048
1017
|
var isCaptureOwnerStackCall = isReactAPICall("captureOwnerStack");
|
|
1049
|
-
var isChildrenCountCall = isReactAPICall("Children
|
|
1050
|
-
var isChildrenForEachCall = isReactAPICall("Children
|
|
1051
|
-
var isChildrenMapCall = isReactAPICall("Children
|
|
1052
|
-
var isChildrenOnlyCall = isReactAPICall("Children
|
|
1053
|
-
var isChildrenToArrayCall = isReactAPICall("Children
|
|
1018
|
+
var isChildrenCountCall = isReactAPICall("Children.count");
|
|
1019
|
+
var isChildrenForEachCall = isReactAPICall("Children.forEach");
|
|
1020
|
+
var isChildrenMapCall = isReactAPICall("Children.map");
|
|
1021
|
+
var isChildrenOnlyCall = isReactAPICall("Children.only");
|
|
1022
|
+
var isChildrenToArrayCall = isReactAPICall("Children.toArray");
|
|
1054
1023
|
var isCloneElementCall = isReactAPICall("cloneElement");
|
|
1055
1024
|
var isCreateContextCall = isReactAPICall("createContext");
|
|
1056
1025
|
var isCreateElementCall = isReactAPICall("createElement");
|
|
@@ -1067,7 +1036,7 @@ function isReactHookName(name) {
|
|
|
1067
1036
|
// src/hook/hook-is.ts
|
|
1068
1037
|
function isReactHook(node) {
|
|
1069
1038
|
if (node == null) return false;
|
|
1070
|
-
const id =
|
|
1039
|
+
const id = AST9__namespace.getFunctionIdentifier(node);
|
|
1071
1040
|
return id?.name != null && isReactHookName(id.name);
|
|
1072
1041
|
}
|
|
1073
1042
|
function isReactHookCall(node) {
|
|
@@ -1088,7 +1057,7 @@ function isReactHookCallWithName(context, node) {
|
|
|
1088
1057
|
const {
|
|
1089
1058
|
importSource = DEFAULT_ESLINT_REACT_SETTINGS.importSource,
|
|
1090
1059
|
skipImportCheck = true
|
|
1091
|
-
} = shared.
|
|
1060
|
+
} = shared.coerceSettings(context.settings);
|
|
1092
1061
|
const initialScope = context.sourceCode.getScope(node);
|
|
1093
1062
|
return (name) => {
|
|
1094
1063
|
switch (true) {
|
|
@@ -1118,7 +1087,7 @@ function isReactHookCallWithNameAlias(context, name, alias = []) {
|
|
|
1118
1087
|
const {
|
|
1119
1088
|
importSource = DEFAULT_ESLINT_REACT_SETTINGS.importSource,
|
|
1120
1089
|
skipImportCheck = true
|
|
1121
|
-
} = shared.
|
|
1090
|
+
} = shared.coerceSettings(context.settings);
|
|
1122
1091
|
return (node) => {
|
|
1123
1092
|
const initialScope = context.sourceCode.getScope(node);
|
|
1124
1093
|
switch (true) {
|
|
@@ -1170,7 +1139,7 @@ function useHookCollector() {
|
|
|
1170
1139
|
const hooks = /* @__PURE__ */ new Map();
|
|
1171
1140
|
const functionEntries = [];
|
|
1172
1141
|
const onFunctionEnter = (node) => {
|
|
1173
|
-
const id =
|
|
1142
|
+
const id = AST9__namespace.getFunctionIdentifier(node);
|
|
1174
1143
|
const key = shared.getId();
|
|
1175
1144
|
const name = id?.name;
|
|
1176
1145
|
if (name != null && isReactHookName(name)) {
|
|
@@ -1224,9 +1193,9 @@ function isFunctionOfUseEffectSetup(node) {
|
|
|
1224
1193
|
}
|
|
1225
1194
|
function isFunctionOfUseEffectCleanup(node) {
|
|
1226
1195
|
if (node == null) return false;
|
|
1227
|
-
const pReturn =
|
|
1228
|
-
const pFaunction =
|
|
1229
|
-
const pFunctionOfReturn =
|
|
1196
|
+
const pReturn = AST9__namespace.findParentNode(node, AST9__namespace.is(types.AST_NODE_TYPES.ReturnStatement));
|
|
1197
|
+
const pFaunction = AST9__namespace.findParentNode(node, AST9__namespace.isFunction);
|
|
1198
|
+
const pFunctionOfReturn = AST9__namespace.findParentNode(pReturn, AST9__namespace.isFunction);
|
|
1230
1199
|
if (pFaunction !== pFunctionOfReturn) return false;
|
|
1231
1200
|
return isFunctionOfUseEffectSetup(pFaunction);
|
|
1232
1201
|
}
|
|
@@ -1343,7 +1312,7 @@ function isJsxText(node) {
|
|
|
1343
1312
|
}
|
|
1344
1313
|
function isJsxLike(code, node, hint = DEFAULT_JSX_DETECTION_HINT) {
|
|
1345
1314
|
if (node == null) return false;
|
|
1346
|
-
if (
|
|
1315
|
+
if (AST9__namespace.isJSX(node)) return true;
|
|
1347
1316
|
switch (node.type) {
|
|
1348
1317
|
case types.AST_NODE_TYPES.Literal: {
|
|
1349
1318
|
switch (typeof node.value) {
|
|
@@ -1417,7 +1386,7 @@ function isJsxLike(code, node, hint = DEFAULT_JSX_DETECTION_HINT) {
|
|
|
1417
1386
|
if (name === "undefined") {
|
|
1418
1387
|
return !(hint & JSXDetectionHint.SkipUndefined);
|
|
1419
1388
|
}
|
|
1420
|
-
if (
|
|
1389
|
+
if (AST9__namespace.isJSXTagNameExpression(node)) {
|
|
1421
1390
|
return true;
|
|
1422
1391
|
}
|
|
1423
1392
|
const variable = VAR3__namespace.findVariable(name, code.getScope(node));
|
|
@@ -1448,7 +1417,7 @@ function findParentAttribute(node, test = eff.constTrue) {
|
|
|
1448
1417
|
const guard = (node2) => {
|
|
1449
1418
|
return node2.type === types.AST_NODE_TYPES.JSXAttribute && test(node2);
|
|
1450
1419
|
};
|
|
1451
|
-
return
|
|
1420
|
+
return AST9__namespace.findParentNode(node, guard);
|
|
1452
1421
|
}
|
|
1453
1422
|
function isHostElement(context, node) {
|
|
1454
1423
|
return node.type === types.AST_NODE_TYPES.JSXElement && node.openingElement.name.type === types.AST_NODE_TYPES.JSXIdentifier && /^[a-z]/u.test(node.openingElement.name.name);
|
|
@@ -1520,58 +1489,58 @@ function isPureComponent(node) {
|
|
|
1520
1489
|
return false;
|
|
1521
1490
|
}
|
|
1522
1491
|
function isComponentDidCatch(node) {
|
|
1523
|
-
return
|
|
1492
|
+
return AST9__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentDidCatch";
|
|
1524
1493
|
}
|
|
1525
1494
|
function isComponentDidMount(node) {
|
|
1526
|
-
return
|
|
1495
|
+
return AST9__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentDidMount";
|
|
1527
1496
|
}
|
|
1528
1497
|
function isComponentDidUpdate(node) {
|
|
1529
|
-
return
|
|
1498
|
+
return AST9__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentDidUpdate";
|
|
1530
1499
|
}
|
|
1531
1500
|
function isComponentWillMount(node) {
|
|
1532
|
-
return
|
|
1501
|
+
return AST9__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentWillMount";
|
|
1533
1502
|
}
|
|
1534
1503
|
function isComponentWillReceiveProps(node) {
|
|
1535
|
-
return
|
|
1504
|
+
return AST9__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentWillReceiveProps";
|
|
1536
1505
|
}
|
|
1537
1506
|
function isComponentWillUnmount(node) {
|
|
1538
|
-
return
|
|
1507
|
+
return AST9__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentWillUnmount";
|
|
1539
1508
|
}
|
|
1540
1509
|
function isComponentWillUpdate(node) {
|
|
1541
|
-
return
|
|
1510
|
+
return AST9__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentWillUpdate";
|
|
1542
1511
|
}
|
|
1543
1512
|
function isGetChildContext(node) {
|
|
1544
|
-
return
|
|
1513
|
+
return AST9__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "getChildContext";
|
|
1545
1514
|
}
|
|
1546
1515
|
function isGetDefaultProps(node) {
|
|
1547
|
-
return
|
|
1516
|
+
return AST9__namespace.isMethodOrProperty(node) && node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "getDefaultProps";
|
|
1548
1517
|
}
|
|
1549
1518
|
function isGetInitialState(node) {
|
|
1550
|
-
return
|
|
1519
|
+
return AST9__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "getInitialState";
|
|
1551
1520
|
}
|
|
1552
1521
|
function isGetSnapshotBeforeUpdate(node) {
|
|
1553
|
-
return
|
|
1522
|
+
return AST9__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "getSnapshotBeforeUpdate";
|
|
1554
1523
|
}
|
|
1555
1524
|
function isShouldComponentUpdate(node) {
|
|
1556
|
-
return
|
|
1525
|
+
return AST9__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "shouldComponentUpdate";
|
|
1557
1526
|
}
|
|
1558
1527
|
function isUnsafeComponentWillMount(node) {
|
|
1559
|
-
return
|
|
1528
|
+
return AST9__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "UNSAFE_componentWillMount";
|
|
1560
1529
|
}
|
|
1561
1530
|
function isUnsafeComponentWillReceiveProps(node) {
|
|
1562
|
-
return
|
|
1531
|
+
return AST9__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "UNSAFE_componentWillReceiveProps";
|
|
1563
1532
|
}
|
|
1564
1533
|
function isUnsafeComponentWillUpdate(node) {
|
|
1565
|
-
return
|
|
1534
|
+
return AST9__namespace.isMethodOrProperty(node) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "UNSAFE_componentWillUpdate";
|
|
1566
1535
|
}
|
|
1567
1536
|
function isGetDerivedStateFromProps(node) {
|
|
1568
|
-
return
|
|
1537
|
+
return AST9__namespace.isMethodOrProperty(node) && node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromProps";
|
|
1569
1538
|
}
|
|
1570
1539
|
function isGetDerivedStateFromError(node) {
|
|
1571
|
-
return
|
|
1540
|
+
return AST9__namespace.isMethodOrProperty(node) && node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromError";
|
|
1572
1541
|
}
|
|
1573
1542
|
function isRenderLike(node) {
|
|
1574
|
-
return
|
|
1543
|
+
return AST9__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "render" && node.parent.parent.type === types.AST_NODE_TYPES.ClassDeclaration;
|
|
1575
1544
|
}
|
|
1576
1545
|
function isFunctionOfRender(node) {
|
|
1577
1546
|
if (!isRenderLike(node.parent)) {
|
|
@@ -1580,7 +1549,7 @@ function isFunctionOfRender(node) {
|
|
|
1580
1549
|
return isClassComponent(node.parent.parent.parent);
|
|
1581
1550
|
}
|
|
1582
1551
|
function isRenderMethodLike(node) {
|
|
1583
|
-
return
|
|
1552
|
+
return AST9__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name.startsWith("render") && node.parent.parent.type === types.AST_NODE_TYPES.ClassDeclaration;
|
|
1584
1553
|
}
|
|
1585
1554
|
|
|
1586
1555
|
// src/component/component-hierarchy.ts
|
|
@@ -1591,13 +1560,13 @@ function isChildrenOfCreateElement(context, node) {
|
|
|
1591
1560
|
return parent.arguments.slice(2).some((arg) => arg === node);
|
|
1592
1561
|
}
|
|
1593
1562
|
function isInsideRenderMethod(node) {
|
|
1594
|
-
return
|
|
1563
|
+
return AST9__namespace.findParentNode(node, (n) => isRenderLike(n) && isClassComponent(n.parent.parent)) != null;
|
|
1595
1564
|
}
|
|
1596
1565
|
function isFunctionOfComponentDidMount(node) {
|
|
1597
|
-
return
|
|
1566
|
+
return AST9__namespace.isFunction(node) && isComponentDidMount(node.parent) && node.parent.value === node;
|
|
1598
1567
|
}
|
|
1599
1568
|
function isFunctionOfComponentWillUnmount(node) {
|
|
1600
|
-
return
|
|
1569
|
+
return AST9__namespace.isFunction(node) && isComponentWillUnmount(node.parent) && node.parent.value === node;
|
|
1601
1570
|
}
|
|
1602
1571
|
function isFunctionOfRenderMethod(node) {
|
|
1603
1572
|
if (!isRenderMethodLike(node.parent)) {
|
|
@@ -1637,12 +1606,12 @@ function isValidComponentDefinition(context, node, hint) {
|
|
|
1637
1606
|
if (hint & ComponentDetectionHint.SkipClassProperty && isFunctionOfClassProperty(node.parent)) {
|
|
1638
1607
|
return false;
|
|
1639
1608
|
}
|
|
1640
|
-
if (hint & ComponentDetectionHint.SkipArrayMapArgument &&
|
|
1609
|
+
if (hint & ComponentDetectionHint.SkipArrayMapArgument && AST9__namespace.isArrayMapCall(node.parent)) {
|
|
1641
1610
|
return false;
|
|
1642
1611
|
}
|
|
1643
|
-
const significantParent =
|
|
1612
|
+
const significantParent = AST9__namespace.findParentNode(
|
|
1644
1613
|
node,
|
|
1645
|
-
|
|
1614
|
+
AST9__namespace.isOneOf([
|
|
1646
1615
|
types.AST_NODE_TYPES.JSXExpressionContainer,
|
|
1647
1616
|
types.AST_NODE_TYPES.ArrowFunctionExpression,
|
|
1648
1617
|
types.AST_NODE_TYPES.FunctionExpression,
|
|
@@ -1663,7 +1632,7 @@ function isComponentWrapperCallLoose(context, node) {
|
|
|
1663
1632
|
|
|
1664
1633
|
// src/component/component-id.ts
|
|
1665
1634
|
function getFunctionComponentId(context, node) {
|
|
1666
|
-
const functionId =
|
|
1635
|
+
const functionId = AST9__namespace.getFunctionIdentifier(node);
|
|
1667
1636
|
if (functionId != null) {
|
|
1668
1637
|
return functionId;
|
|
1669
1638
|
}
|
|
@@ -1690,10 +1659,10 @@ var ComponentFlag = {
|
|
|
1690
1659
|
// src/component/component-init-path.ts
|
|
1691
1660
|
function getComponentFlagFromInitPath(initPath) {
|
|
1692
1661
|
let flag = ComponentFlag.None;
|
|
1693
|
-
if (initPath != null &&
|
|
1662
|
+
if (initPath != null && AST9__namespace.hasCallInFunctionInitPath("memo", initPath)) {
|
|
1694
1663
|
flag |= ComponentFlag.Memo;
|
|
1695
1664
|
}
|
|
1696
|
-
if (initPath != null &&
|
|
1665
|
+
if (initPath != null && AST9__namespace.hasCallInFunctionInitPath("forwardRef", initPath)) {
|
|
1697
1666
|
flag |= ComponentFlag.ForwardRef;
|
|
1698
1667
|
}
|
|
1699
1668
|
return flag;
|
|
@@ -1733,7 +1702,7 @@ function useComponentCollector(context, options = {}) {
|
|
|
1733
1702
|
const entry = functionEntries.at(-1);
|
|
1734
1703
|
if (entry == null) return;
|
|
1735
1704
|
if (!entry.isComponent) return functionEntries.pop();
|
|
1736
|
-
const shouldDrop =
|
|
1705
|
+
const shouldDrop = AST9__namespace.getNestedReturnStatements(entry.node.body).slice().reverse().some((r) => {
|
|
1737
1706
|
return context.sourceCode.getScope(r).block === entry.node && r.argument != null && !isJsxLike(context.sourceCode, r.argument, hint);
|
|
1738
1707
|
});
|
|
1739
1708
|
if (shouldDrop) {
|
|
@@ -1760,7 +1729,7 @@ function useComponentCollector(context, options = {}) {
|
|
|
1760
1729
|
const { body } = entry.node;
|
|
1761
1730
|
const isComponent = hasNoneOrLooseComponentName(context, entry.node) && isJsxLike(context.sourceCode, body, hint) && isValidComponentDefinition(context, entry.node, hint);
|
|
1762
1731
|
if (!isComponent) return;
|
|
1763
|
-
const initPath =
|
|
1732
|
+
const initPath = AST9__namespace.getFunctionInitPath(entry.node);
|
|
1764
1733
|
const id = getFunctionComponentId(context, entry.node);
|
|
1765
1734
|
const name = getComponentNameFromId(id);
|
|
1766
1735
|
const key = shared.getId();
|
|
@@ -1801,7 +1770,7 @@ function useComponentCollector(context, options = {}) {
|
|
|
1801
1770
|
const isComponent = hasNoneOrLooseComponentName(context, entry.node) && isJsxLike(context.sourceCode, node.argument, hint) && isValidComponentDefinition(context, entry.node, hint);
|
|
1802
1771
|
if (!isComponent) return;
|
|
1803
1772
|
entry.isComponent = true;
|
|
1804
|
-
const initPath =
|
|
1773
|
+
const initPath = AST9__namespace.getFunctionInitPath(entry.node);
|
|
1805
1774
|
const id = getFunctionComponentId(context, entry.node);
|
|
1806
1775
|
const name = getComponentNameFromId(id);
|
|
1807
1776
|
components.set(entry.key, {
|
|
@@ -1832,7 +1801,7 @@ function useComponentCollectorLegacy() {
|
|
|
1832
1801
|
if (!isClassComponent(node)) {
|
|
1833
1802
|
return;
|
|
1834
1803
|
}
|
|
1835
|
-
const id =
|
|
1804
|
+
const id = AST9__namespace.getClassIdentifier(node);
|
|
1836
1805
|
const key = shared.getId();
|
|
1837
1806
|
const flag = isPureComponent(node) ? ComponentFlag.PureComponent : ComponentFlag.None;
|
|
1838
1807
|
components.set(
|
|
@@ -1865,7 +1834,7 @@ var ComponentPhaseRelevance = birecord__default.default({
|
|
|
1865
1834
|
var isInversePhase = eff.dual(2, (a, b) => ComponentPhaseRelevance.get(a) === b);
|
|
1866
1835
|
function isRenderFunctionLoose(context, node) {
|
|
1867
1836
|
const { body, parent } = node;
|
|
1868
|
-
if (
|
|
1837
|
+
if (AST9__namespace.getFunctionIdentifier(node)?.name.startsWith("render")) {
|
|
1869
1838
|
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");
|
|
1870
1839
|
}
|
|
1871
1840
|
return isJsxLike(
|
|
@@ -1878,7 +1847,7 @@ function isRenderPropLoose(context, node) {
|
|
|
1878
1847
|
if (node.name.type !== types.AST_NODE_TYPES.JSXIdentifier) {
|
|
1879
1848
|
return false;
|
|
1880
1849
|
}
|
|
1881
|
-
return node.name.name.startsWith("render") && node.value?.type === types.AST_NODE_TYPES.JSXExpressionContainer &&
|
|
1850
|
+
return node.name.name.startsWith("render") && node.value?.type === types.AST_NODE_TYPES.JSXExpressionContainer && AST9__namespace.isFunction(node.value.expression) && isRenderFunctionLoose(context, node.value.expression);
|
|
1882
1851
|
}
|
|
1883
1852
|
function isDirectValueOfRenderPropertyLoose(node) {
|
|
1884
1853
|
const matching = (node2) => {
|
|
@@ -1890,7 +1859,7 @@ function isDeclaredInRenderPropLoose(node) {
|
|
|
1890
1859
|
if (isDirectValueOfRenderPropertyLoose(node)) {
|
|
1891
1860
|
return true;
|
|
1892
1861
|
}
|
|
1893
|
-
const parent =
|
|
1862
|
+
const parent = AST9__namespace.findParentNode(node, AST9__namespace.is(types.AST_NODE_TYPES.JSXExpressionContainer))?.parent;
|
|
1894
1863
|
if (parent?.type !== types.AST_NODE_TYPES.JSXAttribute) {
|
|
1895
1864
|
return false;
|
|
1896
1865
|
}
|
|
@@ -1898,11 +1867,11 @@ function isDeclaredInRenderPropLoose(node) {
|
|
|
1898
1867
|
}
|
|
1899
1868
|
function isThisSetState(node) {
|
|
1900
1869
|
const { callee } = node;
|
|
1901
|
-
return callee.type === types.AST_NODE_TYPES.MemberExpression &&
|
|
1870
|
+
return callee.type === types.AST_NODE_TYPES.MemberExpression && AST9__namespace.isThisExpression(callee.object) && callee.property.type === types.AST_NODE_TYPES.Identifier && callee.property.name === "setState";
|
|
1902
1871
|
}
|
|
1903
1872
|
function isAssignmentToThisState(node) {
|
|
1904
1873
|
const { left } = node;
|
|
1905
|
-
return left.type === types.AST_NODE_TYPES.MemberExpression &&
|
|
1874
|
+
return left.type === types.AST_NODE_TYPES.MemberExpression && AST9__namespace.isThisExpression(left.object) && AST9__namespace.getPropertyName(left.property) === "state";
|
|
1906
1875
|
}
|
|
1907
1876
|
|
|
1908
1877
|
exports.ComponentDetectionHint = ComponentDetectionHint;
|
|
@@ -1925,8 +1894,6 @@ exports.hasAttribute = hasAttribute;
|
|
|
1925
1894
|
exports.hasEveryAttribute = hasEveryAttribute;
|
|
1926
1895
|
exports.hasNoneOrLooseComponentName = hasNoneOrLooseComponentName;
|
|
1927
1896
|
exports.isAssignmentToThisState = isAssignmentToThisState;
|
|
1928
|
-
exports.isCallFromReact = isCallFromReact;
|
|
1929
|
-
exports.isCallFromReactObject = isCallFromReactObject;
|
|
1930
1897
|
exports.isCaptureOwnerStack = isCaptureOwnerStack;
|
|
1931
1898
|
exports.isCaptureOwnerStackCall = isCaptureOwnerStackCall;
|
|
1932
1899
|
exports.isChildrenCount = isChildrenCount;
|
|
@@ -1965,10 +1932,6 @@ exports.isDirectValueOfRenderPropertyLoose = isDirectValueOfRenderPropertyLoose;
|
|
|
1965
1932
|
exports.isForwardRef = isForwardRef;
|
|
1966
1933
|
exports.isForwardRefCall = isForwardRefCall;
|
|
1967
1934
|
exports.isFragmentElement = isFragmentElement;
|
|
1968
|
-
exports.isFromReact = isFromReact;
|
|
1969
|
-
exports.isFromReactLoose = isFromReactLoose;
|
|
1970
|
-
exports.isFromReactObject = isFromReactObject;
|
|
1971
|
-
exports.isFromReactStrict = isFromReactStrict;
|
|
1972
1935
|
exports.isFunctionOfComponentDidMount = isFunctionOfComponentDidMount;
|
|
1973
1936
|
exports.isFunctionOfComponentWillUnmount = isFunctionOfComponentWillUnmount;
|
|
1974
1937
|
exports.isFunctionOfRender = isFunctionOfRender;
|