eslint-plugin-react-hooks 4.0.6 → 4.1.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.
|
@@ -926,7 +926,7 @@ var ExhaustiveDeps = {
|
|
|
926
926
|
if (isEffect && node.async) {
|
|
927
927
|
reportProblem({
|
|
928
928
|
node: node,
|
|
929
|
-
message: "Effect callbacks are synchronous to prevent race conditions. " + "Put the async function inside:\n\n" + 'useEffect(() => {\n' + ' async function fetchData() {\n' + ' // You can await here\n' + ' const response = await MyAPI.getData(someId);\n' + ' // ...\n' + ' }\n' + ' fetchData();\n' + "}, [someId]); // Or [] if effect doesn't need props or state\n\n" + 'Learn more about data fetching with Hooks: https://
|
|
929
|
+
message: "Effect callbacks are synchronous to prevent race conditions. " + "Put the async function inside:\n\n" + 'useEffect(() => {\n' + ' async function fetchData() {\n' + ' // You can await here\n' + ' const response = await MyAPI.getData(someId);\n' + ' // ...\n' + ' }\n' + ' fetchData();\n' + "}, [someId]); // Or [] if effect doesn't need props or state\n\n" + 'Learn more about data fetching with Hooks: https://reactjs.org/link/hooks-data-fetching'
|
|
930
930
|
});
|
|
931
931
|
} // Get the current scope.
|
|
932
932
|
|
|
@@ -1204,6 +1204,10 @@ var ExhaustiveDeps = {
|
|
|
1204
1204
|
});
|
|
1205
1205
|
}
|
|
1206
1206
|
|
|
1207
|
+
if (dependencyNode.parent.type === 'TSTypeQuery') {
|
|
1208
|
+
continue;
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1207
1211
|
var def = reference.resolved.defs[0];
|
|
1208
1212
|
|
|
1209
1213
|
if (def == null) {
|
|
@@ -1504,38 +1508,44 @@ var ExhaustiveDeps = {
|
|
|
1504
1508
|
var problemCount = duplicateDependencies.size + missingDependencies.size + unnecessaryDependencies.size;
|
|
1505
1509
|
|
|
1506
1510
|
if (problemCount === 0) {
|
|
1507
|
-
// If nothing else to report, check if some
|
|
1508
|
-
//
|
|
1509
|
-
var
|
|
1511
|
+
// If nothing else to report, check if some dependencies would
|
|
1512
|
+
// invalidate on every render.
|
|
1513
|
+
var constructions = scanForConstructions({
|
|
1510
1514
|
declaredDependencies: declaredDependencies,
|
|
1511
1515
|
declaredDependenciesNode: declaredDependenciesNode,
|
|
1512
1516
|
componentScope: componentScope,
|
|
1513
1517
|
scope: scope
|
|
1514
1518
|
});
|
|
1515
|
-
|
|
1516
|
-
var
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
var suggest; // Only handle the simple case: arrow functions.
|
|
1519
|
+
constructions.forEach(function (_ref4) {
|
|
1520
|
+
var construction = _ref4.construction,
|
|
1521
|
+
isUsedOutsideOfHook = _ref4.isUsedOutsideOfHook,
|
|
1522
|
+
depType = _ref4.depType;
|
|
1523
|
+
var wrapperHook = depType === 'function' ? 'useCallback' : 'useMemo';
|
|
1524
|
+
var constructionType = depType === 'function' ? 'definition' : 'initialization';
|
|
1525
|
+
var defaultAdvice = "wrap the " + constructionType + " of '" + construction.name.name + "' in its own " + wrapperHook + "() Hook.";
|
|
1526
|
+
var advice = isUsedOutsideOfHook ? "To fix this, " + defaultAdvice : "Move it inside the " + reactiveHookName + " callback. Alternatively, " + defaultAdvice;
|
|
1527
|
+
var causation = depType === 'conditional' || depType === 'logical expression' ? 'could make' : 'makes';
|
|
1528
|
+
var message = "The '" + construction.name.name + "' " + depType + " " + causation + " the dependencies of " + (reactiveHookName + " Hook (at line " + declaredDependenciesNode.loc.start.line + ") ") + ("change on every render. " + advice);
|
|
1529
|
+
var suggest; // Only handle the simple case of variable assignments.
|
|
1527
1530
|
// Wrapping function declarations can mess up hoisting.
|
|
1528
1531
|
|
|
1529
|
-
if (
|
|
1532
|
+
if (isUsedOutsideOfHook && construction.type === 'Variable' && // Objects may be mutated ater construction, which would make this
|
|
1533
|
+
// fix unsafe. Functions _probably_ won't be mutated, so we'll
|
|
1534
|
+
// allow this fix for them.
|
|
1535
|
+
depType === 'function') {
|
|
1530
1536
|
suggest = [{
|
|
1531
|
-
desc: "Wrap the '" +
|
|
1537
|
+
desc: "Wrap the " + constructionType + " of '" + construction.name.name + "' in its own " + wrapperHook + "() Hook.",
|
|
1532
1538
|
fix: function (fixer) {
|
|
1539
|
+
var _ref5 = wrapperHook === 'useMemo' ? ["useMemo(() => { return ", '; })'] : ['useCallback(', ')'],
|
|
1540
|
+
before = _ref5[0],
|
|
1541
|
+
after = _ref5[1];
|
|
1542
|
+
|
|
1533
1543
|
return [// TODO: also add an import?
|
|
1534
|
-
fixer.insertTextBefore(
|
|
1544
|
+
fixer.insertTextBefore(construction.node.init, before), // TODO: ideally we'd gather deps here but it would require
|
|
1535
1545
|
// restructuring the rule code. This will cause a new lint
|
|
1536
1546
|
// error to appear immediately for useCallback. Note we're
|
|
1537
1547
|
// not adding [] because would that changes semantics.
|
|
1538
|
-
fixer.insertTextAfter(
|
|
1548
|
+
fixer.insertTextAfter(construction.node.init, after)];
|
|
1539
1549
|
}
|
|
1540
1550
|
}];
|
|
1541
1551
|
} // TODO: What if the function needs to change on every render anyway?
|
|
@@ -1544,7 +1554,7 @@ var ExhaustiveDeps = {
|
|
|
1544
1554
|
|
|
1545
1555
|
reportProblem({
|
|
1546
1556
|
// TODO: Why not report this at the dependency site?
|
|
1547
|
-
node:
|
|
1557
|
+
node: construction.node,
|
|
1548
1558
|
message: message,
|
|
1549
1559
|
suggest: suggest
|
|
1550
1560
|
});
|
|
@@ -1843,12 +1853,12 @@ var ExhaustiveDeps = {
|
|
|
1843
1853
|
}
|
|
1844
1854
|
}; // The meat of the logic.
|
|
1845
1855
|
|
|
1846
|
-
function collectRecommendations(
|
|
1847
|
-
var dependencies =
|
|
1848
|
-
declaredDependencies =
|
|
1849
|
-
stableDependencies =
|
|
1850
|
-
externalDependencies =
|
|
1851
|
-
isEffect =
|
|
1856
|
+
function collectRecommendations(_ref6) {
|
|
1857
|
+
var dependencies = _ref6.dependencies,
|
|
1858
|
+
declaredDependencies = _ref6.declaredDependencies,
|
|
1859
|
+
stableDependencies = _ref6.stableDependencies,
|
|
1860
|
+
externalDependencies = _ref6.externalDependencies,
|
|
1861
|
+
isEffect = _ref6.isEffect;
|
|
1852
1862
|
// Our primary data structure.
|
|
1853
1863
|
// It is a logical representation of property chains:
|
|
1854
1864
|
// `props` -> `props.foo` -> `props.foo.bar` -> `props.foo.bar.baz`
|
|
@@ -1884,8 +1894,8 @@ function collectRecommendations(_ref5) {
|
|
|
1884
1894
|
}); // Mark all satisfied nodes.
|
|
1885
1895
|
// Imagine checkmarks next to each declared dependency.
|
|
1886
1896
|
|
|
1887
|
-
declaredDependencies.forEach(function (
|
|
1888
|
-
var key =
|
|
1897
|
+
declaredDependencies.forEach(function (_ref7) {
|
|
1898
|
+
var key = _ref7.key;
|
|
1889
1899
|
var node = getOrCreateNodeByPath(depTree, key);
|
|
1890
1900
|
node.isSatisfiedRecursively = true;
|
|
1891
1901
|
});
|
|
@@ -2007,8 +2017,8 @@ function collectRecommendations(_ref5) {
|
|
|
2007
2017
|
var suggestedDependencies = [];
|
|
2008
2018
|
var unnecessaryDependencies = new Set();
|
|
2009
2019
|
var duplicateDependencies = new Set();
|
|
2010
|
-
declaredDependencies.forEach(function (
|
|
2011
|
-
var key =
|
|
2020
|
+
declaredDependencies.forEach(function (_ref8) {
|
|
2021
|
+
var key = _ref8.key;
|
|
2012
2022
|
|
|
2013
2023
|
// Does this declared dep satisfy a real need?
|
|
2014
2024
|
if (satisfyingDependencies.has(key)) {
|
|
@@ -2044,48 +2054,127 @@ function collectRecommendations(_ref5) {
|
|
|
2044
2054
|
duplicateDependencies: duplicateDependencies,
|
|
2045
2055
|
missingDependencies: missingDependencies
|
|
2046
2056
|
};
|
|
2047
|
-
} //
|
|
2057
|
+
} // If the node will result in constructing a referentially unique value, return
|
|
2058
|
+
// its human readable type name, else return null.
|
|
2059
|
+
|
|
2060
|
+
|
|
2061
|
+
function getConstructionExpressionType(node) {
|
|
2062
|
+
switch (node.type) {
|
|
2063
|
+
case 'ObjectExpression':
|
|
2064
|
+
return 'object';
|
|
2065
|
+
|
|
2066
|
+
case 'ArrayExpression':
|
|
2067
|
+
return 'array';
|
|
2068
|
+
|
|
2069
|
+
case 'ArrowFunctionExpression':
|
|
2070
|
+
case 'FunctionExpression':
|
|
2071
|
+
return 'function';
|
|
2072
|
+
|
|
2073
|
+
case 'ClassExpression':
|
|
2074
|
+
return 'class';
|
|
2075
|
+
|
|
2076
|
+
case 'ConditionalExpression':
|
|
2077
|
+
if (getConstructionExpressionType(node.consequent) != null || getConstructionExpressionType(node.alternate) != null) {
|
|
2078
|
+
return 'conditional';
|
|
2079
|
+
}
|
|
2080
|
+
|
|
2081
|
+
return null;
|
|
2082
|
+
|
|
2083
|
+
case 'LogicalExpression':
|
|
2084
|
+
if (getConstructionExpressionType(node.left) != null || getConstructionExpressionType(node.right) != null) {
|
|
2085
|
+
return 'logical expression';
|
|
2086
|
+
}
|
|
2087
|
+
|
|
2088
|
+
return null;
|
|
2089
|
+
|
|
2090
|
+
case 'JSXFragment':
|
|
2091
|
+
return 'JSX fragment';
|
|
2092
|
+
|
|
2093
|
+
case 'JSXElement':
|
|
2094
|
+
return 'JSX element';
|
|
2095
|
+
|
|
2096
|
+
case 'AssignmentExpression':
|
|
2097
|
+
if (getConstructionExpressionType(node.right) != null) {
|
|
2098
|
+
return 'assignment expression';
|
|
2099
|
+
}
|
|
2100
|
+
|
|
2101
|
+
return null;
|
|
2102
|
+
|
|
2103
|
+
case 'NewExpression':
|
|
2104
|
+
return 'object construction';
|
|
2105
|
+
|
|
2106
|
+
case 'Literal':
|
|
2107
|
+
if (node.value instanceof RegExp) {
|
|
2108
|
+
return 'regular expression';
|
|
2109
|
+
}
|
|
2110
|
+
|
|
2111
|
+
return null;
|
|
2112
|
+
|
|
2113
|
+
case 'TypeCastExpression':
|
|
2114
|
+
return getConstructionExpressionType(node.expression);
|
|
2115
|
+
|
|
2116
|
+
case 'TSAsExpression':
|
|
2117
|
+
return getConstructionExpressionType(node.expression);
|
|
2118
|
+
}
|
|
2119
|
+
|
|
2120
|
+
return null;
|
|
2121
|
+
} // Finds variables declared as dependencies
|
|
2048
2122
|
// that would invalidate on every render.
|
|
2049
2123
|
|
|
2050
2124
|
|
|
2051
|
-
function
|
|
2052
|
-
var declaredDependencies =
|
|
2053
|
-
declaredDependenciesNode =
|
|
2054
|
-
componentScope =
|
|
2055
|
-
scope =
|
|
2056
|
-
var
|
|
2057
|
-
var key =
|
|
2058
|
-
var
|
|
2125
|
+
function scanForConstructions(_ref9) {
|
|
2126
|
+
var declaredDependencies = _ref9.declaredDependencies,
|
|
2127
|
+
declaredDependenciesNode = _ref9.declaredDependenciesNode,
|
|
2128
|
+
componentScope = _ref9.componentScope,
|
|
2129
|
+
scope = _ref9.scope;
|
|
2130
|
+
var constructions = declaredDependencies.map(function (_ref10) {
|
|
2131
|
+
var key = _ref10.key;
|
|
2132
|
+
var ref = componentScope.variables.find(function (v) {
|
|
2133
|
+
return v.name === key;
|
|
2134
|
+
});
|
|
2059
2135
|
|
|
2060
|
-
if (
|
|
2136
|
+
if (ref == null) {
|
|
2061
2137
|
return null;
|
|
2062
2138
|
}
|
|
2063
2139
|
|
|
2064
|
-
var
|
|
2140
|
+
var node = ref.defs[0];
|
|
2065
2141
|
|
|
2066
|
-
if (
|
|
2142
|
+
if (node == null) {
|
|
2067
2143
|
return null;
|
|
2068
2144
|
} // const handleChange = function () {}
|
|
2069
2145
|
// const handleChange = () => {}
|
|
2146
|
+
// const foo = {}
|
|
2147
|
+
// const foo = []
|
|
2148
|
+
// etc.
|
|
2149
|
+
|
|
2070
2150
|
|
|
2151
|
+
if (node.type === 'Variable' && node.node.type === 'VariableDeclarator' && node.node.id.type === 'Identifier' && // Ensure this is not destructed assignment
|
|
2152
|
+
node.node.init != null) {
|
|
2153
|
+
var constantExpressionType = getConstructionExpressionType(node.node.init);
|
|
2071
2154
|
|
|
2072
|
-
|
|
2073
|
-
|
|
2155
|
+
if (constantExpressionType != null) {
|
|
2156
|
+
return [ref, constantExpressionType];
|
|
2157
|
+
}
|
|
2074
2158
|
} // function handleChange() {}
|
|
2075
2159
|
|
|
2076
2160
|
|
|
2077
|
-
if (
|
|
2078
|
-
return
|
|
2161
|
+
if (node.type === 'FunctionName' && node.node.type === 'FunctionDeclaration') {
|
|
2162
|
+
return [ref, 'function'];
|
|
2163
|
+
} // class Foo {}
|
|
2164
|
+
|
|
2165
|
+
|
|
2166
|
+
if (node.type === 'ClassName' && node.node.type === 'ClassDeclaration') {
|
|
2167
|
+
return [ref, 'class'];
|
|
2079
2168
|
}
|
|
2080
2169
|
|
|
2081
2170
|
return null;
|
|
2082
2171
|
}).filter(Boolean);
|
|
2083
2172
|
|
|
2084
|
-
function isUsedOutsideOfHook(
|
|
2173
|
+
function isUsedOutsideOfHook(ref) {
|
|
2085
2174
|
var foundWriteExpr = false;
|
|
2086
2175
|
|
|
2087
|
-
for (var i = 0; i <
|
|
2088
|
-
var reference =
|
|
2176
|
+
for (var i = 0; i < ref.references.length; i++) {
|
|
2177
|
+
var reference = ref.references[i];
|
|
2089
2178
|
|
|
2090
2179
|
if (reference.writeExpr) {
|
|
2091
2180
|
if (foundWriteExpr) {
|
|
@@ -2116,10 +2205,13 @@ function scanForDeclaredBareFunctions(_ref8) {
|
|
|
2116
2205
|
return false;
|
|
2117
2206
|
}
|
|
2118
2207
|
|
|
2119
|
-
return
|
|
2208
|
+
return constructions.map(function (_ref11) {
|
|
2209
|
+
var ref = _ref11[0],
|
|
2210
|
+
depType = _ref11[1];
|
|
2120
2211
|
return {
|
|
2121
|
-
|
|
2122
|
-
|
|
2212
|
+
construction: ref.defs[0],
|
|
2213
|
+
depType: depType,
|
|
2214
|
+
isUsedOutsideOfHook: isUsedOutsideOfHook(ref)
|
|
2123
2215
|
};
|
|
2124
2216
|
});
|
|
2125
2217
|
}
|
|
@@ -2136,7 +2228,7 @@ function getDependency(node) {
|
|
|
2136
2228
|
if ((node.parent.type === 'MemberExpression' || node.parent.type === 'OptionalMemberExpression') && node.parent.object === node && node.parent.property.name !== 'current' && !node.parent.computed && !(node.parent.parent != null && (node.parent.parent.type === 'CallExpression' || node.parent.parent.type === 'OptionalCallExpression') && node.parent.parent.callee === node.parent)) {
|
|
2137
2229
|
return getDependency(node.parent);
|
|
2138
2230
|
} else if ( // Note: we don't check OptionalMemberExpression because it can't be LHS.
|
|
2139
|
-
node.type === 'MemberExpression' && node.parent && node.parent.type === 'AssignmentExpression') {
|
|
2231
|
+
node.type === 'MemberExpression' && node.parent && node.parent.type === 'AssignmentExpression' && node.parent.left === node) {
|
|
2140
2232
|
return node.object;
|
|
2141
2233
|
} else {
|
|
2142
2234
|
return node;
|
|
@@ -6,52 +6,55 @@
|
|
|
6
6
|
* This source code is licensed under the MIT license found in the
|
|
7
7
|
* LICENSE file in the root directory of this source tree.
|
|
8
8
|
*/
|
|
9
|
-
'use strict';function
|
|
10
|
-
function
|
|
11
|
-
function
|
|
9
|
+
'use strict';function K(a){if("Identifier"===a.type)return/^use[A-Z0-9].*$/.test(a.name);if("MemberExpression"===a.type&&!a.computed&&K(a.property)){a=a.object;var b=/^[A-Z].*/;return"Identifier"===a.type&&b.test(a.name)}return!1}function ba(a){return"Identifier"===a.type?!/^[a-z]/.test(a.name):!1}function ca(a,b){return a.name===b||"MemberExpression"===a.type&&"React"===a.object.name&&a.property.name===b}function fa(a){return!!(a.parent&&a.parent.callee&&ca(a.parent.callee,"forwardRef"))}
|
|
10
|
+
function ha(a){return!!(a.parent&&a.parent.callee&&ca(a.parent.callee,"memo"))}function ia(a){for(;a;){var b=ja(a);if(b&&(ba(b)||K(b))||fa(a)||ha(a))return!0;a=a.parent}return!1}
|
|
11
|
+
function ja(a){if("FunctionDeclaration"===a.type||"FunctionExpression"===a.type&&a.id)return a.id;if("FunctionExpression"===a.type||"ArrowFunctionExpression"===a.type)return"VariableDeclarator"===a.parent.type&&a.parent.init===a?a.parent.id:"AssignmentExpression"===a.parent.type&&a.parent.right===a&&"="===a.parent.operator?a.parent.left:"Property"!==a.parent.type||a.parent.value!==a||a.parent.computed?"AssignmentPattern"!==a.parent.type||a.parent.right!==a||a.parent.computed?void 0:a.parent.left:
|
|
12
12
|
a.parent.key}
|
|
13
|
-
function
|
|
14
|
-
!0){var
|
|
15
|
-
k.forEach(function(a){e(
|
|
16
|
-
function
|
|
17
|
-
|
|
18
|
-
function
|
|
19
|
-
|
|
20
|
-
function oa(a){return"MemberExpression"!==a.type
|
|
21
|
-
function
|
|
22
|
-
function
|
|
23
|
-
function
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
1;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
'React Hook "'+a.getSource(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
k.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
for(var
|
|
39
|
-
null
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
b
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
13
|
+
function ka(a){function b(){return{isUsed:!1,isSatisfiedRecursively:!1,isSubtreeUsed:!1,children:new Map}}function e(a,c){c=c.split(".");var l=!0,e=!1,h=void 0;try{for(var d=c[Symbol.iterator](),k;!(l=(k=d.next()).done);l=!0){var f=k.value,x=a.children.get(f);x||(x=b(),a.children.set(f,x));a=x}}catch(J){e=!0,h=J}finally{try{l||null==d.return||d.return()}finally{if(e)throw h;}}return a}function f(a,b,c){b=b.split(".");var l=!0,e=!1,h=void 0;try{for(var d=b[Symbol.iterator](),k;!(l=(k=d.next()).done);l=
|
|
14
|
+
!0){var f=a.children.get(k.value);if(!f)break;c(f);a=f}}catch(J){e=!0,h=J}finally{try{l||null==d.return||d.return()}finally{if(e)throw h;}}}function h(a,b,c,e){a.children.forEach(function(a,l){var d=e(l);a.isSatisfiedRecursively?a.isSubtreeUsed&&c.add(d):a.isUsed?b.add(d):h(a,b,c,function(a){return d+"."+a})})}var y=a.dependencies,k=a.declaredDependencies,t=a.stableDependencies,u=a.externalDependencies,A=a.isEffect,r=b();y.forEach(function(a,b){e(r,b).isUsed=!0;f(r,b,function(a){a.isSubtreeUsed=!0})});
|
|
15
|
+
k.forEach(function(a){e(r,a.key).isSatisfiedRecursively=!0});t.forEach(function(a){e(r,a).isSatisfiedRecursively=!0});a=new Set;var d=new Set;h(r,a,d,function(a){return a});var c=[],B=new Set,v=new Set;k.forEach(function(a){a=a.key;d.has(a)?-1===c.indexOf(a)?c.push(a):v.add(a):!A||a.endsWith(".current")||u.has(a)?B.add(a):-1===c.indexOf(a)&&c.push(a)});a.forEach(function(a){c.push(a)});return{suggestedDependencies:c,unnecessaryDependencies:B,duplicateDependencies:v,missingDependencies:a}}
|
|
16
|
+
function O(a){switch(a.type){case "ObjectExpression":return"object";case "ArrayExpression":return"array";case "ArrowFunctionExpression":case "FunctionExpression":return"function";case "ClassExpression":return"class";case "ConditionalExpression":if(null!=O(a.consequent)||null!=O(a.alternate))return"conditional";break;case "LogicalExpression":if(null!=O(a.left)||null!=O(a.right))return"logical expression";break;case "JSXFragment":return"JSX fragment";case "JSXElement":return"JSX element";case "AssignmentExpression":if(null!=
|
|
17
|
+
O(a.right))return"assignment expression";break;case "NewExpression":return"object construction";case "Literal":if(a.value instanceof RegExp)return"regular expression";break;case "TypeCastExpression":return O(a.expression);case "TSAsExpression":return O(a.expression)}return null}
|
|
18
|
+
function ma(a){var b=a.declaredDependenciesNode,e=a.componentScope,f=a.scope;return a.declaredDependencies.map(function(a){var b=a.key;a=e.variables.find(function(a){return a.name===b});if(null==a)return null;var f=a.defs[0];if(null==f)return null;if("Variable"===f.type&&"VariableDeclarator"===f.node.type&&"Identifier"===f.node.id.type&&null!=f.node.init){var h=O(f.node.init);if(null!=h)return[a,h]}return"FunctionName"===f.type&&"FunctionDeclaration"===f.node.type?[a,"function"]:"ClassName"===f.type&&
|
|
19
|
+
"ClassDeclaration"===f.node.type?[a,"class"]:null}).filter(Boolean).map(function(a){var e=a[0];a=a[1];var h=e.defs[0];a:{for(var t=!1,u=0;u<e.references.length;u++){var A=e.references[u];if(A.writeExpr)if(t){e=!0;break a}else{t=!0;continue}for(var r=A.from;r!==f&&null!=r;)r=r.upper;if(r!==f&&!na(b,A.identifier)){e=!0;break a}}e=!1}return{construction:h,depType:a,isUsedOutsideOfHook:e}})}
|
|
20
|
+
function oa(a){return"MemberExpression"!==a.parent.type&&"OptionalMemberExpression"!==a.parent.type||a.parent.object!==a||"current"===a.parent.property.name||a.parent.computed||null!=a.parent.parent&&("CallExpression"===a.parent.parent.type||"OptionalCallExpression"===a.parent.parent.type)&&a.parent.parent.callee===a.parent?"MemberExpression"===a.type&&a.parent&&"AssignmentExpression"===a.parent.type&&a.parent.left===a?a.object:a:oa(a.parent)}
|
|
21
|
+
function X(a,b){if("Identifier"===a.type)return a=a.name,b&&b.set(a,!1),a;if("MemberExpression"!==a.type||a.computed){if("OptionalMemberExpression"!==a.type||a.computed)throw Error("Unsupported node type: "+a.type);var e=X(a.object,b),f=X(a.property,null);e=e+"."+f;b&&(a.optional?b.has(e)||b.set(e,!0):b.set(e,!1));return e}e=X(a.object,b);a=X(a.property,null);a=e+"."+a;b&&b.set(a,!1);return a}
|
|
22
|
+
function pa(a){return"MemberExpression"!==a.type||"Identifier"!==a.object.type||"React"!==a.object.name||"Identifier"!==a.property.type||a.computed?a:a.property}
|
|
23
|
+
function ra(a,b){var e=pa(a);if("Identifier"!==e.type)return-1;switch(e.name){case "useEffect":case "useLayoutEffect":case "useCallback":case "useMemo":return 0;case "useImperativeHandle":return 1;default:if(e===a&&b&&b.additionalHooks){try{var f=X(e,null)}catch(h){if(/Unsupported node type/.test(h.message))return 0;throw h;}return b.additionalHooks.test(f)?0:-1}return-1}}
|
|
24
|
+
function sa(a,b){for(var e=[a],f=null;e.length;){f=e.shift();if("Identifier"===f.type&&f.name===b.name&&f.range[0]===b.range[0]&&f.range[1]===b.range[1])return f;if(na(f,b)){a=0;for(var h=Object.entries(f);a<h.length;a++){var y=h[a],k=y[1];"parent"!==y[0]&&(ta(k)?(k.parent=f,e.push(k)):Array.isArray(k)&&k.forEach(function(a){ta(a)&&(a.parent=f,e.push(a))}))}}}return null}
|
|
25
|
+
function ua(a){for(var b="",e=0;e<a.length;e++)b+=a[e],0===e&&2===a.length?b+=" and ":e===a.length-2&&2<a.length?b+=", and ":e<a.length-1&&(b+=", ");return b}function ta(a){return"object"===typeof a&&null!==a&&!Array.isArray(a)&&"string"===typeof a.type}function na(a,b){return a.range[0]<=b.range[0]&&a.range[1]>=b.range[1]}exports.configs={recommended:{plugins:["react-hooks"],rules:{"react-hooks/rules-of-hooks":"error","react-hooks/exhaustive-deps":"warn"}}};
|
|
26
|
+
exports.rules={"rules-of-hooks":{meta:{type:"problem",docs:{description:"enforces the Rules of Hooks",category:"Possible Errors",recommended:!0,url:"https://reactjs.org/docs/hooks-rules.html"}},create:function(a){var b=[],e=[];return{onCodePathSegmentStart:function(a){return e.push(a)},onCodePathSegmentEnd:function(){return e.pop()},onCodePathStart:function(){return b.push(new Map)},onCodePathEnd:function(e,h){function f(a,b){var c=f.cache,d=c.get(a.id);b=new Set(b);if(b.has(a.id)){c=[].concat(b);
|
|
27
|
+
a=c.slice(c.indexOf(a.id)+1);c=!0;d=!1;var h=void 0;try{for(var l=a[Symbol.iterator](),g;!(c=(g=l.next()).done);c=!0)A.add(g.value)}catch(F){d=!0,h=F}finally{try{c||null==l.return||l.return()}finally{if(d)throw h;}}return 0}b.add(a.id);if(void 0!==d)return d;if(e.thrownSegments.includes(a))d=0;else if(0===a.prevSegments.length)d=1;else{d=0;l=!0;g=!1;var L=void 0;try{h=a.prevSegments[Symbol.iterator]();for(var M;!(l=(M=h.next()).done);l=!0)d+=f(M.value,b)}catch(F){g=!0,L=F}finally{try{l||null==h.return||
|
|
28
|
+
h.return()}finally{if(g)throw L;}}}a.reachable&&0===d?c.delete(a.id):c.set(a.id,d);return d}function k(a,b){var d=k.cache,c=d.get(a.id);b=new Set(b);if(b.has(a.id)){d=Array.from(b);a=d.slice(d.indexOf(a.id)+1);d=!0;c=!1;var f=void 0;try{for(var h=a[Symbol.iterator](),g;!(d=(g=h.next()).done);d=!0)A.add(g.value)}catch(F){c=!0,f=F}finally{try{d||null==h.return||h.return()}finally{if(c)throw f;}}return 0}b.add(a.id);if(void 0!==c)return c;if(e.thrownSegments.includes(a))c=0;else if(0===a.nextSegments.length)c=
|
|
29
|
+
1;else{c=0;h=!0;g=!1;var L=void 0;try{f=a.nextSegments[Symbol.iterator]();for(var M;!(h=(M=f.next()).done);h=!0)c+=k(M.value,b)}catch(F){g=!0,L=F}finally{try{h||null==f.return||f.return()}finally{if(g)throw L;}}}d.set(a.id,c);return c}function t(a){var b=t.cache,c=b.get(a.id);if(null===c)return Infinity;if(void 0!==c)return c;b.set(a.id,null);if(0===a.prevSegments.length)c=1;else{c=Infinity;var d=!0,e=!1,f=void 0;try{for(var g=a.prevSegments[Symbol.iterator](),L;!(d=(L=g.next()).done);d=!0){var M=
|
|
30
|
+
t(L.value);M<c&&(c=M)}}catch(F){e=!0,f=F}finally{try{d||null==g.return||g.return()}finally{if(e)throw f;}}c+=1}b.set(a.id,c);return c}var u=b.pop();if(0!==u.size){var A=new Set;f.cache=new Map;k.cache=new Map;t.cache=new Map;var r=k(e.initialSegment),d=ja(h),c=ia(h),B=d?ba(d)||K(d):fa(h)||ha(h),v=Infinity,l=!0,x=!1,I=void 0;try{for(var Q=e.finalSegments[Symbol.iterator](),p;!(l=(p=Q.next()).done);l=!0){var la=p.value;if(la.reachable){var z=t(la);z<v&&(v=z)}}}catch(E){x=!0,I=E}finally{try{l||null==
|
|
31
|
+
Q.return||Q.return()}finally{if(x)throw I;}}l=!0;x=!1;I=void 0;try{for(var n=u[Symbol.iterator](),U;!(l=(U=n.next()).done);l=!0){var J=U.value,C=J[0],w=J[1];if(C.reachable){var Z=0===C.nextSegments.length?v<=t(C):v<t(C),W=f(C)*k(C),P=A.has(C.id);u=!0;Q=!1;p=void 0;try{for(var G=w[Symbol.iterator](),N;!(u=(N=G.next()).done);u=!0){var m=N.value;P&&a.report({node:m,message:'React Hook "'+a.getSource(m)+'" may be executed more than once. Possibly because it is called in a loop. React Hooks must be called in the exact same order in every component render.'});
|
|
32
|
+
if(B){if(!P&&W!==r){var D='React Hook "'+a.getSource(m)+'" is called conditionally. React Hooks must be called in the exact same order in every component render.'+(Z?" Did you accidentally call a React Hook after an early return?":"");a.report({node:m,message:D})}}else if(h.parent&&("MethodDefinition"===h.parent.type||"ClassProperty"===h.parent.type)&&h.parent.value===h){var aa='React Hook "'+a.getSource(m)+'" cannot be called in a class component. React Hooks must be called in a React function component or a custom React Hook function.';
|
|
33
|
+
a.report({node:m,message:aa})}else if(d){var S='React Hook "'+a.getSource(m)+'" is called in function "'+(a.getSource(d)+'" that is neither a React function component nor a custom React Hook function. React component names must start with an uppercase letter.');a.report({node:m,message:S})}else if("Program"===h.type){var T='React Hook "'+a.getSource(m)+'" cannot be called at the top level. React Hooks must be called in a React function component or a custom React Hook function.';a.report({node:m,
|
|
34
|
+
message:T})}else if(c){var H='React Hook "'+a.getSource(m)+'" cannot be called inside a callback. React Hooks must be called in a React function component or a custom React Hook function.';a.report({node:m,message:H})}}}catch(E){Q=!0,p=E}finally{try{u||null==G.return||G.return()}finally{if(Q)throw p;}}}}}catch(E){x=!0,I=E}finally{try{l||null==n.return||n.return()}finally{if(x)throw I;}}}},CallExpression:function(a){if(K(a.callee)){var f=b[b.length-1],y=e[e.length-1],k=f.get(y);k||(k=[],f.set(y,k));
|
|
35
|
+
k.push(a.callee)}}}}},"exhaustive-deps":{meta:{type:"suggestion",docs:{description:"verifies the list of dependencies for Hooks like useEffect and similar",category:"Best Practices",recommended:!0,url:"https://github.com/facebook/react/issues/14920"},fixable:"code",schema:[{type:"object",additionalProperties:!1,enableDangerousAutofixThisMayCauseInfiniteLoops:!1,properties:{additionalHooks:{type:"string"},enableDangerousAutofixThisMayCauseInfiniteLoops:{type:"boolean"}}}]},create:function(a){function b(b){h&&
|
|
36
|
+
Array.isArray(b.suggest)&&0<b.suggest.length&&(b.fix=b.suggest[0].fix);a.report(b)}function e(a,b){return function(c){if(b.has(c))return b.get(c);var d=a(c);b.set(c,d);return d}}function f(d,c,f,h,l){function x(a){var g=!0,b=!1,c=void 0;try{for(var f=a.references[Symbol.iterator](),e;!(g=(e=f.next()).done);g=!0){var h=e.value;if(h.resolved&&y.has(h.resolved.scope)){var m=sa(d,h.identifier),k=oa(m),v=X(k,Z),p;if(p=l&&"Identifier"===k.type&&("MemberExpression"===k.parent.type||"OptionalMemberExpression"===
|
|
37
|
+
k.parent.type)&&!k.parent.computed&&"Identifier"===k.parent.property.type&&"current"===k.parent.property.name){for(var n=h.from,B=!1;n.block!==d;)"function"===n.type&&(B=null!=n.block.parent&&"ReturnStatement"===n.block.parent.type),n=n.upper;p=B}p&&C.set(v,{reference:h,dependencyNode:k});if("TSTypeQuery"!==k.parent.type){var q=h.resolved.defs[0];if(null!=q&&(null==q.node||q.node.init!==d.parent)&&"TypeParameter"!==q.type)if(w.has(v))w.get(v).references.push(h);else{var t=h.resolved,u=U(t)||J(t);
|
|
38
|
+
w.set(v,{isStable:u,references:[h]})}}}}}catch(ea){b=!0,c=ea}finally{try{g||null==f.return||f.return()}finally{if(b)throw c;}}g=!0;b=!1;c=void 0;try{for(var r=a.childScopes[Symbol.iterator](),I;!(g=(I=r.next()).done);g=!0)x(I.value)}catch(ea){b=!0,c=ea}finally{try{g||null==r.return||r.return()}finally{if(b)throw c;}}}function v(a){a=a.split(".");for(var g="",b=0;b<a.length;b++){if(0!==b){var c=a.slice(0,b+1).join(".");c=!0===Z.get(c);g+=c?"?.":"."}g+=a[b]}return g}function B(a,b,c,f){return 0===a.size?
|
|
39
|
+
null:(1<a.size?"":b+" ")+c+" "+(1<a.size?"dependencies":"dependency")+": "+ua(Array.from(a).sort().map(function(a){return"'"+v(a)+"'"}))+(". Either "+f+" "+(1<a.size?"them":"it")+" or remove the dependency array.")}l&&d.async&&b({node:d,message:"Effect callbacks are synchronous to prevent race conditions. Put the async function inside:\n\nuseEffect(() => {\n async function fetchData() {\n // You can await here\n const response = await MyAPI.getData(someId);\n // ...\n }\n fetchData();\n}, [someId]); // Or [] if effect doesn't need props or state\n\nLearn more about data fetching with Hooks: https://reactjs.org/link/hooks-data-fetching"});
|
|
40
|
+
for(var p=k.acquire(d),y=new Set,z=null,n=p.upper;n;){y.add(n);if("function"===n.type)break;n=n.upper}if(n){z=n;var U=e(function(a){if(!Array.isArray(a.defs))return!1;var b=a.defs[0];if(null==b||"VariableDeclarator"!==b.node.type)return!1;var g=b.node.init;if(null==g)return!1;for(;"TSAsExpression"===g.type;)g=g.expression;var c=b.node.parent;if(null==c&&(sa(z.block,b.node.id),c=b.node.parent,null==c))return!1;if("const"===c.kind&&"Literal"===g.type&&("string"===typeof g.value||"number"===typeof g.value||
|
|
41
|
+
null===g.value))return!0;if("CallExpression"!==g.type)return!1;g=g.callee;"MemberExpression"!==g.type||"React"!==g.object.name||null==g.property||g.computed||(g=g.property);if("Identifier"!==g.type)return!1;b=b.node.id;g=g.name;if("useRef"===g&&"Identifier"===b.type)return!0;if(("useState"===g||"useReducer"===g)&&"ArrayPattern"===b.type&&2===b.elements.length&&Array.isArray(a.identifiers)){if(b.elements[1]===a.identifiers[0]){if("useState"===g)for(a=a.references,g=0;g<a.length;g++)t.set(a[g].identifier,
|
|
42
|
+
b.elements[0]);return!0}if(b.elements[0]===a.identifiers[0]&&"useState"===g)for(a=a.references,b=0;b<a.length;b++)u.add(a[b].identifier)}return!1},A),J=e(function(a){if(!Array.isArray(a.defs))return!1;a=a.defs[0];if(null==a||null==a.node||null==a.node.id)return!1;var b=a.node,g=z.childScopes;a=null;var c;for(c=0;c<g.length;c++){var f=g[c],d=f.block;if("FunctionDeclaration"===b.type&&d===b||"VariableDeclarator"===b.type&&d.parent===b){a=f;break}}if(null==a)return!1;for(c=0;c<a.through.length;c++)if(b=
|
|
43
|
+
a.through[c],null!=b.resolved&&y.has(b.resolved.scope)&&!U(b.resolved))return!1;return!0},r),C=new Map,w=new Map,Z=new Map;x(p);C.forEach(function(a,c){var g=a.dependencyNode;a=a.reference.resolved.references;for(var f=!1,d=0;d<a.length;d++){var e=a[d].identifier.parent;if(null!=e&&"MemberExpression"===e.type&&!e.computed&&"Identifier"===e.property.type&&"current"===e.property.name&&"AssignmentExpression"===e.parent.type&&e.parent.left===e){f=!0;break}}f||b({node:g.parent.property,message:"The ref value '"+
|
|
44
|
+
c+".current' will likely have changed by the time this effect cleanup function runs. If this ref points to a node rendered by React, copy '"+(c+".current' to a variable inside the effect, and use that variable in the cleanup function.")})});var W=new Set,P=new Set;w.forEach(function(c,d){var g=c.references;c.isStable&&P.add(d);g.forEach(function(c){c.writeExpr&&(c=c.writeExpr,W.has(d)||(W.add(d),b({node:c,message:"Assignments to the '"+d+"' variable from inside React Hook "+(a.getSource(f)+" will be lost after each render. To preserve the value over time, store it in a useRef Hook and keep the mutable value in the '.current' property. Otherwise, you can move this variable directly inside ")+
|
|
45
|
+
(a.getSource(f)+".")})))})});if(!(0<W.size))if(c){var G=[],N=new Set;"ArrayExpression"!==c.type?b({node:c,message:"React Hook "+a.getSource(f)+" was passed a dependency list that is not an array literal. This means we can't statically verify whether you've passed the correct dependencies."}):c.elements.forEach(function(c){if(null!==c)if("SpreadElement"===c.type)b({node:c,message:"React Hook "+a.getSource(f)+" has a spread element in its dependency array. This means we can't statically verify whether you've passed the correct dependencies."});
|
|
46
|
+
else{try{var g=X(c,null)}catch(qa){if(/Unsupported node type/.test(qa.message)){"Literal"===c.type?w.has(c.value)?b({node:c,message:"The "+c.raw+" literal is not a valid dependency because it never changes. Did you mean to include "+(c.value+" in the array instead?")}):b({node:c,message:"The "+c.raw+" literal is not a valid dependency because it never changes. You can safely remove it."}):b({node:c,message:"React Hook "+a.getSource(f)+" has a complex expression in the dependency array. Extract it to a separate variable so it can be statically checked."});
|
|
47
|
+
return}throw qa;}for(var d=c;"MemberExpression"===d.type||"OptionalMemberExpression"===d.type;)d=d.object;var e=!z.through.some(function(a){return a.identifier===d});G.push({key:g,node:c});e||N.add(g)}});var m=ka({dependencies:w,declaredDependencies:G,stableDependencies:P,externalDependencies:N,isEffect:l});n=m.unnecessaryDependencies;var D=m.missingDependencies,aa=m.duplicateDependencies,S=m.suggestedDependencies;if(0===aa.size+D.size+n.size)ma({declaredDependencies:G,declaredDependenciesNode:c,
|
|
48
|
+
componentScope:z,scope:p}).forEach(function(a){var g=a.construction,d=a.isUsedOutsideOfHook;a=a.depType;var f="function"===a?"useCallback":"useMemo",e="function"===a?"definition":"initialization",l="wrap the "+e+" of '"+g.name.name+"' in its own "+f+"() Hook.";l="The '"+g.name.name+"' "+a+" "+("conditional"===a||"logical expression"===a?"could make":"makes")+" the dependencies of "+(h+" Hook (at line "+c.loc.start.line+") change on every render. ")+(d?"To fix this, "+l:"Move it inside the "+h+" callback. Alternatively, "+
|
|
49
|
+
l);var k;d&&"Variable"===g.type&&"function"===a&&(k=[{desc:"Wrap the "+e+" of '"+g.name.name+"' in its own "+f+"() Hook.",fix:function(a){var b="useMemo"===f?["useMemo(() => { return ","; })"]:["useCallback(",")"],c=b[1];return[a.insertTextBefore(g.node.init,b[0]),a.insertTextAfter(g.node.init,c)]}}]);b({node:g.node,message:l,suggest:k})});else{!l&&0<D.size&&(S=ka({dependencies:w,declaredDependencies:[],stableDependencies:P,externalDependencies:N,isEffect:l}).suggestedDependencies);(function(){if(0===
|
|
50
|
+
G.length)return!0;var a=G.map(function(a){return a.key}),b=a.slice().sort();return a.join(",")===b.join(",")})()&&S.sort();m="";if(0<n.size){var T=null;Array.from(n.keys()).forEach(function(a){null===T&&a.endsWith(".current")&&(T=a)});if(null!==T)m=" Mutable values like '"+T+"' aren't valid dependencies because mutating them doesn't re-render the component.";else if(0<N.size){var H=Array.from(N)[0];p.set.has(H)||(m=" Outer scope values like '"+H+"' aren't valid dependencies because mutating them doesn't re-render the component.")}}if(!m&&
|
|
51
|
+
D.has("props")){p=w.get("props");if(null==p)return;p=p.references;if(!Array.isArray(p))return;H=!0;for(var E=0;E<p.length;E++){var R=sa(z.block,p[E].identifier);if(!R){H=!1;break}R=R.parent;if(null==R){H=!1;break}if("MemberExpression"!==R.type&&"OptionalMemberExpression"!==R.type){H=!1;break}}H&&(m=" However, 'props' will change when *any* prop changes, so the preferred fix is to destructure the 'props' object outside of the "+(h+" call and refer to those specific props inside ")+(a.getSource(f)+
|
|
52
|
+
"."))}if(!m&&0<D.size){var Y=null;D.forEach(function(a){if(!Y){var b=z.set.get(a),c=w.get(a);if(c.references[0].resolved===b&&(b=b.defs[0],null!=b&&null!=b.name&&"Parameter"===b.type)){b=!1;for(var d,g=0;g<c.references.length;g++)if(d=c.references[g].identifier,null!=d&&null!=d.parent&&("CallExpression"===d.parent.type||"OptionalCallExpression"===d.parent.type)&&d.parent.callee===d){b=!0;break}b&&(Y=a)}}});null!==Y&&(m=" If '"+Y+"' changes too often, find the parent component that defines it and wrap that definition in useCallback.")}if(!m&&
|
|
53
|
+
0<D.size){var q=null;D.forEach(function(a){if(null===q)for(var b=w.get(a).references,c,d,g=0;g<b.length;g++){c=b[g].identifier;for(d=c.parent;null!=d&&d!==z.block;){if("CallExpression"===d.type){var f=t.get(d.callee);if(null!=f){f.name===a?q={missingDep:a,setter:d.callee.name,form:"updater"}:u.has(c)?q={missingDep:a,setter:d.callee.name,form:"reducer"}:(c=b[g].resolved,null!=c&&(c=c.defs[0],null!=c&&"Parameter"===c.type&&(q={missingDep:a,setter:d.callee.name,form:"inlineReducer"})));break}}d=d.parent}if(null!==
|
|
54
|
+
q)break}});if(null!==q)switch(q.form){case "reducer":m=" You can also replace multiple useState variables with useReducer if '"+(q.setter+"' needs the current value of '")+(q.missingDep+"'.");break;case "inlineReducer":m=" If '"+q.setter+"' needs the current value of '"+(q.missingDep+"', you can also switch to useReducer instead of useState and read '")+(q.missingDep+"' in the reducer.");break;case "updater":m=" You can also do a functional update '"+q.setter+"("+q.missingDep.substring(0,1)+" => ...)' if you only need '"+
|
|
55
|
+
q.missingDep+"' in the '"+(q.setter+"' call.");break;default:throw Error("Unknown case.");}}b({node:c,message:"React Hook "+a.getSource(f)+" has "+(B(D,"a","missing","include")||B(n,"an","unnecessary","exclude")||B(aa,"a","duplicate","omit"))+m,suggest:[{desc:"Update the dependencies array to be: ["+S.map(v).join(", ")+"]",fix:function(a){return a.replaceText(c,"["+S.map(v).join(", ")+"]")}}]})}}else{var V=null;w.forEach(function(a,b){V||a.references.forEach(function(a){if(!V&&t.has(a.identifier)){for(a=
|
|
56
|
+
a.from;"function"!==a.type;)a=a.upper;a.block===d&&(V=b)}})});if(V){var da=ka({dependencies:w,declaredDependencies:[],stableDependencies:P,externalDependencies:new Set,isEffect:!0}).suggestedDependencies;b({node:f,message:"React Hook "+h+" contains a call to '"+V+"'. Without a list of dependencies, this can lead to an infinite chain of updates. To fix this, pass ["+da.join(", ")+("] as a second argument to the "+h+" Hook."),suggest:[{desc:"Add dependencies array: ["+da.join(", ")+"]",fix:function(a){return a.insertTextAfter(d,
|
|
57
|
+
", ["+da.join(", ")+"]")}}]})}}}}var h=a.options&&a.options[0]&&a.options[0].enableDangerousAutofixThisMayCauseInfiniteLoops||!1,y={additionalHooks:a.options&&a.options[0]&&a.options[0].additionalHooks?new RegExp(a.options[0].additionalHooks):void 0,enableDangerousAutofixThisMayCauseInfiniteLoops:h},k=a.getSourceCode().scopeManager,t=new WeakMap,u=new WeakSet,A=new WeakMap,r=new WeakMap;return{CallExpression:function(d){var c=ra(d.callee,y);if(-1!==c){var e=d.arguments[c],h=d.callee,l=pa(h).name,
|
|
58
|
+
k=d.arguments[c+1];d=/Effect($|[^a-z])/g.test(l);if(k||d){switch(e.type){case "FunctionExpression":case "ArrowFunctionExpression":f(e,k,h,l,d);return;case "Identifier":if(!k||k.elements&&k.elements.some(function(a){return a&&"Identifier"===a.type&&a.name===e.name}))return;c=a.getScope().set.get(e.name);if(null==c||null==c.defs)return;c=c.defs[0];if(!c||!c.node)break;if("Variable"!==c.type&&"FunctionName"!==c.type)break;switch(c.node.type){case "FunctionDeclaration":f(c.node,k,h,l,d);return;case "VariableDeclarator":if(c=
|
|
59
|
+
c.node.init)switch(c.type){case "ArrowFunctionExpression":case "FunctionExpression":f(c,k,h,l,d);return}}break;default:b({node:h,message:"React Hook "+l+" received a function whose dependencies are unknown. Pass an inline function instead."});return}b({node:h,message:"React Hook "+l+" has a missing dependency: '"+e.name+"'. Either include it or remove the dependency array.",suggest:[{desc:"Update the dependencies array to be: ["+e.name+"]",fix:function(a){return a.replaceText(k,"["+e.name+"]")}}]})}else"useMemo"!==
|
|
60
|
+
l&&"useCallback"!==l||b({node:h,message:"React Hook "+l+" does nothing when called with only one argument. Did you forget to pass an array of dependencies?"})}}}}}};
|