@remotion/eslint-config-flat 4.0.272 → 4.0.273

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.
@@ -92590,7 +92590,7 @@ var require_rule_tester = __commonJS((exports, module) => {
92590
92590
  var { Linter, SourceCodeFixer, interpolate } = require_linter2();
92591
92591
  var CodePath = require_code_path();
92592
92592
  var ajv = require_ajv2()({ strictDefaults: true });
92593
- var espreePath = __require.resolve("espree");
92593
+ var espreePath = __require.resolve("/Users/jonathanburger/remotion/node_modules/.pnpm/espree@9.6.1/node_modules/espree/dist/espree.cjs");
92594
92594
  var parserSymbol = Symbol.for("eslint.RuleTester.parser");
92595
92595
  var { SourceCode } = require_source_code2();
92596
92596
  var testerDefaultConfig = { rules: {} };
@@ -132695,120 +132695,1525 @@ var require_eslint_plugin_react = __commonJS((exports, module) => {
132695
132695
  module.exports = plugin;
132696
132696
  });
132697
132697
 
132698
- // ../../node_modules/.pnpm/eslint-plugin-react-hooks@5.2.0-canary-de1eaa26-20250124_eslint@9.19.0/node_modules/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.production.js
132698
+ // ../../node_modules/.pnpm/eslint-plugin-react-hooks@5.2.0_eslint@9.19.0/node_modules/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.production.js
132699
132699
  var require_eslint_plugin_react_hooks_production = __commonJS((exports) => {
132700
- var assign = Object.assign;
132701
- function _unsupportedIterableToArray(o, minLen) {
132702
- if (o) {
132703
- if (typeof o === "string")
132704
- return _arrayLikeToArray(o, minLen);
132705
- var n = Object.prototype.toString.call(o).slice(8, -1);
132706
- n === "Object" && o.constructor && (n = o.constructor.name);
132707
- if (n === "Map" || n === "Set")
132708
- return Array.from(o);
132709
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
132710
- return _arrayLikeToArray(o, minLen);
132711
- }
132712
- }
132713
- function _arrayLikeToArray(arr, len) {
132714
- if (len == null || len > arr.length)
132715
- len = arr.length;
132716
- for (var i = 0, arr2 = Array(len);i < len; i++)
132717
- arr2[i] = arr[i];
132718
- return arr2;
132700
+ /*! *****************************************************************************
132701
+ Copyright (c) Microsoft Corporation.
132702
+
132703
+ Permission to use, copy, modify, and/or distribute this software for any
132704
+ purpose with or without fee is hereby granted.
132705
+
132706
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
132707
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
132708
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
132709
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
132710
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
132711
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
132712
+ PERFORMANCE OF THIS SOFTWARE.
132713
+ ***************************************************************************** */
132714
+ function __values(o) {
132715
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
132716
+ if (m)
132717
+ return m.call(o);
132718
+ if (o && typeof o.length === "number")
132719
+ return {
132720
+ next: function() {
132721
+ if (o && i >= o.length)
132722
+ o = undefined;
132723
+ return { value: o && o[i++], done: !o };
132724
+ }
132725
+ };
132726
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
132719
132727
  }
132720
- function _createForOfIteratorHelper(o, allowArrayLike) {
132721
- var it2;
132722
- if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
132723
- if (Array.isArray(o) || (it2 = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
132724
- it2 && (o = it2);
132725
- var i = 0;
132726
- allowArrayLike = function() {
132727
- };
132728
- return {
132729
- s: allowArrayLike,
132730
- n: function() {
132731
- return i >= o.length ? { done: true } : { done: false, value: o[i++] };
132732
- },
132733
- e: function(e) {
132734
- throw e;
132735
- },
132736
- f: allowArrayLike
132737
- };
132728
+ function __read(o, n) {
132729
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
132730
+ if (!m)
132731
+ return o;
132732
+ var i = m.call(o), r, ar = [], e;
132733
+ try {
132734
+ while ((n === undefined || n-- > 0) && !(r = i.next()).done)
132735
+ ar.push(r.value);
132736
+ } catch (error) {
132737
+ e = { error };
132738
+ } finally {
132739
+ try {
132740
+ if (r && !r.done && (m = i["return"]))
132741
+ m.call(i);
132742
+ } finally {
132743
+ if (e)
132744
+ throw e.error;
132738
132745
  }
132739
- throw new TypeError(`Invalid attempt to iterate non-iterable instance.
132740
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`);
132741
132746
  }
132742
- var normalCompletion = true, didErr = false, err;
132743
- return {
132744
- s: function() {
132745
- it2 = o[Symbol.iterator]();
132746
- },
132747
- n: function() {
132748
- var step = it2.next();
132749
- normalCompletion = step.done;
132750
- return step;
132751
- },
132752
- e: function(e) {
132753
- didErr = true;
132754
- err = e;
132755
- },
132756
- f: function() {
132757
- try {
132758
- normalCompletion || it2.return == null || it2.return();
132759
- } finally {
132760
- if (didErr)
132761
- throw err;
132747
+ return ar;
132748
+ }
132749
+ function __spreadArray(to, from, pack) {
132750
+ if (pack || arguments.length === 2)
132751
+ for (var i = 0, l = from.length, ar;i < l; i++) {
132752
+ if (ar || !(i in from)) {
132753
+ if (!ar)
132754
+ ar = Array.prototype.slice.call(from, 0, i);
132755
+ ar[i] = from[i];
132762
132756
  }
132763
132757
  }
132764
- };
132758
+ return to.concat(ar || from);
132759
+ }
132760
+ function isHookName(s) {
132761
+ return s === "use" || /^use[A-Z0-9]/.test(s);
132765
132762
  }
132766
132763
  function isHook(node) {
132767
- if (node.type === "Identifier")
132768
- return node = node.name, node === "use" || /^use[A-Z0-9]/.test(node);
132769
- if (node.type === "MemberExpression" && !node.computed && isHook(node.property)) {
132770
- node = node.object;
132764
+ if (node.type === "Identifier") {
132765
+ return isHookName(node.name);
132766
+ } else if (node.type === "MemberExpression" && !node.computed && isHook(node.property)) {
132767
+ var obj = node.object;
132771
132768
  var isPascalCaseNameSpace = /^[A-Z].*/;
132772
- return node.type === "Identifier" && isPascalCaseNameSpace.test(node.name);
132769
+ return obj.type === "Identifier" && isPascalCaseNameSpace.test(obj.name);
132770
+ } else {
132771
+ return false;
132773
132772
  }
132774
- return false;
132775
132773
  }
132776
132774
  function isComponentName(node) {
132777
132775
  return node.type === "Identifier" && /^[A-Z]/.test(node.name);
132778
132776
  }
132779
132777
  function isReactFunction(node, functionName) {
132780
- return node.name === functionName || node.type === "MemberExpression" && node.object.name === "React" && node.property.name === functionName;
132778
+ return "name" in node && node.name === functionName || node.type === "MemberExpression" && "name" in node.object && node.object.name === "React" && "name" in node.property && node.property.name === functionName;
132781
132779
  }
132782
132780
  function isForwardRefCallback(node) {
132783
- return !!(node.parent && node.parent.callee && isReactFunction(node.parent.callee, "forwardRef"));
132781
+ return !!(node.parent && ("callee" in node.parent) && node.parent.callee && isReactFunction(node.parent.callee, "forwardRef"));
132784
132782
  }
132785
132783
  function isMemoCallback(node) {
132786
- return !!(node.parent && node.parent.callee && isReactFunction(node.parent.callee, "memo"));
132784
+ return !!(node.parent && ("callee" in node.parent) && node.parent.callee && isReactFunction(node.parent.callee, "memo"));
132787
132785
  }
132788
132786
  function isInsideComponentOrHook(node) {
132789
- for (;node; ) {
132787
+ while (node) {
132790
132788
  var functionName = getFunctionName(node);
132791
- if (functionName && (isComponentName(functionName) || isHook(functionName)) || isForwardRefCallback(node) || isMemoCallback(node))
132789
+ if (functionName) {
132790
+ if (isComponentName(functionName) || isHook(functionName)) {
132791
+ return true;
132792
+ }
132793
+ }
132794
+ if (isForwardRefCallback(node) || isMemoCallback(node)) {
132792
132795
  return true;
132796
+ }
132793
132797
  node = node.parent;
132794
132798
  }
132795
132799
  return false;
132796
132800
  }
132797
132801
  function isInsideDoWhileLoop(node) {
132798
- for (;node; ) {
132799
- if (node.type === "DoWhileStatement")
132802
+ while (node) {
132803
+ if (node.type === "DoWhileStatement") {
132800
132804
  return true;
132805
+ }
132801
132806
  node = node.parent;
132802
132807
  }
132803
132808
  return false;
132804
132809
  }
132810
+ function isUseEffectEventIdentifier$1(node) {
132811
+ return false;
132812
+ }
132813
+ function isUseIdentifier(node) {
132814
+ return isReactFunction(node, "use");
132815
+ }
132816
+ var rule$1 = {
132817
+ meta: {
132818
+ type: "problem",
132819
+ docs: {
132820
+ description: "enforces the Rules of Hooks",
132821
+ recommended: true,
132822
+ url: "https://reactjs.org/docs/hooks-rules.html"
132823
+ }
132824
+ },
132825
+ create: function(context) {
132826
+ var lastEffect = null;
132827
+ var codePathReactHooksMapStack = [];
132828
+ var codePathSegmentStack = [];
132829
+ var useEffectEventFunctions = new WeakSet;
132830
+ function recordAllUseEffectEventFunctions(scope) {
132831
+ var e_1, _a, e_2, _b;
132832
+ try {
132833
+ for (var _c = __values(scope.references), _d = _c.next();!_d.done; _d = _c.next()) {
132834
+ var reference = _d.value;
132835
+ var parent = reference.identifier.parent;
132836
+ if ((parent === null || parent === undefined ? undefined : parent.type) === "VariableDeclarator" && parent.init && parent.init.type === "CallExpression" && parent.init.callee && isUseEffectEventIdentifier$1(parent.init.callee)) {
132837
+ if (reference.resolved === null) {
132838
+ throw new Error("Unexpected null reference.resolved");
132839
+ }
132840
+ try {
132841
+ for (var _e = (e_2 = undefined, __values(reference.resolved.references)), _f = _e.next();!_f.done; _f = _e.next()) {
132842
+ var ref = _f.value;
132843
+ if (ref !== reference) {
132844
+ useEffectEventFunctions.add(ref.identifier);
132845
+ }
132846
+ }
132847
+ } catch (e_2_1) {
132848
+ e_2 = { error: e_2_1 };
132849
+ } finally {
132850
+ try {
132851
+ if (_f && !_f.done && (_b = _e.return))
132852
+ _b.call(_e);
132853
+ } finally {
132854
+ if (e_2)
132855
+ throw e_2.error;
132856
+ }
132857
+ }
132858
+ }
132859
+ }
132860
+ } catch (e_1_1) {
132861
+ e_1 = { error: e_1_1 };
132862
+ } finally {
132863
+ try {
132864
+ if (_d && !_d.done && (_a = _c.return))
132865
+ _a.call(_c);
132866
+ } finally {
132867
+ if (e_1)
132868
+ throw e_1.error;
132869
+ }
132870
+ }
132871
+ }
132872
+ var getSourceCode = typeof context.getSourceCode === "function" ? function() {
132873
+ return context.getSourceCode();
132874
+ } : function() {
132875
+ return context.sourceCode;
132876
+ };
132877
+ var getScope = typeof context.getScope === "function" ? function() {
132878
+ return context.getScope();
132879
+ } : function(node) {
132880
+ return getSourceCode().getScope(node);
132881
+ };
132882
+ return {
132883
+ onCodePathSegmentStart: function(segment) {
132884
+ return codePathSegmentStack.push(segment);
132885
+ },
132886
+ onCodePathSegmentEnd: function() {
132887
+ return codePathSegmentStack.pop();
132888
+ },
132889
+ onCodePathStart: function() {
132890
+ return codePathReactHooksMapStack.push(new Map);
132891
+ },
132892
+ onCodePathEnd: function(codePath, codePathNode) {
132893
+ var e_3, _a, e_4, _b, e_5, _c;
132894
+ var reactHooksMap = codePathReactHooksMapStack.pop();
132895
+ if ((reactHooksMap === null || reactHooksMap === undefined ? undefined : reactHooksMap.size) === 0) {
132896
+ return;
132897
+ } else if (typeof reactHooksMap === "undefined") {
132898
+ throw new Error("Unexpected undefined reactHooksMap");
132899
+ }
132900
+ var cyclic = new Set;
132901
+ function countPathsFromStart(segment2, pathHistory) {
132902
+ var e_6, _a2, e_7, _b2;
132903
+ var cache = countPathsFromStart.cache;
132904
+ var paths = cache.get(segment2.id);
132905
+ var pathList = new Set(pathHistory);
132906
+ if (pathList.has(segment2.id)) {
132907
+ var pathArray = __spreadArray([], __read(pathList), false);
132908
+ var cyclicSegments = pathArray.slice(pathArray.indexOf(segment2.id) + 1);
132909
+ try {
132910
+ for (var cyclicSegments_1 = __values(cyclicSegments), cyclicSegments_1_1 = cyclicSegments_1.next();!cyclicSegments_1_1.done; cyclicSegments_1_1 = cyclicSegments_1.next()) {
132911
+ var cyclicSegment = cyclicSegments_1_1.value;
132912
+ cyclic.add(cyclicSegment);
132913
+ }
132914
+ } catch (e_6_1) {
132915
+ e_6 = { error: e_6_1 };
132916
+ } finally {
132917
+ try {
132918
+ if (cyclicSegments_1_1 && !cyclicSegments_1_1.done && (_a2 = cyclicSegments_1.return))
132919
+ _a2.call(cyclicSegments_1);
132920
+ } finally {
132921
+ if (e_6)
132922
+ throw e_6.error;
132923
+ }
132924
+ }
132925
+ return BigInt("0");
132926
+ }
132927
+ pathList.add(segment2.id);
132928
+ if (paths !== undefined) {
132929
+ return paths;
132930
+ }
132931
+ if (codePath.thrownSegments.includes(segment2)) {
132932
+ paths = BigInt("0");
132933
+ } else if (segment2.prevSegments.length === 0) {
132934
+ paths = BigInt("1");
132935
+ } else {
132936
+ paths = BigInt("0");
132937
+ try {
132938
+ for (var _c2 = __values(segment2.prevSegments), _d2 = _c2.next();!_d2.done; _d2 = _c2.next()) {
132939
+ var prevSegment = _d2.value;
132940
+ paths += countPathsFromStart(prevSegment, pathList);
132941
+ }
132942
+ } catch (e_7_1) {
132943
+ e_7 = { error: e_7_1 };
132944
+ } finally {
132945
+ try {
132946
+ if (_d2 && !_d2.done && (_b2 = _c2.return))
132947
+ _b2.call(_c2);
132948
+ } finally {
132949
+ if (e_7)
132950
+ throw e_7.error;
132951
+ }
132952
+ }
132953
+ }
132954
+ if (segment2.reachable && paths === BigInt("0")) {
132955
+ cache.delete(segment2.id);
132956
+ } else {
132957
+ cache.set(segment2.id, paths);
132958
+ }
132959
+ return paths;
132960
+ }
132961
+ function countPathsToEnd(segment2, pathHistory) {
132962
+ var e_8, _a2, e_9, _b2;
132963
+ var cache = countPathsToEnd.cache;
132964
+ var paths = cache.get(segment2.id);
132965
+ var pathList = new Set(pathHistory);
132966
+ if (pathList.has(segment2.id)) {
132967
+ var pathArray = Array.from(pathList);
132968
+ var cyclicSegments = pathArray.slice(pathArray.indexOf(segment2.id) + 1);
132969
+ try {
132970
+ for (var cyclicSegments_2 = __values(cyclicSegments), cyclicSegments_2_1 = cyclicSegments_2.next();!cyclicSegments_2_1.done; cyclicSegments_2_1 = cyclicSegments_2.next()) {
132971
+ var cyclicSegment = cyclicSegments_2_1.value;
132972
+ cyclic.add(cyclicSegment);
132973
+ }
132974
+ } catch (e_8_1) {
132975
+ e_8 = { error: e_8_1 };
132976
+ } finally {
132977
+ try {
132978
+ if (cyclicSegments_2_1 && !cyclicSegments_2_1.done && (_a2 = cyclicSegments_2.return))
132979
+ _a2.call(cyclicSegments_2);
132980
+ } finally {
132981
+ if (e_8)
132982
+ throw e_8.error;
132983
+ }
132984
+ }
132985
+ return BigInt("0");
132986
+ }
132987
+ pathList.add(segment2.id);
132988
+ if (paths !== undefined) {
132989
+ return paths;
132990
+ }
132991
+ if (codePath.thrownSegments.includes(segment2)) {
132992
+ paths = BigInt("0");
132993
+ } else if (segment2.nextSegments.length === 0) {
132994
+ paths = BigInt("1");
132995
+ } else {
132996
+ paths = BigInt("0");
132997
+ try {
132998
+ for (var _c2 = __values(segment2.nextSegments), _d2 = _c2.next();!_d2.done; _d2 = _c2.next()) {
132999
+ var nextSegment = _d2.value;
133000
+ paths += countPathsToEnd(nextSegment, pathList);
133001
+ }
133002
+ } catch (e_9_1) {
133003
+ e_9 = { error: e_9_1 };
133004
+ } finally {
133005
+ try {
133006
+ if (_d2 && !_d2.done && (_b2 = _c2.return))
133007
+ _b2.call(_c2);
133008
+ } finally {
133009
+ if (e_9)
133010
+ throw e_9.error;
133011
+ }
133012
+ }
133013
+ }
133014
+ cache.set(segment2.id, paths);
133015
+ return paths;
133016
+ }
133017
+ function shortestPathLengthToStart(segment2) {
133018
+ var e_10, _a2;
133019
+ var cache = shortestPathLengthToStart.cache;
133020
+ var length2 = cache.get(segment2.id);
133021
+ if (length2 === null) {
133022
+ return Infinity;
133023
+ }
133024
+ if (length2 !== undefined) {
133025
+ return length2;
133026
+ }
133027
+ cache.set(segment2.id, null);
133028
+ if (segment2.prevSegments.length === 0) {
133029
+ length2 = 1;
133030
+ } else {
133031
+ length2 = Infinity;
133032
+ try {
133033
+ for (var _b2 = __values(segment2.prevSegments), _c2 = _b2.next();!_c2.done; _c2 = _b2.next()) {
133034
+ var prevSegment = _c2.value;
133035
+ var prevLength = shortestPathLengthToStart(prevSegment);
133036
+ if (prevLength < length2) {
133037
+ length2 = prevLength;
133038
+ }
133039
+ }
133040
+ } catch (e_10_1) {
133041
+ e_10 = { error: e_10_1 };
133042
+ } finally {
133043
+ try {
133044
+ if (_c2 && !_c2.done && (_a2 = _b2.return))
133045
+ _a2.call(_b2);
133046
+ } finally {
133047
+ if (e_10)
133048
+ throw e_10.error;
133049
+ }
133050
+ }
133051
+ length2 += 1;
133052
+ }
133053
+ cache.set(segment2.id, length2);
133054
+ return length2;
133055
+ }
133056
+ countPathsFromStart.cache = new Map;
133057
+ countPathsToEnd.cache = new Map;
133058
+ shortestPathLengthToStart.cache = new Map;
133059
+ var allPathsFromStartToEnd = countPathsToEnd(codePath.initialSegment);
133060
+ var codePathFunctionName = getFunctionName(codePathNode);
133061
+ var isSomewhereInsideComponentOrHook = isInsideComponentOrHook(codePathNode);
133062
+ var isDirectlyInsideComponentOrHook = codePathFunctionName ? isComponentName(codePathFunctionName) || isHook(codePathFunctionName) : isForwardRefCallback(codePathNode) || isMemoCallback(codePathNode);
133063
+ var shortestFinalPathLength = Infinity;
133064
+ try {
133065
+ for (var _d = __values(codePath.finalSegments), _e = _d.next();!_e.done; _e = _d.next()) {
133066
+ var finalSegment = _e.value;
133067
+ if (!finalSegment.reachable) {
133068
+ continue;
133069
+ }
133070
+ var length = shortestPathLengthToStart(finalSegment);
133071
+ if (length < shortestFinalPathLength) {
133072
+ shortestFinalPathLength = length;
133073
+ }
133074
+ }
133075
+ } catch (e_3_1) {
133076
+ e_3 = { error: e_3_1 };
133077
+ } finally {
133078
+ try {
133079
+ if (_e && !_e.done && (_a = _d.return))
133080
+ _a.call(_d);
133081
+ } finally {
133082
+ if (e_3)
133083
+ throw e_3.error;
133084
+ }
133085
+ }
133086
+ try {
133087
+ for (var reactHooksMap_1 = __values(reactHooksMap), reactHooksMap_1_1 = reactHooksMap_1.next();!reactHooksMap_1_1.done; reactHooksMap_1_1 = reactHooksMap_1.next()) {
133088
+ var _f = __read(reactHooksMap_1_1.value, 2), segment = _f[0], reactHooks = _f[1];
133089
+ if (!segment.reachable) {
133090
+ continue;
133091
+ }
133092
+ var possiblyHasEarlyReturn = segment.nextSegments.length === 0 ? shortestFinalPathLength <= shortestPathLengthToStart(segment) : shortestFinalPathLength < shortestPathLengthToStart(segment);
133093
+ var pathsFromStartToEnd = countPathsFromStart(segment) * countPathsToEnd(segment);
133094
+ var cycled = cyclic.has(segment.id);
133095
+ try {
133096
+ for (var reactHooks_1 = (e_5 = undefined, __values(reactHooks)), reactHooks_1_1 = reactHooks_1.next();!reactHooks_1_1.done; reactHooks_1_1 = reactHooks_1.next()) {
133097
+ var hook = reactHooks_1_1.value;
133098
+ if ((cycled || isInsideDoWhileLoop(hook)) && !isUseIdentifier(hook)) {
133099
+ context.report({
133100
+ node: hook,
133101
+ message: 'React Hook "'.concat(getSourceCode().getText(hook), '" 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."
133102
+ });
133103
+ }
133104
+ if (isDirectlyInsideComponentOrHook) {
133105
+ var isAsyncFunction = codePathNode.async;
133106
+ if (isAsyncFunction) {
133107
+ context.report({
133108
+ node: hook,
133109
+ message: 'React Hook "'.concat(getSourceCode().getText(hook), '" cannot be ') + "called in an async function."
133110
+ });
133111
+ }
133112
+ if (!cycled && pathsFromStartToEnd !== allPathsFromStartToEnd && !isUseIdentifier(hook) && !isInsideDoWhileLoop(hook)) {
133113
+ var message = 'React Hook "'.concat(getSourceCode().getText(hook), '" is called ') + "conditionally. React Hooks must be called in the exact " + "same order in every component render." + (possiblyHasEarlyReturn ? " Did you accidentally call a React Hook after an" + " early return?" : "");
133114
+ context.report({ node: hook, message });
133115
+ }
133116
+ } else if (codePathNode.parent != null && (codePathNode.parent.type === "MethodDefinition" || codePathNode.parent.type === "ClassProperty" || codePathNode.parent.type === "PropertyDefinition") && codePathNode.parent.value === codePathNode) {
133117
+ var message = 'React Hook "'.concat(getSourceCode().getText(hook), '" cannot be called ') + "in a class component. React Hooks must be called in a " + "React function component or a custom React Hook function.";
133118
+ context.report({ node: hook, message });
133119
+ } else if (codePathFunctionName) {
133120
+ var message = 'React Hook "'.concat(getSourceCode().getText(hook), '" is called in ') + 'function "'.concat(getSourceCode().getText(codePathFunctionName), '" ') + "that is neither a React function component nor a custom " + "React Hook function." + " React component names must start with an uppercase letter." + ' React Hook names must start with the word "use".';
133121
+ context.report({ node: hook, message });
133122
+ } else if (codePathNode.type === "Program") {
133123
+ var message = 'React Hook "'.concat(getSourceCode().getText(hook), '" cannot be called ') + "at the top level. React Hooks must be called in a " + "React function component or a custom React Hook function.";
133124
+ context.report({ node: hook, message });
133125
+ } else {
133126
+ if (isSomewhereInsideComponentOrHook && !isUseIdentifier(hook)) {
133127
+ var message = 'React Hook "'.concat(getSourceCode().getText(hook), '" cannot be called ') + "inside a callback. React Hooks must be called in a " + "React function component or a custom React Hook function.";
133128
+ context.report({ node: hook, message });
133129
+ }
133130
+ }
133131
+ }
133132
+ } catch (e_5_1) {
133133
+ e_5 = { error: e_5_1 };
133134
+ } finally {
133135
+ try {
133136
+ if (reactHooks_1_1 && !reactHooks_1_1.done && (_c = reactHooks_1.return))
133137
+ _c.call(reactHooks_1);
133138
+ } finally {
133139
+ if (e_5)
133140
+ throw e_5.error;
133141
+ }
133142
+ }
133143
+ }
133144
+ } catch (e_4_1) {
133145
+ e_4 = { error: e_4_1 };
133146
+ } finally {
133147
+ try {
133148
+ if (reactHooksMap_1_1 && !reactHooksMap_1_1.done && (_b = reactHooksMap_1.return))
133149
+ _b.call(reactHooksMap_1);
133150
+ } finally {
133151
+ if (e_4)
133152
+ throw e_4.error;
133153
+ }
133154
+ }
133155
+ },
133156
+ CallExpression: function(node) {
133157
+ if (isHook(node.callee)) {
133158
+ var reactHooksMap = last(codePathReactHooksMapStack);
133159
+ var codePathSegment = last(codePathSegmentStack);
133160
+ var reactHooks = reactHooksMap.get(codePathSegment);
133161
+ if (!reactHooks) {
133162
+ reactHooks = [];
133163
+ reactHooksMap.set(codePathSegment, reactHooks);
133164
+ }
133165
+ reactHooks.push(node.callee);
133166
+ }
133167
+ if (node.callee.type === "Identifier" && (node.callee.name === "useEffect" || isUseEffectEventIdentifier$1()) && node.arguments.length > 0) {
133168
+ lastEffect = node;
133169
+ }
133170
+ },
133171
+ Identifier: function(node) {
133172
+ if (lastEffect == null && useEffectEventFunctions.has(node) && node.parent.type !== "CallExpression") {
133173
+ context.report({
133174
+ node,
133175
+ message: "`".concat(getSourceCode().getText(node), '` is a function created with React Hook "useEffectEvent", and can only be called from ') + "the same component. They cannot be assigned to variables or passed down."
133176
+ });
133177
+ }
133178
+ },
133179
+ "CallExpression:exit": function(node) {
133180
+ if (node === lastEffect) {
133181
+ lastEffect = null;
133182
+ }
133183
+ },
133184
+ FunctionDeclaration: function(node) {
133185
+ if (isInsideComponentOrHook(node)) {
133186
+ recordAllUseEffectEventFunctions(getScope(node));
133187
+ }
133188
+ },
133189
+ ArrowFunctionExpression: function(node) {
133190
+ if (isInsideComponentOrHook(node)) {
133191
+ recordAllUseEffectEventFunctions(getScope(node));
133192
+ }
133193
+ }
133194
+ };
133195
+ }
133196
+ };
132805
133197
  function getFunctionName(node) {
132806
- if (node.type === "FunctionDeclaration" || node.type === "FunctionExpression" && node.id)
133198
+ var _a, _b, _c, _d;
133199
+ if (node.type === "FunctionDeclaration" || node.type === "FunctionExpression" && node.id) {
132807
133200
  return node.id;
132808
- if (node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression")
132809
- return node.parent.type === "VariableDeclarator" && node.parent.init === node ? node.parent.id : node.parent.type === "AssignmentExpression" && node.parent.right === node && node.parent.operator === "=" ? node.parent.left : node.parent.type !== "Property" || node.parent.value !== node || node.parent.computed ? node.parent.type !== "AssignmentPattern" || node.parent.right !== node || node.parent.computed ? undefined : node.parent.left : node.parent.key;
133201
+ } else if (node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression") {
133202
+ if (((_a = node.parent) === null || _a === undefined ? undefined : _a.type) === "VariableDeclarator" && node.parent.init === node) {
133203
+ return node.parent.id;
133204
+ } else if (((_b = node.parent) === null || _b === undefined ? undefined : _b.type) === "AssignmentExpression" && node.parent.right === node && node.parent.operator === "=") {
133205
+ return node.parent.left;
133206
+ } else if (((_c = node.parent) === null || _c === undefined ? undefined : _c.type) === "Property" && node.parent.value === node && !node.parent.computed) {
133207
+ return node.parent.key;
133208
+ } else if (((_d = node.parent) === null || _d === undefined ? undefined : _d.type) === "AssignmentPattern" && node.parent.right === node && !node.parent.computed) {
133209
+ return node.parent.left;
133210
+ } else {
133211
+ return;
133212
+ }
133213
+ } else {
133214
+ return;
133215
+ }
133216
+ }
133217
+ function last(array) {
133218
+ return array[array.length - 1];
132810
133219
  }
132811
- function collectRecommendations(_ref6) {
133220
+ var rule2 = {
133221
+ meta: {
133222
+ type: "suggestion",
133223
+ docs: {
133224
+ description: "verifies the list of dependencies for Hooks like useEffect and similar",
133225
+ recommended: true,
133226
+ url: "https://github.com/facebook/react/issues/14920"
133227
+ },
133228
+ fixable: "code",
133229
+ hasSuggestions: true,
133230
+ schema: [
133231
+ {
133232
+ type: "object",
133233
+ additionalProperties: false,
133234
+ enableDangerousAutofixThisMayCauseInfiniteLoops: false,
133235
+ properties: {
133236
+ additionalHooks: {
133237
+ type: "string"
133238
+ },
133239
+ enableDangerousAutofixThisMayCauseInfiniteLoops: {
133240
+ type: "boolean"
133241
+ }
133242
+ }
133243
+ }
133244
+ ]
133245
+ },
133246
+ create: function(context) {
133247
+ var additionalHooks = context.options && context.options[0] && context.options[0].additionalHooks ? new RegExp(context.options[0].additionalHooks) : undefined;
133248
+ var enableDangerousAutofixThisMayCauseInfiniteLoops = context.options && context.options[0] && context.options[0].enableDangerousAutofixThisMayCauseInfiniteLoops || false;
133249
+ var options = {
133250
+ additionalHooks,
133251
+ enableDangerousAutofixThisMayCauseInfiniteLoops
133252
+ };
133253
+ function reportProblem(problem) {
133254
+ if (enableDangerousAutofixThisMayCauseInfiniteLoops) {
133255
+ if (Array.isArray(problem.suggest) && problem.suggest.length > 0 && problem.suggest[0]) {
133256
+ problem.fix = problem.suggest[0].fix;
133257
+ }
133258
+ }
133259
+ context.report(problem);
133260
+ }
133261
+ var getSourceCode = typeof context.getSourceCode === "function" ? function() {
133262
+ return context.getSourceCode();
133263
+ } : function() {
133264
+ return context.sourceCode;
133265
+ };
133266
+ var getScope = typeof context.getScope === "function" ? function() {
133267
+ return context.getScope();
133268
+ } : function(node) {
133269
+ return context.sourceCode.getScope(node);
133270
+ };
133271
+ var scopeManager = getSourceCode().scopeManager;
133272
+ var setStateCallSites = new WeakMap;
133273
+ var stateVariables = new WeakSet;
133274
+ var stableKnownValueCache = new WeakMap;
133275
+ var functionWithoutCapturedValueCache = new WeakMap;
133276
+ var useEffectEventVariables = new WeakSet;
133277
+ function memoizeWithWeakMap(fn, map) {
133278
+ return function(arg) {
133279
+ if (map.has(arg)) {
133280
+ return map.get(arg);
133281
+ }
133282
+ var result = fn(arg);
133283
+ map.set(arg, result);
133284
+ return result;
133285
+ };
133286
+ }
133287
+ function visitFunctionWithDependencies(node, declaredDependenciesNode, reactiveHook, reactiveHookName, isEffect) {
133288
+ var e_1, _a, e_2, _b, e_3, _c;
133289
+ if (isEffect && node.async) {
133290
+ reportProblem({
133291
+ node,
133292
+ message: "Effect callbacks are synchronous to prevent race conditions. " + `Put the async function inside:
133293
+
133294
+ ` + `useEffect(() => {
133295
+ ` + ` async function fetchData() {
133296
+ ` + ` // You can await here
133297
+ ` + ` const response = await MyAPI.getData(someId);
133298
+ ` + ` // ...
133299
+ ` + ` }
133300
+ ` + ` fetchData();
133301
+ ` + `}, [someId]); // Or [] if effect doesn't need props or state
133302
+
133303
+ ` + "Learn more about data fetching with Hooks: https://react.dev/link/hooks-data-fetching"
133304
+ });
133305
+ }
133306
+ var scope = scopeManager.acquire(node);
133307
+ if (!scope) {
133308
+ throw new Error("Unable to acquire scope for the current node. This is a bug in eslint-plugin-react-hooks, please file an issue.");
133309
+ }
133310
+ var pureScopes = new Set;
133311
+ var componentScope = null;
133312
+ {
133313
+ var currentScope = scope.upper;
133314
+ while (currentScope) {
133315
+ pureScopes.add(currentScope);
133316
+ if (currentScope.type === "function") {
133317
+ break;
133318
+ }
133319
+ currentScope = currentScope.upper;
133320
+ }
133321
+ if (!currentScope) {
133322
+ return;
133323
+ }
133324
+ componentScope = currentScope;
133325
+ }
133326
+ var isArray = Array.isArray;
133327
+ function isStableKnownHookValue(resolved2) {
133328
+ var e_4, _a2, e_5, _b2, e_6, _c2;
133329
+ if (!isArray(resolved2.defs)) {
133330
+ return false;
133331
+ }
133332
+ var def2 = resolved2.defs[0];
133333
+ if (def2 == null) {
133334
+ return false;
133335
+ }
133336
+ var defNode = def2.node;
133337
+ if (defNode.type !== "VariableDeclarator") {
133338
+ return false;
133339
+ }
133340
+ var init = defNode.init;
133341
+ if (init == null) {
133342
+ return false;
133343
+ }
133344
+ while (init.type === "TSAsExpression" || init.type === "AsExpression") {
133345
+ init = init.expression;
133346
+ }
133347
+ var declaration = defNode.parent;
133348
+ if (declaration == null && componentScope != null) {
133349
+ fastFindReferenceWithParent(componentScope.block, def2.node.id);
133350
+ declaration = def2.node.parent;
133351
+ if (declaration == null) {
133352
+ return false;
133353
+ }
133354
+ }
133355
+ if (declaration != null && "kind" in declaration && declaration.kind === "const" && init.type === "Literal" && (typeof init.value === "string" || typeof init.value === "number" || init.value === null)) {
133356
+ return true;
133357
+ }
133358
+ if (init.type !== "CallExpression") {
133359
+ return false;
133360
+ }
133361
+ var callee = init.callee;
133362
+ if (callee.type === "MemberExpression" && "name" in callee.object && callee.object.name === "React" && callee.property != null && !callee.computed) {
133363
+ callee = callee.property;
133364
+ }
133365
+ if (callee.type !== "Identifier") {
133366
+ return false;
133367
+ }
133368
+ var definitionNode = def2.node;
133369
+ var id2 = definitionNode.id;
133370
+ var name = callee.name;
133371
+ if (name === "useRef" && id2.type === "Identifier") {
133372
+ return true;
133373
+ } else if (isUseEffectEventIdentifier() && id2.type === "Identifier") {
133374
+ try {
133375
+ for (var _d2 = __values(resolved2.references), _e = _d2.next();!_e.done; _e = _d2.next()) {
133376
+ var ref2 = _e.value;
133377
+ if (ref2 !== id2) {
133378
+ useEffectEventVariables.add(ref2.identifier);
133379
+ }
133380
+ }
133381
+ } catch (e_4_1) {
133382
+ e_4 = { error: e_4_1 };
133383
+ } finally {
133384
+ try {
133385
+ if (_e && !_e.done && (_a2 = _d2.return))
133386
+ _a2.call(_d2);
133387
+ } finally {
133388
+ if (e_4)
133389
+ throw e_4.error;
133390
+ }
133391
+ }
133392
+ return true;
133393
+ } else if (name === "useState" || name === "useReducer" || name === "useActionState") {
133394
+ if (id2.type === "ArrayPattern" && id2.elements.length === 2 && isArray(resolved2.identifiers)) {
133395
+ if (id2.elements[1] === resolved2.identifiers[0]) {
133396
+ if (name === "useState") {
133397
+ var references2 = resolved2.references;
133398
+ var writeCount = 0;
133399
+ try {
133400
+ for (var references_2 = __values(references2), references_2_1 = references_2.next();!references_2_1.done; references_2_1 = references_2.next()) {
133401
+ var reference2 = references_2_1.value;
133402
+ if (reference2.isWrite()) {
133403
+ writeCount++;
133404
+ }
133405
+ if (writeCount > 1) {
133406
+ return false;
133407
+ }
133408
+ setStateCallSites.set(reference2.identifier, id2.elements[0]);
133409
+ }
133410
+ } catch (e_5_1) {
133411
+ e_5 = { error: e_5_1 };
133412
+ } finally {
133413
+ try {
133414
+ if (references_2_1 && !references_2_1.done && (_b2 = references_2.return))
133415
+ _b2.call(references_2);
133416
+ } finally {
133417
+ if (e_5)
133418
+ throw e_5.error;
133419
+ }
133420
+ }
133421
+ }
133422
+ return true;
133423
+ } else if (id2.elements[0] === resolved2.identifiers[0]) {
133424
+ if (name === "useState") {
133425
+ var references2 = resolved2.references;
133426
+ try {
133427
+ for (var references_3 = __values(references2), references_3_1 = references_3.next();!references_3_1.done; references_3_1 = references_3.next()) {
133428
+ var reference2 = references_3_1.value;
133429
+ stateVariables.add(reference2.identifier);
133430
+ }
133431
+ } catch (e_6_1) {
133432
+ e_6 = { error: e_6_1 };
133433
+ } finally {
133434
+ try {
133435
+ if (references_3_1 && !references_3_1.done && (_c2 = references_3.return))
133436
+ _c2.call(references_3);
133437
+ } finally {
133438
+ if (e_6)
133439
+ throw e_6.error;
133440
+ }
133441
+ }
133442
+ }
133443
+ return false;
133444
+ }
133445
+ }
133446
+ } else if (name === "useTransition") {
133447
+ if (id2.type === "ArrayPattern" && id2.elements.length === 2 && Array.isArray(resolved2.identifiers)) {
133448
+ if (id2.elements[1] === resolved2.identifiers[0]) {
133449
+ return true;
133450
+ }
133451
+ }
133452
+ }
133453
+ return false;
133454
+ }
133455
+ function isFunctionWithoutCapturedValues(resolved2) {
133456
+ var e_7, _a2, e_8, _b2;
133457
+ if (!isArray(resolved2.defs)) {
133458
+ return false;
133459
+ }
133460
+ var def2 = resolved2.defs[0];
133461
+ if (def2 == null) {
133462
+ return false;
133463
+ }
133464
+ if (def2.node == null || def2.node.id == null) {
133465
+ return false;
133466
+ }
133467
+ var fnNode = def2.node;
133468
+ var childScopes = (componentScope === null || componentScope === undefined ? undefined : componentScope.childScopes) || [];
133469
+ var fnScope = null;
133470
+ try {
133471
+ for (var childScopes_1 = __values(childScopes), childScopes_1_1 = childScopes_1.next();!childScopes_1_1.done; childScopes_1_1 = childScopes_1.next()) {
133472
+ var childScope = childScopes_1_1.value;
133473
+ var childScopeBlock = childScope.block;
133474
+ if (fnNode.type === "FunctionDeclaration" && childScopeBlock === fnNode || fnNode.type === "VariableDeclarator" && childScopeBlock.parent === fnNode) {
133475
+ fnScope = childScope;
133476
+ break;
133477
+ }
133478
+ }
133479
+ } catch (e_7_1) {
133480
+ e_7 = { error: e_7_1 };
133481
+ } finally {
133482
+ try {
133483
+ if (childScopes_1_1 && !childScopes_1_1.done && (_a2 = childScopes_1.return))
133484
+ _a2.call(childScopes_1);
133485
+ } finally {
133486
+ if (e_7)
133487
+ throw e_7.error;
133488
+ }
133489
+ }
133490
+ if (fnScope == null) {
133491
+ return false;
133492
+ }
133493
+ try {
133494
+ for (var _c2 = __values(fnScope.through), _d2 = _c2.next();!_d2.done; _d2 = _c2.next()) {
133495
+ var ref2 = _d2.value;
133496
+ if (ref2.resolved == null) {
133497
+ continue;
133498
+ }
133499
+ if (pureScopes.has(ref2.resolved.scope) && !memoizedIsStableKnownHookValue(ref2.resolved)) {
133500
+ return false;
133501
+ }
133502
+ }
133503
+ } catch (e_8_1) {
133504
+ e_8 = { error: e_8_1 };
133505
+ } finally {
133506
+ try {
133507
+ if (_d2 && !_d2.done && (_b2 = _c2.return))
133508
+ _b2.call(_c2);
133509
+ } finally {
133510
+ if (e_8)
133511
+ throw e_8.error;
133512
+ }
133513
+ }
133514
+ return true;
133515
+ }
133516
+ var memoizedIsStableKnownHookValue = memoizeWithWeakMap(isStableKnownHookValue, stableKnownValueCache);
133517
+ var memoizedIsFunctionWithoutCapturedValues = memoizeWithWeakMap(isFunctionWithoutCapturedValues, functionWithoutCapturedValueCache);
133518
+ var currentRefsInEffectCleanup = new Map;
133519
+ function isInsideEffectCleanup(reference2) {
133520
+ var curScope = reference2.from;
133521
+ var isInReturnedFunction = false;
133522
+ while (curScope != null && curScope.block !== node) {
133523
+ if (curScope.type === "function") {
133524
+ isInReturnedFunction = curScope.block.parent != null && curScope.block.parent.type === "ReturnStatement";
133525
+ }
133526
+ curScope = curScope.upper;
133527
+ }
133528
+ return isInReturnedFunction;
133529
+ }
133530
+ var dependencies = new Map;
133531
+ var optionalChains = new Map;
133532
+ gatherDependenciesRecursively(scope);
133533
+ function gatherDependenciesRecursively(currentScope2) {
133534
+ var e_9, _a2, e_10, _b2;
133535
+ var _c2, _d2, _e, _f, _g;
133536
+ try {
133537
+ for (var _h = __values(currentScope2.references), _j = _h.next();!_j.done; _j = _h.next()) {
133538
+ var reference2 = _j.value;
133539
+ if (!reference2.resolved) {
133540
+ continue;
133541
+ }
133542
+ if (!pureScopes.has(reference2.resolved.scope)) {
133543
+ continue;
133544
+ }
133545
+ var referenceNode = fastFindReferenceWithParent(node, reference2.identifier);
133546
+ if (referenceNode == null) {
133547
+ continue;
133548
+ }
133549
+ var dependencyNode = getDependency(referenceNode);
133550
+ var dependency = analyzePropertyChain(dependencyNode, optionalChains);
133551
+ if (isEffect && dependencyNode.type === "Identifier" && (((_c2 = dependencyNode.parent) === null || _c2 === undefined ? undefined : _c2.type) === "MemberExpression" || ((_d2 = dependencyNode.parent) === null || _d2 === undefined ? undefined : _d2.type) === "OptionalMemberExpression") && !dependencyNode.parent.computed && dependencyNode.parent.property.type === "Identifier" && dependencyNode.parent.property.name === "current" && isInsideEffectCleanup(reference2)) {
133552
+ currentRefsInEffectCleanup.set(dependency, {
133553
+ reference: reference2,
133554
+ dependencyNode
133555
+ });
133556
+ }
133557
+ if (((_e = dependencyNode.parent) === null || _e === undefined ? undefined : _e.type) === "TSTypeQuery" || ((_f = dependencyNode.parent) === null || _f === undefined ? undefined : _f.type) === "TSTypeReference") {
133558
+ continue;
133559
+ }
133560
+ var def2 = reference2.resolved.defs[0];
133561
+ if (def2 == null) {
133562
+ continue;
133563
+ }
133564
+ if (def2.node != null && def2.node.init === node.parent) {
133565
+ continue;
133566
+ }
133567
+ if (def2.type === "TypeParameter") {
133568
+ continue;
133569
+ }
133570
+ if (!dependencies.has(dependency)) {
133571
+ var resolved2 = reference2.resolved;
133572
+ var isStable = memoizedIsStableKnownHookValue(resolved2) || memoizedIsFunctionWithoutCapturedValues(resolved2);
133573
+ dependencies.set(dependency, {
133574
+ isStable,
133575
+ references: [reference2]
133576
+ });
133577
+ } else {
133578
+ (_g = dependencies.get(dependency)) === null || _g === undefined || _g.references.push(reference2);
133579
+ }
133580
+ }
133581
+ } catch (e_9_1) {
133582
+ e_9 = { error: e_9_1 };
133583
+ } finally {
133584
+ try {
133585
+ if (_j && !_j.done && (_a2 = _h.return))
133586
+ _a2.call(_h);
133587
+ } finally {
133588
+ if (e_9)
133589
+ throw e_9.error;
133590
+ }
133591
+ }
133592
+ try {
133593
+ for (var _k = __values(currentScope2.childScopes), _l = _k.next();!_l.done; _l = _k.next()) {
133594
+ var childScope = _l.value;
133595
+ gatherDependenciesRecursively(childScope);
133596
+ }
133597
+ } catch (e_10_1) {
133598
+ e_10 = { error: e_10_1 };
133599
+ } finally {
133600
+ try {
133601
+ if (_l && !_l.done && (_b2 = _k.return))
133602
+ _b2.call(_k);
133603
+ } finally {
133604
+ if (e_10)
133605
+ throw e_10.error;
133606
+ }
133607
+ }
133608
+ }
133609
+ currentRefsInEffectCleanup.forEach(function(_a2, dependency) {
133610
+ var e_11, _b2;
133611
+ var _c2, _d2;
133612
+ var { reference: reference2, dependencyNode } = _a2;
133613
+ var references2 = ((_c2 = reference2.resolved) === null || _c2 === undefined ? undefined : _c2.references) || [];
133614
+ var foundCurrentAssignment = false;
133615
+ try {
133616
+ for (var references_4 = __values(references2), references_4_1 = references_4.next();!references_4_1.done; references_4_1 = references_4.next()) {
133617
+ var ref2 = references_4_1.value;
133618
+ var identifier = ref2.identifier;
133619
+ var parent2 = identifier.parent;
133620
+ if (parent2 != null && parent2.type === "MemberExpression" && !parent2.computed && parent2.property.type === "Identifier" && parent2.property.name === "current" && ((_d2 = parent2.parent) === null || _d2 === undefined ? undefined : _d2.type) === "AssignmentExpression" && parent2.parent.left === parent2) {
133621
+ foundCurrentAssignment = true;
133622
+ break;
133623
+ }
133624
+ }
133625
+ } catch (e_11_1) {
133626
+ e_11 = { error: e_11_1 };
133627
+ } finally {
133628
+ try {
133629
+ if (references_4_1 && !references_4_1.done && (_b2 = references_4.return))
133630
+ _b2.call(references_4);
133631
+ } finally {
133632
+ if (e_11)
133633
+ throw e_11.error;
133634
+ }
133635
+ }
133636
+ if (foundCurrentAssignment) {
133637
+ return;
133638
+ }
133639
+ reportProblem({
133640
+ node: dependencyNode.parent.property,
133641
+ message: "The ref value '".concat(dependency, ".current' will likely have ") + "changed by the time this effect cleanup function runs. If " + "this ref points to a node rendered by React, copy " + "'".concat(dependency, ".current' to a variable inside the effect, and ") + "use that variable in the cleanup function."
133642
+ });
133643
+ });
133644
+ var staleAssignments = new Set;
133645
+ function reportStaleAssignment(writeExpr, key) {
133646
+ if (staleAssignments.has(key)) {
133647
+ return;
133648
+ }
133649
+ staleAssignments.add(key);
133650
+ reportProblem({
133651
+ node: writeExpr,
133652
+ message: "Assignments to the '".concat(key, "' variable from inside React Hook ") + "".concat(getSourceCode().getText(reactiveHook), " 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 " + "".concat(getSourceCode().getText(reactiveHook), ".")
133653
+ });
133654
+ }
133655
+ var stableDependencies = new Set;
133656
+ dependencies.forEach(function(_a2, key) {
133657
+ var { isStable, references: references2 } = _a2;
133658
+ if (isStable) {
133659
+ stableDependencies.add(key);
133660
+ }
133661
+ references2.forEach(function(reference2) {
133662
+ if (reference2.writeExpr) {
133663
+ reportStaleAssignment(reference2.writeExpr, key);
133664
+ }
133665
+ });
133666
+ });
133667
+ if (staleAssignments.size > 0) {
133668
+ return;
133669
+ }
133670
+ if (!declaredDependenciesNode) {
133671
+ var setStateInsideEffectWithoutDeps_1 = null;
133672
+ dependencies.forEach(function(_a2, key) {
133673
+ var references2 = _a2.references;
133674
+ if (setStateInsideEffectWithoutDeps_1) {
133675
+ return;
133676
+ }
133677
+ references2.forEach(function(reference2) {
133678
+ if (setStateInsideEffectWithoutDeps_1) {
133679
+ return;
133680
+ }
133681
+ var id2 = reference2.identifier;
133682
+ var isSetState = setStateCallSites.has(id2);
133683
+ if (!isSetState) {
133684
+ return;
133685
+ }
133686
+ var fnScope = reference2.from;
133687
+ while (fnScope != null && fnScope.type !== "function") {
133688
+ fnScope = fnScope.upper;
133689
+ }
133690
+ var isDirectlyInsideEffect = (fnScope === null || fnScope === undefined ? undefined : fnScope.block) === node;
133691
+ if (isDirectlyInsideEffect) {
133692
+ setStateInsideEffectWithoutDeps_1 = key;
133693
+ }
133694
+ });
133695
+ });
133696
+ if (setStateInsideEffectWithoutDeps_1) {
133697
+ var suggestedDependencies_1 = collectRecommendations({
133698
+ dependencies,
133699
+ declaredDependencies: [],
133700
+ stableDependencies,
133701
+ externalDependencies: new Set,
133702
+ isEffect: true
133703
+ }).suggestedDependencies;
133704
+ reportProblem({
133705
+ node: reactiveHook,
133706
+ message: "React Hook ".concat(reactiveHookName, " contains a call to '").concat(setStateInsideEffectWithoutDeps_1, "'. ") + "Without a list of dependencies, this can lead to an infinite chain of updates. " + "To fix this, pass [" + suggestedDependencies_1.join(", ") + "] as a second argument to the ".concat(reactiveHookName, " Hook."),
133707
+ suggest: [
133708
+ {
133709
+ desc: "Add dependencies array: [".concat(suggestedDependencies_1.join(", "), "]"),
133710
+ fix: function(fixer) {
133711
+ return fixer.insertTextAfter(node, ", [".concat(suggestedDependencies_1.join(", "), "]"));
133712
+ }
133713
+ }
133714
+ ]
133715
+ });
133716
+ }
133717
+ return;
133718
+ }
133719
+ var declaredDependencies = [];
133720
+ var externalDependencies = new Set;
133721
+ var isArrayExpression = declaredDependenciesNode.type === "ArrayExpression";
133722
+ var isTSAsArrayExpression = declaredDependenciesNode.type === "TSAsExpression" && declaredDependenciesNode.expression.type === "ArrayExpression";
133723
+ if (!isArrayExpression && !isTSAsArrayExpression) {
133724
+ reportProblem({
133725
+ node: declaredDependenciesNode,
133726
+ message: "React Hook ".concat(getSourceCode().getText(reactiveHook), " 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."
133727
+ });
133728
+ } else {
133729
+ var arrayExpression = isTSAsArrayExpression ? declaredDependenciesNode.expression : declaredDependenciesNode;
133730
+ arrayExpression.elements.forEach(function(declaredDependencyNode) {
133731
+ if (declaredDependencyNode === null) {
133732
+ return;
133733
+ }
133734
+ if (declaredDependencyNode.type === "SpreadElement") {
133735
+ reportProblem({
133736
+ node: declaredDependencyNode,
133737
+ message: "React Hook ".concat(getSourceCode().getText(reactiveHook), " has a spread ") + "element in its dependency array. This means we can't " + "statically verify whether you've passed the " + "correct dependencies."
133738
+ });
133739
+ return;
133740
+ }
133741
+ if (useEffectEventVariables.has(declaredDependencyNode)) {
133742
+ reportProblem({
133743
+ node: declaredDependencyNode,
133744
+ message: "Functions returned from `useEffectEvent` must not be included in the dependency array. " + "Remove `".concat(getSourceCode().getText(declaredDependencyNode), "` from the list."),
133745
+ suggest: [
133746
+ {
133747
+ desc: "Remove the dependency `".concat(getSourceCode().getText(declaredDependencyNode), "`"),
133748
+ fix: function(fixer) {
133749
+ return fixer.removeRange(declaredDependencyNode.range);
133750
+ }
133751
+ }
133752
+ ]
133753
+ });
133754
+ }
133755
+ var declaredDependency;
133756
+ try {
133757
+ declaredDependency = analyzePropertyChain(declaredDependencyNode, null);
133758
+ } catch (error) {
133759
+ if (error instanceof Error && /Unsupported node type/.test(error.message)) {
133760
+ if (declaredDependencyNode.type === "Literal") {
133761
+ if (declaredDependencyNode.value && dependencies.has(declaredDependencyNode.value)) {
133762
+ reportProblem({
133763
+ node: declaredDependencyNode,
133764
+ message: "The ".concat(declaredDependencyNode.raw, " literal is not a valid dependency ") + "because it never changes. " + "Did you mean to include ".concat(declaredDependencyNode.value, " in the array instead?")
133765
+ });
133766
+ } else {
133767
+ reportProblem({
133768
+ node: declaredDependencyNode,
133769
+ message: "The ".concat(declaredDependencyNode.raw, " literal is not a valid dependency ") + "because it never changes. You can safely remove it."
133770
+ });
133771
+ }
133772
+ } else {
133773
+ reportProblem({
133774
+ node: declaredDependencyNode,
133775
+ message: "React Hook ".concat(getSourceCode().getText(reactiveHook), " has a ") + "complex expression in the dependency array. " + "Extract it to a separate variable so it can be statically checked."
133776
+ });
133777
+ }
133778
+ return;
133779
+ } else {
133780
+ throw error;
133781
+ }
133782
+ }
133783
+ var maybeID = declaredDependencyNode;
133784
+ while (maybeID.type === "MemberExpression" || maybeID.type === "OptionalMemberExpression" || maybeID.type === "ChainExpression") {
133785
+ maybeID = maybeID.object || maybeID.expression.object;
133786
+ }
133787
+ var isDeclaredInComponent = !componentScope.through.some(function(ref2) {
133788
+ return ref2.identifier === maybeID;
133789
+ });
133790
+ declaredDependencies.push({
133791
+ key: declaredDependency,
133792
+ node: declaredDependencyNode
133793
+ });
133794
+ if (!isDeclaredInComponent) {
133795
+ externalDependencies.add(declaredDependency);
133796
+ }
133797
+ });
133798
+ }
133799
+ var _d = collectRecommendations({
133800
+ dependencies,
133801
+ declaredDependencies,
133802
+ stableDependencies,
133803
+ externalDependencies,
133804
+ isEffect
133805
+ }), suggestedDependencies = _d.suggestedDependencies, unnecessaryDependencies = _d.unnecessaryDependencies, missingDependencies = _d.missingDependencies, duplicateDependencies = _d.duplicateDependencies;
133806
+ var suggestedDeps = suggestedDependencies;
133807
+ var problemCount = duplicateDependencies.size + missingDependencies.size + unnecessaryDependencies.size;
133808
+ if (problemCount === 0) {
133809
+ var constructions = scanForConstructions({
133810
+ declaredDependencies,
133811
+ declaredDependenciesNode,
133812
+ componentScope,
133813
+ scope
133814
+ });
133815
+ constructions.forEach(function(_a2) {
133816
+ var _b2;
133817
+ var { construction, isUsedOutsideOfHook, depType } = _a2;
133818
+ var wrapperHook = depType === "function" ? "useCallback" : "useMemo";
133819
+ var constructionType = depType === "function" ? "definition" : "initialization";
133820
+ var defaultAdvice = "wrap the ".concat(constructionType, " of '").concat(construction.name.name, "' in its own ").concat(wrapperHook, "() Hook.");
133821
+ var advice = isUsedOutsideOfHook ? "To fix this, ".concat(defaultAdvice) : "Move it inside the ".concat(reactiveHookName, " callback. Alternatively, ").concat(defaultAdvice);
133822
+ var causation = depType === "conditional" || depType === "logical expression" ? "could make" : "makes";
133823
+ var message = "The '".concat(construction.name.name, "' ").concat(depType, " ").concat(causation, " the dependencies of ") + "".concat(reactiveHookName, " Hook (at line ").concat((_b2 = declaredDependenciesNode.loc) === null || _b2 === undefined ? undefined : _b2.start.line, ") ") + "change on every render. ".concat(advice);
133824
+ var suggest;
133825
+ if (isUsedOutsideOfHook && construction.type === "Variable" && depType === "function") {
133826
+ suggest = [
133827
+ {
133828
+ desc: "Wrap the ".concat(constructionType, " of '").concat(construction.name.name, "' in its own ").concat(wrapperHook, "() Hook."),
133829
+ fix: function(fixer) {
133830
+ var _a3 = __read(wrapperHook === "useMemo" ? ["useMemo(() => { return ", "; })"] : ["useCallback(", ")"], 2), before = _a3[0], after = _a3[1];
133831
+ return [
133832
+ fixer.insertTextBefore(construction.node.init, before),
133833
+ fixer.insertTextAfter(construction.node.init, after)
133834
+ ];
133835
+ }
133836
+ }
133837
+ ];
133838
+ }
133839
+ reportProblem({
133840
+ node: construction.node,
133841
+ message,
133842
+ suggest
133843
+ });
133844
+ });
133845
+ return;
133846
+ }
133847
+ if (!isEffect && missingDependencies.size > 0) {
133848
+ suggestedDeps = collectRecommendations({
133849
+ dependencies,
133850
+ declaredDependencies: [],
133851
+ stableDependencies,
133852
+ externalDependencies,
133853
+ isEffect
133854
+ }).suggestedDependencies;
133855
+ }
133856
+ function areDeclaredDepsAlphabetized() {
133857
+ if (declaredDependencies.length === 0) {
133858
+ return true;
133859
+ }
133860
+ var declaredDepKeys = declaredDependencies.map(function(dep2) {
133861
+ return dep2.key;
133862
+ });
133863
+ var sortedDeclaredDepKeys = declaredDepKeys.slice().sort();
133864
+ return declaredDepKeys.join(",") === sortedDeclaredDepKeys.join(",");
133865
+ }
133866
+ if (areDeclaredDepsAlphabetized()) {
133867
+ suggestedDeps.sort();
133868
+ }
133869
+ function formatDependency(path) {
133870
+ var members = path.split(".");
133871
+ var finalPath = "";
133872
+ for (var i = 0;i < members.length; i++) {
133873
+ if (i !== 0) {
133874
+ var pathSoFar = members.slice(0, i + 1).join(".");
133875
+ var isOptional = optionalChains.get(pathSoFar) === true;
133876
+ finalPath += isOptional ? "?." : ".";
133877
+ }
133878
+ finalPath += members[i];
133879
+ }
133880
+ return finalPath;
133881
+ }
133882
+ function getWarningMessage(deps, singlePrefix, label, fixVerb) {
133883
+ if (deps.size === 0) {
133884
+ return null;
133885
+ }
133886
+ return (deps.size > 1 ? "" : singlePrefix + " ") + label + " " + (deps.size > 1 ? "dependencies" : "dependency") + ": " + joinEnglish(Array.from(deps).sort().map(function(name) {
133887
+ return "'" + formatDependency(name) + "'";
133888
+ })) + ". Either ".concat(fixVerb, " ").concat(deps.size > 1 ? "them" : "it", " or remove the dependency array.");
133889
+ }
133890
+ var extraWarning = "";
133891
+ if (unnecessaryDependencies.size > 0) {
133892
+ var badRef_1 = null;
133893
+ Array.from(unnecessaryDependencies.keys()).forEach(function(key) {
133894
+ if (badRef_1 !== null) {
133895
+ return;
133896
+ }
133897
+ if (key.endsWith(".current")) {
133898
+ badRef_1 = key;
133899
+ }
133900
+ });
133901
+ if (badRef_1 !== null) {
133902
+ extraWarning = " Mutable values like '".concat(badRef_1, "' aren't valid dependencies ") + "because mutating them doesn't re-render the component.";
133903
+ } else if (externalDependencies.size > 0) {
133904
+ var dep = Array.from(externalDependencies)[0];
133905
+ if (!scope.set.has(dep)) {
133906
+ extraWarning = " Outer scope values like '".concat(dep, "' aren't valid dependencies ") + "because mutating them doesn't re-render the component.";
133907
+ }
133908
+ }
133909
+ }
133910
+ if (!extraWarning && missingDependencies.has("props")) {
133911
+ var propDep = dependencies.get("props");
133912
+ if (propDep == null) {
133913
+ return;
133914
+ }
133915
+ var refs = propDep.references;
133916
+ if (!Array.isArray(refs)) {
133917
+ return;
133918
+ }
133919
+ var isPropsOnlyUsedInMembers = true;
133920
+ try {
133921
+ for (var refs_1 = __values(refs), refs_1_1 = refs_1.next();!refs_1_1.done; refs_1_1 = refs_1.next()) {
133922
+ var ref = refs_1_1.value;
133923
+ var id = fastFindReferenceWithParent(componentScope.block, ref.identifier);
133924
+ if (!id) {
133925
+ isPropsOnlyUsedInMembers = false;
133926
+ break;
133927
+ }
133928
+ var parent = id.parent;
133929
+ if (parent == null) {
133930
+ isPropsOnlyUsedInMembers = false;
133931
+ break;
133932
+ }
133933
+ if (parent.type !== "MemberExpression" && parent.type !== "OptionalMemberExpression") {
133934
+ isPropsOnlyUsedInMembers = false;
133935
+ break;
133936
+ }
133937
+ }
133938
+ } catch (e_1_1) {
133939
+ e_1 = { error: e_1_1 };
133940
+ } finally {
133941
+ try {
133942
+ if (refs_1_1 && !refs_1_1.done && (_a = refs_1.return))
133943
+ _a.call(refs_1);
133944
+ } finally {
133945
+ if (e_1)
133946
+ throw e_1.error;
133947
+ }
133948
+ }
133949
+ if (isPropsOnlyUsedInMembers) {
133950
+ extraWarning = " However, 'props' will change when *any* prop changes, so the " + "preferred fix is to destructure the 'props' object outside of " + "the ".concat(reactiveHookName, " call and refer to those specific props ") + "inside ".concat(getSourceCode().getText(reactiveHook), ".");
133951
+ }
133952
+ }
133953
+ if (!extraWarning && missingDependencies.size > 0) {
133954
+ var missingCallbackDep_1 = null;
133955
+ missingDependencies.forEach(function(missingDep2) {
133956
+ var e_12, _a2;
133957
+ var _b2;
133958
+ if (missingCallbackDep_1) {
133959
+ return;
133960
+ }
133961
+ var topScopeRef = componentScope.set.get(missingDep2);
133962
+ var usedDep2 = dependencies.get(missingDep2);
133963
+ if (!(usedDep2 === null || usedDep2 === undefined ? undefined : usedDep2.references) || ((_b2 = usedDep2 === null || usedDep2 === undefined ? undefined : usedDep2.references[0]) === null || _b2 === undefined ? undefined : _b2.resolved) !== topScopeRef) {
133964
+ return;
133965
+ }
133966
+ var def2 = topScopeRef === null || topScopeRef === undefined ? undefined : topScopeRef.defs[0];
133967
+ if (def2 == null || def2.name == null || def2.type !== "Parameter") {
133968
+ return;
133969
+ }
133970
+ var isFunctionCall = false;
133971
+ var id2;
133972
+ try {
133973
+ for (var _c2 = __values(usedDep2.references), _d2 = _c2.next();!_d2.done; _d2 = _c2.next()) {
133974
+ var reference2 = _d2.value;
133975
+ id2 = reference2.identifier;
133976
+ if (id2 != null && id2.parent != null && (id2.parent.type === "CallExpression" || id2.parent.type === "OptionalCallExpression") && id2.parent.callee === id2) {
133977
+ isFunctionCall = true;
133978
+ break;
133979
+ }
133980
+ }
133981
+ } catch (e_12_1) {
133982
+ e_12 = { error: e_12_1 };
133983
+ } finally {
133984
+ try {
133985
+ if (_d2 && !_d2.done && (_a2 = _c2.return))
133986
+ _a2.call(_c2);
133987
+ } finally {
133988
+ if (e_12)
133989
+ throw e_12.error;
133990
+ }
133991
+ }
133992
+ if (!isFunctionCall) {
133993
+ return;
133994
+ }
133995
+ missingCallbackDep_1 = missingDep2;
133996
+ });
133997
+ if (missingCallbackDep_1 !== null) {
133998
+ extraWarning = " If '".concat(missingCallbackDep_1, "' changes too often, ") + "find the parent component that defines it " + "and wrap that definition in useCallback.";
133999
+ }
134000
+ }
134001
+ if (!extraWarning && missingDependencies.size > 0) {
134002
+ var setStateRecommendation = null;
134003
+ try {
134004
+ for (var missingDependencies_1 = __values(missingDependencies), missingDependencies_1_1 = missingDependencies_1.next();!missingDependencies_1_1.done; missingDependencies_1_1 = missingDependencies_1.next()) {
134005
+ var missingDep = missingDependencies_1_1.value;
134006
+ if (setStateRecommendation !== null) {
134007
+ break;
134008
+ }
134009
+ var usedDep = dependencies.get(missingDep);
134010
+ var references = usedDep.references;
134011
+ var id = undefined;
134012
+ var maybeCall = undefined;
134013
+ try {
134014
+ for (var references_1 = (e_3 = undefined, __values(references)), references_1_1 = references_1.next();!references_1_1.done; references_1_1 = references_1.next()) {
134015
+ var reference = references_1_1.value;
134016
+ id = reference.identifier;
134017
+ maybeCall = id.parent;
134018
+ while (maybeCall != null && maybeCall !== componentScope.block) {
134019
+ if (maybeCall.type === "CallExpression") {
134020
+ var correspondingStateVariable = setStateCallSites.get(maybeCall.callee);
134021
+ if (correspondingStateVariable != null) {
134022
+ if ("name" in correspondingStateVariable && correspondingStateVariable.name === missingDep) {
134023
+ setStateRecommendation = {
134024
+ missingDep,
134025
+ setter: "name" in maybeCall.callee ? maybeCall.callee.name : "",
134026
+ form: "updater"
134027
+ };
134028
+ } else if (stateVariables.has(id)) {
134029
+ setStateRecommendation = {
134030
+ missingDep,
134031
+ setter: "name" in maybeCall.callee ? maybeCall.callee.name : "",
134032
+ form: "reducer"
134033
+ };
134034
+ } else {
134035
+ var resolved = reference.resolved;
134036
+ if (resolved != null) {
134037
+ var def = resolved.defs[0];
134038
+ if (def != null && def.type === "Parameter") {
134039
+ setStateRecommendation = {
134040
+ missingDep,
134041
+ setter: "name" in maybeCall.callee ? maybeCall.callee.name : "",
134042
+ form: "inlineReducer"
134043
+ };
134044
+ }
134045
+ }
134046
+ }
134047
+ break;
134048
+ }
134049
+ }
134050
+ maybeCall = maybeCall.parent;
134051
+ }
134052
+ if (setStateRecommendation !== null) {
134053
+ break;
134054
+ }
134055
+ }
134056
+ } catch (e_3_1) {
134057
+ e_3 = { error: e_3_1 };
134058
+ } finally {
134059
+ try {
134060
+ if (references_1_1 && !references_1_1.done && (_c = references_1.return))
134061
+ _c.call(references_1);
134062
+ } finally {
134063
+ if (e_3)
134064
+ throw e_3.error;
134065
+ }
134066
+ }
134067
+ }
134068
+ } catch (e_2_1) {
134069
+ e_2 = { error: e_2_1 };
134070
+ } finally {
134071
+ try {
134072
+ if (missingDependencies_1_1 && !missingDependencies_1_1.done && (_b = missingDependencies_1.return))
134073
+ _b.call(missingDependencies_1);
134074
+ } finally {
134075
+ if (e_2)
134076
+ throw e_2.error;
134077
+ }
134078
+ }
134079
+ if (setStateRecommendation !== null) {
134080
+ switch (setStateRecommendation.form) {
134081
+ case "reducer":
134082
+ extraWarning = " You can also replace multiple useState variables with useReducer " + "if '".concat(setStateRecommendation.setter, "' needs the ") + "current value of '".concat(setStateRecommendation.missingDep, "'.");
134083
+ break;
134084
+ case "inlineReducer":
134085
+ extraWarning = " If '".concat(setStateRecommendation.setter, "' needs the ") + "current value of '".concat(setStateRecommendation.missingDep, "', ") + "you can also switch to useReducer instead of useState and " + "read '".concat(setStateRecommendation.missingDep, "' in the reducer.");
134086
+ break;
134087
+ case "updater":
134088
+ extraWarning = " You can also do a functional update '".concat(setStateRecommendation.setter, "(").concat(setStateRecommendation.missingDep.slice(0, 1), " => ...)' if you only need '").concat(setStateRecommendation.missingDep, "'") + " in the '".concat(setStateRecommendation.setter, "' call.");
134089
+ break;
134090
+ default:
134091
+ throw new Error("Unknown case.");
134092
+ }
134093
+ }
134094
+ }
134095
+ reportProblem({
134096
+ node: declaredDependenciesNode,
134097
+ message: "React Hook ".concat(getSourceCode().getText(reactiveHook), " has ") + (getWarningMessage(missingDependencies, "a", "missing", "include") || getWarningMessage(unnecessaryDependencies, "an", "unnecessary", "exclude") || getWarningMessage(duplicateDependencies, "a", "duplicate", "omit")) + extraWarning,
134098
+ suggest: [
134099
+ {
134100
+ desc: "Update the dependencies array to be: [".concat(suggestedDeps.map(formatDependency).join(", "), "]"),
134101
+ fix: function(fixer) {
134102
+ return fixer.replaceText(declaredDependenciesNode, "[".concat(suggestedDeps.map(formatDependency).join(", "), "]"));
134103
+ }
134104
+ }
134105
+ ]
134106
+ });
134107
+ }
134108
+ function visitCallExpression(node) {
134109
+ var callbackIndex = getReactiveHookCallbackIndex(node.callee, options);
134110
+ if (callbackIndex === -1) {
134111
+ return;
134112
+ }
134113
+ var callback = node.arguments[callbackIndex];
134114
+ var reactiveHook = node.callee;
134115
+ var nodeWithoutNamespace = getNodeWithoutReactNamespace(reactiveHook);
134116
+ var reactiveHookName = "name" in nodeWithoutNamespace ? nodeWithoutNamespace.name : "";
134117
+ var maybeNode = node.arguments[callbackIndex + 1];
134118
+ var declaredDependenciesNode = maybeNode && !(maybeNode.type === "Identifier" && maybeNode.name === "undefined") ? maybeNode : undefined;
134119
+ var isEffect = /Effect($|[^a-z])/g.test(reactiveHookName);
134120
+ if (!callback) {
134121
+ reportProblem({
134122
+ node: reactiveHook,
134123
+ message: "React Hook ".concat(reactiveHookName, " requires an effect callback. ") + "Did you forget to pass a callback to the hook?"
134124
+ });
134125
+ return;
134126
+ }
134127
+ if (!declaredDependenciesNode && !isEffect) {
134128
+ if (reactiveHookName === "useMemo" || reactiveHookName === "useCallback") {
134129
+ reportProblem({
134130
+ node: reactiveHook,
134131
+ message: "React Hook ".concat(reactiveHookName, " does nothing when called with ") + "only one argument. Did you forget to pass an array of " + "dependencies?"
134132
+ });
134133
+ }
134134
+ return;
134135
+ }
134136
+ while (callback.type === "TSAsExpression" || callback.type === "AsExpression") {
134137
+ callback = callback.expression;
134138
+ }
134139
+ switch (callback.type) {
134140
+ case "FunctionExpression":
134141
+ case "ArrowFunctionExpression":
134142
+ visitFunctionWithDependencies(callback, declaredDependenciesNode, reactiveHook, reactiveHookName, isEffect);
134143
+ return;
134144
+ case "Identifier":
134145
+ if (!declaredDependenciesNode) {
134146
+ return;
134147
+ }
134148
+ if ("elements" in declaredDependenciesNode && declaredDependenciesNode.elements && declaredDependenciesNode.elements.some(function(el) {
134149
+ return el && el.type === "Identifier" && el.name === callback.name;
134150
+ })) {
134151
+ return;
134152
+ }
134153
+ var variable = getScope(callback).set.get(callback.name);
134154
+ if (variable == null || variable.defs == null) {
134155
+ return;
134156
+ }
134157
+ var def = variable.defs[0];
134158
+ if (!def || !def.node) {
134159
+ break;
134160
+ }
134161
+ if (def.type === "Parameter") {
134162
+ reportProblem({
134163
+ node: reactiveHook,
134164
+ message: getUnknownDependenciesMessage(reactiveHookName)
134165
+ });
134166
+ return;
134167
+ }
134168
+ if (def.type !== "Variable" && def.type !== "FunctionName") {
134169
+ break;
134170
+ }
134171
+ switch (def.node.type) {
134172
+ case "FunctionDeclaration":
134173
+ visitFunctionWithDependencies(def.node, declaredDependenciesNode, reactiveHook, reactiveHookName, isEffect);
134174
+ return;
134175
+ case "VariableDeclarator":
134176
+ var init = def.node.init;
134177
+ if (!init) {
134178
+ break;
134179
+ }
134180
+ switch (init.type) {
134181
+ case "ArrowFunctionExpression":
134182
+ case "FunctionExpression":
134183
+ visitFunctionWithDependencies(init, declaredDependenciesNode, reactiveHook, reactiveHookName, isEffect);
134184
+ return;
134185
+ }
134186
+ break;
134187
+ }
134188
+ break;
134189
+ default:
134190
+ reportProblem({
134191
+ node: reactiveHook,
134192
+ message: getUnknownDependenciesMessage(reactiveHookName)
134193
+ });
134194
+ return;
134195
+ }
134196
+ reportProblem({
134197
+ node: reactiveHook,
134198
+ message: "React Hook ".concat(reactiveHookName, " has a missing dependency: '").concat(callback.name, "'. ") + "Either include it or remove the dependency array.",
134199
+ suggest: [
134200
+ {
134201
+ desc: "Update the dependencies array to be: [".concat(callback.name, "]"),
134202
+ fix: function(fixer) {
134203
+ return fixer.replaceText(declaredDependenciesNode, "[".concat(callback.name, "]"));
134204
+ }
134205
+ }
134206
+ ]
134207
+ });
134208
+ }
134209
+ return {
134210
+ CallExpression: visitCallExpression
134211
+ };
134212
+ }
134213
+ };
134214
+ function collectRecommendations(_a) {
134215
+ var { dependencies, declaredDependencies, stableDependencies, externalDependencies, isEffect } = _a;
134216
+ var depTree = createDepTree();
132812
134217
  function createDepTree() {
132813
134218
  return {
132814
134219
  isUsed: false,
@@ -132817,80 +134222,127 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
132817
134222
  children: new Map
132818
134223
  };
132819
134224
  }
134225
+ dependencies.forEach(function(_, key) {
134226
+ var node = getOrCreateNodeByPath(depTree, key);
134227
+ node.isUsed = true;
134228
+ markAllParentsByPath(depTree, key, function(parent) {
134229
+ parent.isSubtreeUsed = true;
134230
+ });
134231
+ });
134232
+ declaredDependencies.forEach(function(_a2) {
134233
+ var key = _a2.key;
134234
+ var node = getOrCreateNodeByPath(depTree, key);
134235
+ node.isSatisfiedRecursively = true;
134236
+ });
134237
+ stableDependencies.forEach(function(key) {
134238
+ var node = getOrCreateNodeByPath(depTree, key);
134239
+ node.isSatisfiedRecursively = true;
134240
+ });
132820
134241
  function getOrCreateNodeByPath(rootNode, path) {
132821
- path = path.split(".");
132822
- path = _createForOfIteratorHelper(path);
132823
- var _step4;
134242
+ var e_13, _a2;
134243
+ var keys = path.split(".");
134244
+ var node = rootNode;
132824
134245
  try {
132825
- for (path.s();!(_step4 = path.n()).done; ) {
132826
- var key = _step4.value, child = rootNode.children.get(key);
132827
- child || (child = createDepTree(), rootNode.children.set(key, child));
132828
- rootNode = child;
134246
+ for (var keys_1 = __values(keys), keys_1_1 = keys_1.next();!keys_1_1.done; keys_1_1 = keys_1.next()) {
134247
+ var key = keys_1_1.value;
134248
+ var child = node.children.get(key);
134249
+ if (!child) {
134250
+ child = createDepTree();
134251
+ node.children.set(key, child);
134252
+ }
134253
+ node = child;
132829
134254
  }
132830
- } catch (err) {
132831
- path.e(err);
134255
+ } catch (e_13_1) {
134256
+ e_13 = { error: e_13_1 };
132832
134257
  } finally {
132833
- path.f();
134258
+ try {
134259
+ if (keys_1_1 && !keys_1_1.done && (_a2 = keys_1.return))
134260
+ _a2.call(keys_1);
134261
+ } finally {
134262
+ if (e_13)
134263
+ throw e_13.error;
134264
+ }
132834
134265
  }
132835
- return rootNode;
134266
+ return node;
132836
134267
  }
132837
134268
  function markAllParentsByPath(rootNode, path, fn) {
132838
- path = path.split(".");
132839
- path = _createForOfIteratorHelper(path);
132840
- var _step5;
134269
+ var e_14, _a2;
134270
+ var keys = path.split(".");
134271
+ var node = rootNode;
132841
134272
  try {
132842
- for (path.s();!(_step5 = path.n()).done; ) {
132843
- var child = rootNode.children.get(_step5.value);
132844
- if (!child)
132845
- break;
134273
+ for (var keys_2 = __values(keys), keys_2_1 = keys_2.next();!keys_2_1.done; keys_2_1 = keys_2.next()) {
134274
+ var key = keys_2_1.value;
134275
+ var child = node.children.get(key);
134276
+ if (!child) {
134277
+ return;
134278
+ }
132846
134279
  fn(child);
132847
- rootNode = child;
134280
+ node = child;
132848
134281
  }
132849
- } catch (err) {
132850
- path.e(err);
134282
+ } catch (e_14_1) {
134283
+ e_14 = { error: e_14_1 };
132851
134284
  } finally {
132852
- path.f();
134285
+ try {
134286
+ if (keys_2_1 && !keys_2_1.done && (_a2 = keys_2.return))
134287
+ _a2.call(keys_2);
134288
+ } finally {
134289
+ if (e_14)
134290
+ throw e_14.error;
134291
+ }
132853
134292
  }
132854
134293
  }
134294
+ var missingDependencies = new Set;
134295
+ var satisfyingDependencies = new Set;
134296
+ scanTreeRecursively(depTree, missingDependencies, satisfyingDependencies, function(key) {
134297
+ return key;
134298
+ });
132855
134299
  function scanTreeRecursively(node, missingPaths, satisfyingPaths, keyToPath) {
132856
134300
  node.children.forEach(function(child, key) {
132857
134301
  var path = keyToPath(key);
132858
- child.isSatisfiedRecursively ? child.isSubtreeUsed && satisfyingPaths.add(path) : child.isUsed ? missingPaths.add(path) : scanTreeRecursively(child, missingPaths, satisfyingPaths, function(childKey) {
134302
+ if (child.isSatisfiedRecursively) {
134303
+ if (child.isSubtreeUsed) {
134304
+ satisfyingPaths.add(path);
134305
+ }
134306
+ return;
134307
+ }
134308
+ if (child.isUsed) {
134309
+ missingPaths.add(path);
134310
+ return;
134311
+ }
134312
+ scanTreeRecursively(child, missingPaths, satisfyingPaths, function(childKey) {
132859
134313
  return path + "." + childKey;
132860
134314
  });
132861
134315
  });
132862
134316
  }
132863
- var { dependencies, declaredDependencies, stableDependencies, externalDependencies, isEffect } = _ref6, depTree = createDepTree();
132864
- dependencies.forEach(function(_, key) {
132865
- getOrCreateNodeByPath(depTree, key).isUsed = true;
132866
- markAllParentsByPath(depTree, key, function(parent) {
132867
- parent.isSubtreeUsed = true;
132868
- });
132869
- });
132870
- declaredDependencies.forEach(function(_ref7) {
132871
- getOrCreateNodeByPath(depTree, _ref7.key).isSatisfiedRecursively = true;
132872
- });
132873
- stableDependencies.forEach(function(key) {
132874
- getOrCreateNodeByPath(depTree, key).isSatisfiedRecursively = true;
132875
- });
132876
- _ref6 = new Set;
132877
- var satisfyingDependencies = new Set;
132878
- scanTreeRecursively(depTree, _ref6, satisfyingDependencies, function(key) {
132879
- return key;
132880
- });
132881
- var suggestedDependencies = [], unnecessaryDependencies = new Set, duplicateDependencies = new Set;
132882
- declaredDependencies.forEach(function(_ref8) {
132883
- _ref8 = _ref8.key;
132884
- satisfyingDependencies.has(_ref8) ? suggestedDependencies.indexOf(_ref8) === -1 ? suggestedDependencies.push(_ref8) : duplicateDependencies.add(_ref8) : !isEffect || _ref8.endsWith(".current") || externalDependencies.has(_ref8) ? unnecessaryDependencies.add(_ref8) : suggestedDependencies.indexOf(_ref8) === -1 && suggestedDependencies.push(_ref8);
134317
+ var suggestedDependencies = [];
134318
+ var unnecessaryDependencies = new Set;
134319
+ var duplicateDependencies = new Set;
134320
+ declaredDependencies.forEach(function(_a2) {
134321
+ var key = _a2.key;
134322
+ if (satisfyingDependencies.has(key)) {
134323
+ if (suggestedDependencies.indexOf(key) === -1) {
134324
+ suggestedDependencies.push(key);
134325
+ } else {
134326
+ duplicateDependencies.add(key);
134327
+ }
134328
+ } else {
134329
+ if (isEffect && !key.endsWith(".current") && !externalDependencies.has(key)) {
134330
+ if (suggestedDependencies.indexOf(key) === -1) {
134331
+ suggestedDependencies.push(key);
134332
+ }
134333
+ } else {
134334
+ unnecessaryDependencies.add(key);
134335
+ }
134336
+ }
132885
134337
  });
132886
- _ref6.forEach(function(key) {
134338
+ missingDependencies.forEach(function(key) {
132887
134339
  suggestedDependencies.push(key);
132888
134340
  });
132889
134341
  return {
132890
134342
  suggestedDependencies,
132891
134343
  unnecessaryDependencies,
132892
134344
  duplicateDependencies,
132893
- missingDependencies: _ref6
134345
+ missingDependencies
132894
134346
  };
132895
134347
  }
132896
134348
  function getConstructionExpressionType(node) {
@@ -132905,27 +134357,31 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
132905
134357
  case "ClassExpression":
132906
134358
  return "class";
132907
134359
  case "ConditionalExpression":
132908
- if (getConstructionExpressionType(node.consequent) != null || getConstructionExpressionType(node.alternate) != null)
134360
+ if (getConstructionExpressionType(node.consequent) != null || getConstructionExpressionType(node.alternate) != null) {
132909
134361
  return "conditional";
132910
- break;
134362
+ }
134363
+ return null;
132911
134364
  case "LogicalExpression":
132912
- if (getConstructionExpressionType(node.left) != null || getConstructionExpressionType(node.right) != null)
134365
+ if (getConstructionExpressionType(node.left) != null || getConstructionExpressionType(node.right) != null) {
132913
134366
  return "logical expression";
132914
- break;
134367
+ }
134368
+ return null;
132915
134369
  case "JSXFragment":
132916
134370
  return "JSX fragment";
132917
134371
  case "JSXElement":
132918
134372
  return "JSX element";
132919
134373
  case "AssignmentExpression":
132920
- if (getConstructionExpressionType(node.right) != null)
134374
+ if (getConstructionExpressionType(node.right) != null) {
132921
134375
  return "assignment expression";
132922
- break;
134376
+ }
134377
+ return null;
132923
134378
  case "NewExpression":
132924
134379
  return "object construction";
132925
134380
  case "Literal":
132926
- if (node.value instanceof RegExp)
134381
+ if (node.value instanceof RegExp) {
132927
134382
  return "regular expression";
132928
- break;
134383
+ }
134384
+ return null;
132929
134385
  case "TypeCastExpression":
132930
134386
  case "AsExpression":
132931
134387
  case "TSAsExpression":
@@ -132933,95 +134389,144 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
132933
134389
  }
132934
134390
  return null;
132935
134391
  }
132936
- function scanForConstructions(_ref9) {
132937
- var { declaredDependenciesNode, componentScope, scope } = _ref9;
132938
- return _ref9.declaredDependencies.map(function(_ref10) {
132939
- var key = _ref10.key;
132940
- _ref10 = componentScope.variables.find(function(v) {
134392
+ function scanForConstructions(_a) {
134393
+ var { declaredDependencies, declaredDependenciesNode, componentScope, scope } = _a;
134394
+ var constructions = declaredDependencies.map(function(_a2) {
134395
+ var key = _a2.key;
134396
+ var ref = componentScope.variables.find(function(v) {
132941
134397
  return v.name === key;
132942
134398
  });
132943
- if (_ref10 == null)
134399
+ if (ref == null) {
132944
134400
  return null;
132945
- var node = _ref10.defs[0];
132946
- if (node == null)
134401
+ }
134402
+ var node = ref.defs[0];
134403
+ if (node == null) {
132947
134404
  return null;
134405
+ }
132948
134406
  if (node.type === "Variable" && node.node.type === "VariableDeclarator" && node.node.id.type === "Identifier" && node.node.init != null) {
132949
134407
  var constantExpressionType = getConstructionExpressionType(node.node.init);
132950
- if (constantExpressionType != null)
132951
- return [_ref10, constantExpressionType];
132952
- }
132953
- return node.type === "FunctionName" && node.node.type === "FunctionDeclaration" ? [_ref10, "function"] : node.type === "ClassName" && node.node.type === "ClassDeclaration" ? [_ref10, "class"] : null;
132954
- }).filter(Boolean).map(function(_ref11) {
132955
- var ref = _ref11[0];
132956
- _ref11 = _ref11[1];
132957
- var JSCompiler_temp_const = ref.defs[0];
132958
- a: {
132959
- for (var foundWriteExpr = false, i = 0;i < ref.references.length; i++) {
132960
- var reference = ref.references[i];
132961
- if (reference.writeExpr)
134408
+ if (constantExpressionType) {
134409
+ return [ref, constantExpressionType];
134410
+ }
134411
+ }
134412
+ if (node.type === "FunctionName" && node.node.type === "FunctionDeclaration") {
134413
+ return [ref, "function"];
134414
+ }
134415
+ if (node.type === "ClassName" && node.node.type === "ClassDeclaration") {
134416
+ return [ref, "class"];
134417
+ }
134418
+ return null;
134419
+ }).filter(Boolean);
134420
+ function isUsedOutsideOfHook(ref) {
134421
+ var e_15, _a2;
134422
+ var foundWriteExpr = false;
134423
+ try {
134424
+ for (var _b = __values(ref.references), _c = _b.next();!_c.done; _c = _b.next()) {
134425
+ var reference = _c.value;
134426
+ if (reference.writeExpr) {
132962
134427
  if (foundWriteExpr) {
132963
- ref = true;
132964
- break a;
134428
+ return true;
132965
134429
  } else {
132966
134430
  foundWriteExpr = true;
132967
134431
  continue;
132968
134432
  }
132969
- for (var currentScope = reference.from;currentScope !== scope && currentScope != null; )
134433
+ }
134434
+ var currentScope = reference.from;
134435
+ while (currentScope !== scope && currentScope != null) {
132970
134436
  currentScope = currentScope.upper;
132971
- if (currentScope !== scope && !isAncestorNodeOf(declaredDependenciesNode, reference.identifier)) {
132972
- ref = true;
132973
- break a;
134437
+ }
134438
+ if (currentScope !== scope) {
134439
+ if (!isAncestorNodeOf(declaredDependenciesNode, reference.identifier)) {
134440
+ return true;
134441
+ }
132974
134442
  }
132975
134443
  }
132976
- ref = false;
134444
+ } catch (e_15_1) {
134445
+ e_15 = { error: e_15_1 };
134446
+ } finally {
134447
+ try {
134448
+ if (_c && !_c.done && (_a2 = _b.return))
134449
+ _a2.call(_b);
134450
+ } finally {
134451
+ if (e_15)
134452
+ throw e_15.error;
134453
+ }
132977
134454
  }
134455
+ return false;
134456
+ }
134457
+ return constructions.map(function(_a2) {
134458
+ var _b = __read(_a2, 2), ref = _b[0], depType = _b[1];
132978
134459
  return {
132979
- construction: JSCompiler_temp_const,
132980
- depType: _ref11,
132981
- isUsedOutsideOfHook: ref
134460
+ construction: ref.defs[0],
134461
+ depType,
134462
+ isUsedOutsideOfHook: isUsedOutsideOfHook(ref)
132982
134463
  };
132983
134464
  });
132984
134465
  }
132985
134466
  function getDependency(node) {
132986
- return 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 ? node.type === "MemberExpression" && node.parent && node.parent.type === "AssignmentExpression" && node.parent.left === node ? node.object : node : getDependency(node.parent);
134467
+ if (node.parent && (node.parent.type === "MemberExpression" || node.parent.type === "OptionalMemberExpression") && node.parent.object === node && "name" in node.parent.property && 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)) {
134468
+ return getDependency(node.parent);
134469
+ } else if (node.type === "MemberExpression" && node.parent && node.parent.type === "AssignmentExpression" && node.parent.left === node) {
134470
+ return node.object;
134471
+ } else {
134472
+ return node;
134473
+ }
132987
134474
  }
132988
134475
  function markNode(node, optionalChains, result) {
132989
- optionalChains && (node.optional ? optionalChains.has(result) || optionalChains.set(result, true) : optionalChains.set(result, false));
134476
+ if (optionalChains) {
134477
+ if ("optional" in node && node.optional) {
134478
+ if (!optionalChains.has(result)) {
134479
+ optionalChains.set(result, true);
134480
+ }
134481
+ } else {
134482
+ optionalChains.set(result, false);
134483
+ }
134484
+ }
132990
134485
  }
132991
134486
  function analyzePropertyChain(node, optionalChains) {
132992
- if (node.type === "Identifier" || node.type === "JSXIdentifier")
132993
- return node = node.name, optionalChains && optionalChains.set(node, false), node;
132994
- if (node.type !== "MemberExpression" || node.computed) {
132995
- if (node.type !== "OptionalMemberExpression" || node.computed) {
132996
- if (node.type !== "ChainExpression" || node.computed)
132997
- throw Error("Unsupported node type: " + node.type);
132998
- node = node.expression;
132999
- if (node.type === "CallExpression")
133000
- throw Error("Unsupported node type: " + node.type);
133001
- var object$20 = analyzePropertyChain(node.object, optionalChains), property$21 = analyzePropertyChain(node.property, null);
133002
- object$20 = object$20 + "." + property$21;
133003
- markNode(node, optionalChains, object$20);
133004
- return object$20;
133005
- }
133006
- object$20 = analyzePropertyChain(node.object, optionalChains);
133007
- property$21 = analyzePropertyChain(node.property, null);
133008
- object$20 = object$20 + "." + property$21;
133009
- markNode(node, optionalChains, object$20);
133010
- return object$20;
133011
- }
133012
- object$20 = analyzePropertyChain(node.object, optionalChains);
133013
- property$21 = analyzePropertyChain(node.property, null);
133014
- object$20 = object$20 + "." + property$21;
133015
- markNode(node, optionalChains, object$20);
133016
- return object$20;
134487
+ if (node.type === "Identifier" || node.type === "JSXIdentifier") {
134488
+ var result = node.name;
134489
+ if (optionalChains) {
134490
+ optionalChains.set(result, false);
134491
+ }
134492
+ return result;
134493
+ } else if (node.type === "MemberExpression" && !node.computed) {
134494
+ var object = analyzePropertyChain(node.object, optionalChains);
134495
+ var property = analyzePropertyChain(node.property, null);
134496
+ var result = "".concat(object, ".").concat(property);
134497
+ markNode(node, optionalChains, result);
134498
+ return result;
134499
+ } else if (node.type === "OptionalMemberExpression" && !node.computed) {
134500
+ var object = analyzePropertyChain(node.object, optionalChains);
134501
+ var property = analyzePropertyChain(node.property, null);
134502
+ var result = "".concat(object, ".").concat(property);
134503
+ markNode(node, optionalChains, result);
134504
+ return result;
134505
+ } else if (node.type === "ChainExpression" && (!("computed" in node) || !node.computed)) {
134506
+ var expression = node.expression;
134507
+ if (expression.type === "CallExpression") {
134508
+ throw new Error("Unsupported node type: ".concat(expression.type));
134509
+ }
134510
+ var object = analyzePropertyChain(expression.object, optionalChains);
134511
+ var property = analyzePropertyChain(expression.property, null);
134512
+ var result = "".concat(object, ".").concat(property);
134513
+ markNode(expression, optionalChains, result);
134514
+ return result;
134515
+ } else {
134516
+ throw new Error("Unsupported node type: ".concat(node.type));
134517
+ }
133017
134518
  }
133018
134519
  function getNodeWithoutReactNamespace(node) {
133019
- return node.type !== "MemberExpression" || node.object.type !== "Identifier" || node.object.name !== "React" || node.property.type !== "Identifier" || node.computed ? node : node.property;
134520
+ if (node.type === "MemberExpression" && node.object.type === "Identifier" && node.object.name === "React" && node.property.type === "Identifier" && !node.computed) {
134521
+ return node.property;
134522
+ }
134523
+ return node;
133020
134524
  }
133021
134525
  function getReactiveHookCallbackIndex(calleeNode, options) {
133022
134526
  var node = getNodeWithoutReactNamespace(calleeNode);
133023
- if (node.type !== "Identifier")
134527
+ if (node.type !== "Identifier") {
133024
134528
  return -1;
134529
+ }
133025
134530
  switch (node.name) {
133026
134531
  case "useEffect":
133027
134532
  case "useLayoutEffect":
@@ -133032,893 +134537,132 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
133032
134537
  return 1;
133033
134538
  default:
133034
134539
  if (node === calleeNode && options && options.additionalHooks) {
134540
+ var name = undefined;
133035
134541
  try {
133036
- var name = analyzePropertyChain(node, null);
134542
+ name = analyzePropertyChain(node, null);
133037
134543
  } catch (error) {
133038
- if (/Unsupported node type/.test(error.message))
134544
+ if (error instanceof Error && /Unsupported node type/.test(error.message)) {
133039
134545
  return 0;
133040
- throw error;
134546
+ } else {
134547
+ throw error;
134548
+ }
133041
134549
  }
133042
134550
  return options.additionalHooks.test(name) ? 0 : -1;
134551
+ } else {
134552
+ return -1;
133043
134553
  }
133044
- return -1;
133045
134554
  }
133046
134555
  }
133047
134556
  function fastFindReferenceWithParent(start, target) {
133048
- for (var queue = [start], item = null;queue.length; ) {
134557
+ var e_16, _a;
134558
+ var queue = [start];
134559
+ var item;
134560
+ while (queue.length) {
133049
134561
  item = queue.shift();
133050
- if ((item.type === "Identifier" || item.type === "JSXIdentifier") && item.type === target.type && item.name === target.name && item.range[0] === target.range[0] && item.range[1] === target.range[1])
134562
+ if (isSameIdentifier(item, target)) {
133051
134563
  return item;
133052
- if (isAncestorNodeOf(item, target)) {
133053
- start = 0;
133054
- for (var _Object$entries = Object.entries(item);start < _Object$entries.length; start++) {
133055
- var _Object$entries$_i = _Object$entries[start], value2 = _Object$entries$_i[1];
133056
- _Object$entries$_i[0] !== "parent" && (isNodeLike(value2) ? (value2.parent = item, queue.push(value2)) : Array.isArray(value2) && value2.forEach(function(val) {
133057
- isNodeLike(val) && (val.parent = item, queue.push(val));
133058
- }));
134564
+ }
134565
+ if (!isAncestorNodeOf(item, target)) {
134566
+ continue;
134567
+ }
134568
+ try {
134569
+ for (var _b = (e_16 = undefined, __values(Object.entries(item))), _c = _b.next();!_c.done; _c = _b.next()) {
134570
+ var _d = __read(_c.value, 2), key = _d[0], value2 = _d[1];
134571
+ if (key === "parent") {
134572
+ continue;
134573
+ }
134574
+ if (isNodeLike(value2)) {
134575
+ value2.parent = item;
134576
+ queue.push(value2);
134577
+ } else if (Array.isArray(value2)) {
134578
+ value2.forEach(function(val) {
134579
+ if (isNodeLike(val)) {
134580
+ val.parent = item;
134581
+ queue.push(val);
134582
+ }
134583
+ });
134584
+ }
134585
+ }
134586
+ } catch (e_16_1) {
134587
+ e_16 = { error: e_16_1 };
134588
+ } finally {
134589
+ try {
134590
+ if (_c && !_c.done && (_a = _b.return))
134591
+ _a.call(_b);
134592
+ } finally {
134593
+ if (e_16)
134594
+ throw e_16.error;
133059
134595
  }
133060
134596
  }
133061
134597
  }
133062
134598
  return null;
133063
134599
  }
133064
134600
  function joinEnglish(arr) {
133065
- for (var s = "", i = 0;i < arr.length; i++)
133066
- s += arr[i], i === 0 && arr.length === 2 ? s += " and " : i === arr.length - 2 && 2 < arr.length ? s += ", and " : i < arr.length - 1 && (s += ", ");
134601
+ var s = "";
134602
+ for (var i = 0;i < arr.length; i++) {
134603
+ s += arr[i];
134604
+ if (i === 0 && arr.length === 2) {
134605
+ s += " and ";
134606
+ } else if (i === arr.length - 2 && arr.length > 2) {
134607
+ s += ", and ";
134608
+ } else if (i < arr.length - 1) {
134609
+ s += ", ";
134610
+ }
134611
+ }
133067
134612
  return s;
133068
134613
  }
133069
134614
  function isNodeLike(val) {
133070
- return typeof val === "object" && val !== null && !Array.isArray(val) && typeof val.type === "string";
134615
+ return typeof val === "object" && val !== null && !Array.isArray(val) && "type" in val && typeof val.type === "string";
134616
+ }
134617
+ function isSameIdentifier(a, b) {
134618
+ return (a.type === "Identifier" || a.type === "JSXIdentifier") && a.type === b.type && a.name === b.name && !!a.range && !!b.range && a.range[0] === b.range[0] && a.range[1] === b.range[1];
133071
134619
  }
133072
134620
  function isAncestorNodeOf(a, b) {
133073
- return a.range[0] <= b.range[0] && a.range[1] >= b.range[1];
134621
+ return !!a.range && !!b.range && a.range[0] <= b.range[0] && a.range[1] >= b.range[1];
134622
+ }
134623
+ function isUseEffectEventIdentifier(node) {
134624
+ return false;
133074
134625
  }
133075
134626
  function getUnknownDependenciesMessage(reactiveHookName) {
133076
- return "React Hook " + reactiveHookName + " received a function whose dependencies are unknown. Pass an inline function instead.";
134627
+ return "React Hook ".concat(reactiveHookName, " received a function whose dependencies ") + "are unknown. Pass an inline function instead.";
133077
134628
  }
133078
134629
  var rules = {
133079
- "rules-of-hooks": {
133080
- meta: {
133081
- type: "problem",
133082
- docs: {
133083
- description: "enforces the Rules of Hooks",
133084
- recommended: true,
133085
- url: "https://reactjs.org/docs/hooks-rules.html"
133086
- }
133087
- },
133088
- create: function(context) {
133089
- function recordAllUseEffectEventFunctions(scope) {
133090
- scope = _createForOfIteratorHelper(scope.references);
133091
- try {
133092
- for (scope.s();!scope.n().done; )
133093
- ;
133094
- } catch (err$1) {
133095
- scope.e(err$1);
133096
- } finally {
133097
- scope.f();
133098
- }
133099
- }
133100
- var lastEffect = null, codePathReactHooksMapStack = [], codePathSegmentStack = [], useEffectEventFunctions = new WeakSet, getSource = typeof context.getSource === "function" ? function(node) {
133101
- return context.getSource(node);
133102
- } : function(node) {
133103
- return context.sourceCode.getText(node);
133104
- }, getScope = typeof context.getScope === "function" ? function() {
133105
- return context.getScope();
133106
- } : function(node) {
133107
- return context.sourceCode.getScope(node);
133108
- }, $jscomp$compprop0 = {};
133109
- return $jscomp$compprop0.onCodePathSegmentStart = function(segment) {
133110
- return codePathSegmentStack.push(segment);
133111
- }, $jscomp$compprop0.onCodePathSegmentEnd = function() {
133112
- return codePathSegmentStack.pop();
133113
- }, $jscomp$compprop0.onCodePathStart = function() {
133114
- return codePathReactHooksMapStack.push(new Map);
133115
- }, $jscomp$compprop0.onCodePathEnd = function(codePath, codePathNode) {
133116
- function countPathsFromStart(segment, pathHistory) {
133117
- var cache = countPathsFromStart.cache, paths = cache.get(segment.id);
133118
- pathHistory = new Set(pathHistory);
133119
- if (pathHistory.has(segment.id)) {
133120
- cache = [].concat(pathHistory);
133121
- segment = cache.slice(cache.indexOf(segment.id) + 1);
133122
- segment = _createForOfIteratorHelper(segment);
133123
- var _step3;
133124
- try {
133125
- for (segment.s();!(_step3 = segment.n()).done; )
133126
- cyclic.add(_step3.value);
133127
- } catch (err) {
133128
- segment.e(err);
133129
- } finally {
133130
- segment.f();
133131
- }
133132
- return BigInt("0");
133133
- }
133134
- pathHistory.add(segment.id);
133135
- if (paths !== undefined)
133136
- return paths;
133137
- if (codePath.thrownSegments.includes(segment))
133138
- paths = BigInt("0");
133139
- else if (segment.prevSegments.length === 0)
133140
- paths = BigInt("1");
133141
- else {
133142
- paths = BigInt("0");
133143
- _step3 = _createForOfIteratorHelper(segment.prevSegments);
133144
- var _step4;
133145
- try {
133146
- for (_step3.s();!(_step4 = _step3.n()).done; )
133147
- paths += countPathsFromStart(_step4.value, pathHistory);
133148
- } catch (err$2) {
133149
- _step3.e(err$2);
133150
- } finally {
133151
- _step3.f();
133152
- }
133153
- }
133154
- segment.reachable && paths === BigInt("0") ? cache.delete(segment.id) : cache.set(segment.id, paths);
133155
- return paths;
133156
- }
133157
- function countPathsToEnd(segment, pathHistory) {
133158
- var cache = countPathsToEnd.cache, paths = cache.get(segment.id);
133159
- pathHistory = new Set(pathHistory);
133160
- if (pathHistory.has(segment.id)) {
133161
- cache = Array.from(pathHistory);
133162
- segment = cache.slice(cache.indexOf(segment.id) + 1);
133163
- segment = _createForOfIteratorHelper(segment);
133164
- var _step5;
133165
- try {
133166
- for (segment.s();!(_step5 = segment.n()).done; )
133167
- cyclic.add(_step5.value);
133168
- } catch (err) {
133169
- segment.e(err);
133170
- } finally {
133171
- segment.f();
133172
- }
133173
- return BigInt("0");
133174
- }
133175
- pathHistory.add(segment.id);
133176
- if (paths !== undefined)
133177
- return paths;
133178
- if (codePath.thrownSegments.includes(segment))
133179
- paths = BigInt("0");
133180
- else if (segment.nextSegments.length === 0)
133181
- paths = BigInt("1");
133182
- else {
133183
- paths = BigInt("0");
133184
- _step5 = _createForOfIteratorHelper(segment.nextSegments);
133185
- var _step6;
133186
- try {
133187
- for (_step5.s();!(_step6 = _step5.n()).done; )
133188
- paths += countPathsToEnd(_step6.value, pathHistory);
133189
- } catch (err$3) {
133190
- _step5.e(err$3);
133191
- } finally {
133192
- _step5.f();
133193
- }
133194
- }
133195
- cache.set(segment.id, paths);
133196
- return paths;
133197
- }
133198
- function shortestPathLengthToStart(segment) {
133199
- var cache = shortestPathLengthToStart.cache, length = cache.get(segment.id);
133200
- if (length === null)
133201
- return Infinity;
133202
- if (length !== undefined)
133203
- return length;
133204
- cache.set(segment.id, null);
133205
- if (segment.prevSegments.length === 0)
133206
- length = 1;
133207
- else {
133208
- length = Infinity;
133209
- var _iterator7 = _createForOfIteratorHelper(segment.prevSegments), _step7;
133210
- try {
133211
- for (_iterator7.s();!(_step7 = _iterator7.n()).done; ) {
133212
- var prevLength = shortestPathLengthToStart(_step7.value);
133213
- prevLength < length && (length = prevLength);
133214
- }
133215
- } catch (err) {
133216
- _iterator7.e(err);
133217
- } finally {
133218
- _iterator7.f();
133219
- }
133220
- length += 1;
133221
- }
133222
- cache.set(segment.id, length);
133223
- return length;
133224
- }
133225
- var reactHooksMap = codePathReactHooksMapStack.pop();
133226
- if (reactHooksMap.size !== 0) {
133227
- var cyclic = new Set;
133228
- countPathsFromStart.cache = new Map;
133229
- countPathsToEnd.cache = new Map;
133230
- shortestPathLengthToStart.cache = new Map;
133231
- var allPathsFromStartToEnd = countPathsToEnd(codePath.initialSegment), codePathFunctionName = getFunctionName(codePathNode), isSomewhereInsideComponentOrHook = isInsideComponentOrHook(codePathNode), isDirectlyInsideComponentOrHook = codePathFunctionName ? isComponentName(codePathFunctionName) || isHook(codePathFunctionName) : isForwardRefCallback(codePathNode) || isMemoCallback(codePathNode), shortestFinalPathLength = Infinity, _iterator8 = _createForOfIteratorHelper(codePath.finalSegments), _step8;
133232
- try {
133233
- for (_iterator8.s();!(_step8 = _iterator8.n()).done; ) {
133234
- var finalSegment = _step8.value;
133235
- if (finalSegment.reachable) {
133236
- var length$jscomp$0 = shortestPathLengthToStart(finalSegment);
133237
- length$jscomp$0 < shortestFinalPathLength && (shortestFinalPathLength = length$jscomp$0);
133238
- }
133239
- }
133240
- } catch (err) {
133241
- _iterator8.e(err);
133242
- } finally {
133243
- _iterator8.f();
133244
- }
133245
- reactHooksMap = _createForOfIteratorHelper(reactHooksMap);
133246
- var _step9;
133247
- try {
133248
- for (reactHooksMap.s();!(_step9 = reactHooksMap.n()).done; ) {
133249
- var _step9$value = _step9.value, segment$jscomp$0 = _step9$value[0], reactHooks = _step9$value[1];
133250
- if (segment$jscomp$0.reachable) {
133251
- var possiblyHasEarlyReturn = segment$jscomp$0.nextSegments.length === 0 ? shortestFinalPathLength <= shortestPathLengthToStart(segment$jscomp$0) : shortestFinalPathLength < shortestPathLengthToStart(segment$jscomp$0), pathsFromStartToEnd = countPathsFromStart(segment$jscomp$0) * countPathsToEnd(segment$jscomp$0), cycled = cyclic.has(segment$jscomp$0.id), _iterator10 = _createForOfIteratorHelper(reactHooks), _step10;
133252
- try {
133253
- for (_iterator10.s();!(_step10 = _iterator10.n()).done; ) {
133254
- var hook = _step10.value;
133255
- !cycled && !isInsideDoWhileLoop(hook) || isReactFunction(hook, "use") || context.report({
133256
- node: hook,
133257
- message: 'React Hook "' + getSource(hook) + '" 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.'
133258
- });
133259
- if (isDirectlyInsideComponentOrHook) {
133260
- if (codePathNode.async && context.report({
133261
- node: hook,
133262
- message: 'React Hook "' + getSource(hook) + '" cannot be called in an async function.'
133263
- }), !cycled && pathsFromStartToEnd !== allPathsFromStartToEnd && !isReactFunction(hook, "use") && !isInsideDoWhileLoop(hook)) {
133264
- var message = 'React Hook "' + getSource(hook) + '" is called conditionally. React Hooks must be called in the exact same order in every component render.' + (possiblyHasEarlyReturn ? " Did you accidentally call a React Hook after an early return?" : "");
133265
- context.report({ node: hook, message });
133266
- }
133267
- } else if (codePathNode.parent && (codePathNode.parent.type === "MethodDefinition" || codePathNode.parent.type === "ClassProperty" || codePathNode.parent.type === "PropertyDefinition") && codePathNode.parent.value === codePathNode) {
133268
- var message$4 = 'React Hook "' + getSource(hook) + '" cannot be called in a class component. React Hooks must be called in a React function component or a custom React Hook function.';
133269
- context.report({ node: hook, message: message$4 });
133270
- } else if (codePathFunctionName) {
133271
- var message$5 = 'React Hook "' + getSource(hook) + '" is called in function "' + (getSource(codePathFunctionName) + '" that is neither a React function component nor a custom React Hook function. React component names must start with an uppercase letter. React Hook names must start with the word "use".');
133272
- context.report({ node: hook, message: message$5 });
133273
- } else if (codePathNode.type === "Program") {
133274
- var message$6 = 'React Hook "' + getSource(hook) + '" cannot be called at the top level. React Hooks must be called in a React function component or a custom React Hook function.';
133275
- context.report({ node: hook, message: message$6 });
133276
- } else if (isSomewhereInsideComponentOrHook && !isReactFunction(hook, "use")) {
133277
- var message$7 = 'React Hook "' + getSource(hook) + '" cannot be called inside a callback. React Hooks must be called in a React function component or a custom React Hook function.';
133278
- context.report({ node: hook, message: message$7 });
133279
- }
133280
- }
133281
- } catch (err$8) {
133282
- _iterator10.e(err$8);
133283
- } finally {
133284
- _iterator10.f();
133285
- }
133286
- }
133287
- }
133288
- } catch (err$9) {
133289
- reactHooksMap.e(err$9);
133290
- } finally {
133291
- reactHooksMap.f();
133292
- }
133293
- }
133294
- }, $jscomp$compprop0.CallExpression = function(node) {
133295
- if (isHook(node.callee)) {
133296
- var reactHooksMap = codePathReactHooksMapStack[codePathReactHooksMapStack.length - 1], codePathSegment = codePathSegmentStack[codePathSegmentStack.length - 1], reactHooks = reactHooksMap.get(codePathSegment);
133297
- reactHooks || (reactHooks = [], reactHooksMap.set(codePathSegment, reactHooks));
133298
- reactHooks.push(node.callee);
133299
- }
133300
- node.callee.type === "Identifier" && node.callee.name === "useEffect" && 0 < node.arguments.length && (lastEffect = node);
133301
- }, $jscomp$compprop0.Identifier = function(node) {
133302
- lastEffect == null && useEffectEventFunctions.has(node) && node.parent.type !== "CallExpression" && context.report({
133303
- node,
133304
- message: "`" + getSource(node) + '` is a function created with React Hook "useEffectEvent", and can only be called from the same component. They cannot be assigned to variables or passed down.'
133305
- });
133306
- }, $jscomp$compprop0["CallExpression:exit"] = function(node) {
133307
- node === lastEffect && (lastEffect = null);
133308
- }, $jscomp$compprop0.FunctionDeclaration = function(node) {
133309
- isInsideComponentOrHook(node) && recordAllUseEffectEventFunctions(getScope(node));
133310
- }, $jscomp$compprop0.ArrowFunctionExpression = function(node) {
133311
- isInsideComponentOrHook(node) && recordAllUseEffectEventFunctions(getScope(node));
133312
- }, $jscomp$compprop0;
133313
- }
133314
- },
133315
- "exhaustive-deps": {
133316
- meta: {
133317
- type: "suggestion",
133318
- docs: {
133319
- description: "verifies the list of dependencies for Hooks like useEffect and similar",
133320
- recommended: true,
133321
- url: "https://github.com/facebook/react/issues/14920"
133322
- },
133323
- fixable: "code",
133324
- hasSuggestions: true,
133325
- schema: [
133326
- {
133327
- type: "object",
133328
- additionalProperties: false,
133329
- enableDangerousAutofixThisMayCauseInfiniteLoops: false,
133330
- properties: {
133331
- additionalHooks: { type: "string" },
133332
- enableDangerousAutofixThisMayCauseInfiniteLoops: {
133333
- type: "boolean"
133334
- }
133335
- }
133336
- }
133337
- ]
133338
- },
133339
- create: function(context) {
133340
- function reportProblem(problem) {
133341
- enableDangerousAutofixThisMayCauseInfiniteLoops && Array.isArray(problem.suggest) && 0 < problem.suggest.length && (problem.fix = problem.suggest[0].fix);
133342
- context.report(problem);
133343
- }
133344
- function memoizeWithWeakMap(fn, map) {
133345
- return function(arg) {
133346
- if (map.has(arg))
133347
- return map.get(arg);
133348
- var result = fn(arg);
133349
- map.set(arg, result);
133350
- return result;
133351
- };
133352
- }
133353
- function visitFunctionWithDependencies(node, declaredDependenciesNode, reactiveHook, reactiveHookName, isEffect) {
133354
- function gatherDependenciesRecursively(currentScope2) {
133355
- var _iterator2 = _createForOfIteratorHelper(currentScope2.references), _step2;
133356
- try {
133357
- for (_iterator2.s();!(_step2 = _iterator2.n()).done; ) {
133358
- var reference = _step2.value;
133359
- if (reference.resolved && pureScopes.has(reference.resolved.scope)) {
133360
- var referenceNode = fastFindReferenceWithParent(node, reference.identifier), dependencyNode = getDependency(referenceNode), dependency = analyzePropertyChain(dependencyNode, optionalChains), JSCompiler_temp;
133361
- if (JSCompiler_temp = isEffect && dependencyNode.type === "Identifier" && (dependencyNode.parent.type === "MemberExpression" || dependencyNode.parent.type === "OptionalMemberExpression") && !dependencyNode.parent.computed && dependencyNode.parent.property.type === "Identifier" && dependencyNode.parent.property.name === "current") {
133362
- for (var curScope = reference.from, isInReturnedFunction = false;curScope.block !== node; )
133363
- curScope.type === "function" && (isInReturnedFunction = curScope.block.parent != null && curScope.block.parent.type === "ReturnStatement"), curScope = curScope.upper;
133364
- JSCompiler_temp = isInReturnedFunction;
133365
- }
133366
- JSCompiler_temp && currentRefsInEffectCleanup.set(dependency, {
133367
- reference,
133368
- dependencyNode
133369
- });
133370
- if (dependencyNode.parent.type !== "TSTypeQuery" && dependencyNode.parent.type !== "TSTypeReference") {
133371
- var def = reference.resolved.defs[0];
133372
- if (def != null && (def.node == null || def.node.init !== node.parent) && def.type !== "TypeParameter")
133373
- if (dependencies.has(dependency))
133374
- dependencies.get(dependency).references.push(reference);
133375
- else {
133376
- var resolved = reference.resolved, isStable = memoizedIsStableKnownHookValue(resolved) || memoizedIsFunctionWithoutCapturedValues(resolved);
133377
- dependencies.set(dependency, {
133378
- isStable,
133379
- references: [reference]
133380
- });
133381
- }
133382
- }
133383
- }
133384
- }
133385
- } catch (err) {
133386
- _iterator2.e(err);
133387
- } finally {
133388
- _iterator2.f();
133389
- }
133390
- currentScope2 = _createForOfIteratorHelper(currentScope2.childScopes);
133391
- var _step3;
133392
- try {
133393
- for (currentScope2.s();!(_step3 = currentScope2.n()).done; )
133394
- gatherDependenciesRecursively(_step3.value);
133395
- } catch (err$12) {
133396
- currentScope2.e(err$12);
133397
- } finally {
133398
- currentScope2.f();
133399
- }
133400
- }
133401
- function formatDependency(path) {
133402
- path = path.split(".");
133403
- for (var finalPath = "", i = 0;i < path.length; i++) {
133404
- if (i !== 0) {
133405
- var pathSoFar = path.slice(0, i + 1).join(".");
133406
- pathSoFar = optionalChains.get(pathSoFar) === true;
133407
- finalPath += pathSoFar ? "?." : ".";
133408
- }
133409
- finalPath += path[i];
133410
- }
133411
- return finalPath;
133412
- }
133413
- function getWarningMessage(deps, singlePrefix, label, fixVerb) {
133414
- return deps.size === 0 ? null : (1 < deps.size ? "" : singlePrefix + " ") + label + " " + (1 < deps.size ? "dependencies" : "dependency") + ": " + joinEnglish(Array.from(deps).sort().map(function(name) {
133415
- return "'" + formatDependency(name) + "'";
133416
- })) + (". Either " + fixVerb + " " + (1 < deps.size ? "them" : "it") + " or remove the dependency array.");
133417
- }
133418
- isEffect && node.async && reportProblem({
133419
- node,
133420
- message: `Effect callbacks are synchronous to prevent race conditions. Put the async function inside:
133421
-
133422
- useEffect(() => {
133423
- async function fetchData() {
133424
- // You can await here
133425
- const response = await MyAPI.getData(someId);
133426
- // ...
133427
- }
133428
- fetchData();
133429
- }, [someId]); // Or [] if effect doesn't need props or state
133430
-
133431
- Learn more about data fetching with Hooks: https://react.dev/link/hooks-data-fetching`
133432
- });
133433
- for (var scope = scopeManager.acquire(node), pureScopes = new Set, componentScope = null, currentScope = scope.upper;currentScope; ) {
133434
- pureScopes.add(currentScope);
133435
- if (currentScope.type === "function")
133436
- break;
133437
- currentScope = currentScope.upper;
133438
- }
133439
- if (currentScope) {
133440
- componentScope = currentScope;
133441
- var isArray = Array.isArray, memoizedIsStableKnownHookValue = memoizeWithWeakMap(function(resolved) {
133442
- if (!isArray(resolved.defs))
133443
- return false;
133444
- var def = resolved.defs[0];
133445
- if (def == null || def.node.type !== "VariableDeclarator")
133446
- return false;
133447
- var init = def.node.init;
133448
- if (init == null)
133449
- return false;
133450
- for (;init.type === "TSAsExpression" || init.type === "AsExpression"; )
133451
- init = init.expression;
133452
- var declaration = def.node.parent;
133453
- if (declaration == null && (fastFindReferenceWithParent(componentScope.block, def.node.id), declaration = def.node.parent, declaration == null))
133454
- return false;
133455
- if (declaration.kind === "const" && init.type === "Literal" && (typeof init.value === "string" || typeof init.value === "number" || init.value === null))
133456
- return true;
133457
- if (init.type !== "CallExpression")
133458
- return false;
133459
- init = init.callee;
133460
- init.type !== "MemberExpression" || init.object.name !== "React" || init.property == null || init.computed || (init = init.property);
133461
- if (init.type !== "Identifier")
133462
- return false;
133463
- def = def.node.id;
133464
- init = init.name;
133465
- if (init === "useRef" && def.type === "Identifier")
133466
- return true;
133467
- if (init === "useState" || init === "useReducer" || init === "useActionState") {
133468
- if (def.type === "ArrayPattern" && def.elements.length === 2 && isArray(resolved.identifiers)) {
133469
- if (def.elements[1] === resolved.identifiers[0]) {
133470
- if (init === "useState")
133471
- for (resolved = resolved.references, declaration = init = 0;declaration < resolved.length; declaration++) {
133472
- resolved[declaration].isWrite() && init++;
133473
- if (1 < init)
133474
- return false;
133475
- setStateCallSites.set(resolved[declaration].identifier, def.elements[0]);
133476
- }
133477
- return true;
133478
- }
133479
- if (def.elements[0] === resolved.identifiers[0] && init === "useState")
133480
- for (resolved = resolved.references, def = 0;def < resolved.length; def++)
133481
- stateVariables.add(resolved[def].identifier);
133482
- }
133483
- } else if (init === "useTransition" && def.type === "ArrayPattern" && def.elements.length === 2 && Array.isArray(resolved.identifiers) && def.elements[1] === resolved.identifiers[0])
133484
- return true;
133485
- return false;
133486
- }, stableKnownValueCache), memoizedIsFunctionWithoutCapturedValues = memoizeWithWeakMap(function(resolved) {
133487
- if (!isArray(resolved.defs))
133488
- return false;
133489
- resolved = resolved.defs[0];
133490
- if (resolved == null || resolved.node == null || resolved.node.id == null)
133491
- return false;
133492
- var fnNode = resolved.node, childScopes = componentScope.childScopes;
133493
- resolved = null;
133494
- var i;
133495
- for (i = 0;i < childScopes.length; i++) {
133496
- var childScope = childScopes[i], childScopeBlock = childScope.block;
133497
- if (fnNode.type === "FunctionDeclaration" && childScopeBlock === fnNode || fnNode.type === "VariableDeclarator" && childScopeBlock.parent === fnNode) {
133498
- resolved = childScope;
133499
- break;
133500
- }
133501
- }
133502
- if (resolved == null)
133503
- return false;
133504
- for (i = 0;i < resolved.through.length; i++)
133505
- if (fnNode = resolved.through[i], fnNode.resolved != null && pureScopes.has(fnNode.resolved.scope) && !memoizedIsStableKnownHookValue(fnNode.resolved))
133506
- return false;
133507
- return true;
133508
- }, functionWithoutCapturedValueCache), currentRefsInEffectCleanup = new Map, dependencies = new Map, optionalChains = new Map;
133509
- gatherDependenciesRecursively(scope);
133510
- currentRefsInEffectCleanup.forEach(function(_ref, dependency) {
133511
- var dependencyNode = _ref.dependencyNode;
133512
- _ref = _ref.reference.resolved.references;
133513
- for (var foundCurrentAssignment = false, i = 0;i < _ref.length; i++) {
133514
- var parent = _ref[i].identifier.parent;
133515
- if (parent != null && parent.type === "MemberExpression" && !parent.computed && parent.property.type === "Identifier" && parent.property.name === "current" && parent.parent.type === "AssignmentExpression" && parent.parent.left === parent) {
133516
- foundCurrentAssignment = true;
133517
- break;
133518
- }
133519
- }
133520
- foundCurrentAssignment || reportProblem({
133521
- node: dependencyNode.parent.property,
133522
- message: "The ref value '" + dependency + ".current' will likely have changed by the time this effect cleanup function runs. If this ref points to a node rendered by React, copy '" + (dependency + ".current' to a variable inside the effect, and use that variable in the cleanup function.")
133523
- });
133524
- });
133525
- var staleAssignments = new Set, stableDependencies = new Set;
133526
- dependencies.forEach(function(_ref2, key) {
133527
- var references = _ref2.references;
133528
- _ref2.isStable && stableDependencies.add(key);
133529
- references.forEach(function(reference) {
133530
- reference.writeExpr && (reference = reference.writeExpr, staleAssignments.has(key) || (staleAssignments.add(key), reportProblem({
133531
- node: reference,
133532
- message: "Assignments to the '" + key + "' variable from inside React Hook " + (getSource(reactiveHook) + " 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 ") + (getSource(reactiveHook) + ".")
133533
- })));
133534
- });
133535
- });
133536
- if (!(0 < staleAssignments.size))
133537
- if (declaredDependenciesNode) {
133538
- var declaredDependencies = [], externalDependencies = new Set;
133539
- currentScope = declaredDependenciesNode.type === "TSAsExpression" && declaredDependenciesNode.expression.type === "ArrayExpression";
133540
- declaredDependenciesNode.type === "ArrayExpression" || currentScope ? (currentScope ? declaredDependenciesNode.expression : declaredDependenciesNode).elements.forEach(function(declaredDependencyNode) {
133541
- if (declaredDependencyNode !== null)
133542
- if (declaredDependencyNode.type === "SpreadElement")
133543
- reportProblem({
133544
- node: declaredDependencyNode,
133545
- message: "React Hook " + getSource(reactiveHook) + " has a spread element in its dependency array. This means we can't statically verify whether you've passed the correct dependencies."
133546
- });
133547
- else {
133548
- useEffectEventVariables.has(declaredDependencyNode) && reportProblem({
133549
- node: declaredDependencyNode,
133550
- message: "Functions returned from `useEffectEvent` must not be included in the dependency array. Remove `" + (getSource(declaredDependencyNode) + "` from the list."),
133551
- suggest: [
133552
- {
133553
- desc: "Remove the dependency `" + getSource(declaredDependencyNode) + "`",
133554
- fix: function(fixer) {
133555
- return fixer.removeRange(declaredDependencyNode.range);
133556
- }
133557
- }
133558
- ]
133559
- });
133560
- try {
133561
- var declaredDependency = analyzePropertyChain(declaredDependencyNode, null);
133562
- } catch (error) {
133563
- if (/Unsupported node type/.test(error.message)) {
133564
- declaredDependencyNode.type === "Literal" ? dependencies.has(declaredDependencyNode.value) ? reportProblem({
133565
- node: declaredDependencyNode,
133566
- message: "The " + declaredDependencyNode.raw + " literal is not a valid dependency because it never changes. Did you mean to include " + (declaredDependencyNode.value + " in the array instead?")
133567
- }) : reportProblem({
133568
- node: declaredDependencyNode,
133569
- message: "The " + declaredDependencyNode.raw + " literal is not a valid dependency because it never changes. You can safely remove it."
133570
- }) : reportProblem({
133571
- node: declaredDependencyNode,
133572
- message: "React Hook " + getSource(reactiveHook) + " has a complex expression in the dependency array. Extract it to a separate variable so it can be statically checked."
133573
- });
133574
- return;
133575
- }
133576
- throw error;
133577
- }
133578
- for (var maybeID = declaredDependencyNode;maybeID.type === "MemberExpression" || maybeID.type === "OptionalMemberExpression" || maybeID.type === "ChainExpression"; )
133579
- maybeID = maybeID.object || maybeID.expression.object;
133580
- var isDeclaredInComponent = !componentScope.through.some(function(ref) {
133581
- return ref.identifier === maybeID;
133582
- });
133583
- declaredDependencies.push({
133584
- key: declaredDependency,
133585
- node: declaredDependencyNode
133586
- });
133587
- isDeclaredInComponent || externalDependencies.add(declaredDependency);
133588
- }
133589
- }) : reportProblem({
133590
- node: declaredDependenciesNode,
133591
- message: "React Hook " + getSource(reactiveHook) + " 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."
133592
- });
133593
- var _collectRecommendatio2 = collectRecommendations({
133594
- dependencies,
133595
- declaredDependencies,
133596
- stableDependencies,
133597
- externalDependencies,
133598
- isEffect
133599
- });
133600
- currentScope = _collectRecommendatio2.unnecessaryDependencies;
133601
- var { missingDependencies, duplicateDependencies, suggestedDependencies: suggestedDeps } = _collectRecommendatio2;
133602
- if (duplicateDependencies.size + missingDependencies.size + currentScope.size === 0)
133603
- scanForConstructions({
133604
- declaredDependencies,
133605
- declaredDependenciesNode,
133606
- componentScope,
133607
- scope
133608
- }).forEach(function(_ref4) {
133609
- var { construction, isUsedOutsideOfHook } = _ref4;
133610
- _ref4 = _ref4.depType;
133611
- var wrapperHook = _ref4 === "function" ? "useCallback" : "useMemo", constructionType = _ref4 === "function" ? "definition" : "initialization", defaultAdvice = "wrap the " + constructionType + " of '" + construction.name.name + "' in its own " + wrapperHook + "() Hook.";
133612
- defaultAdvice = "The '" + construction.name.name + "' " + _ref4 + " " + (_ref4 === "conditional" || _ref4 === "logical expression" ? "could make" : "makes") + " the dependencies of " + (reactiveHookName + " Hook (at line " + declaredDependenciesNode.loc.start.line + ") change on every render. ") + (isUsedOutsideOfHook ? "To fix this, " + defaultAdvice : "Move it inside the " + reactiveHookName + " callback. Alternatively, " + defaultAdvice);
133613
- var suggest;
133614
- isUsedOutsideOfHook && construction.type === "Variable" && _ref4 === "function" && (suggest = [
133615
- {
133616
- desc: "Wrap the " + constructionType + " of '" + construction.name.name + "' in its own " + wrapperHook + "() Hook.",
133617
- fix: function(fixer) {
133618
- var _ref5 = wrapperHook === "useMemo" ? ["useMemo(() => { return ", "; })"] : ["useCallback(", ")"], after = _ref5[1];
133619
- return [
133620
- fixer.insertTextBefore(construction.node.init, _ref5[0]),
133621
- fixer.insertTextAfter(construction.node.init, after)
133622
- ];
133623
- }
133624
- }
133625
- ]);
133626
- reportProblem({
133627
- node: construction.node,
133628
- message: defaultAdvice,
133629
- suggest
133630
- });
133631
- });
133632
- else {
133633
- !isEffect && 0 < missingDependencies.size && (suggestedDeps = collectRecommendations({
133634
- dependencies,
133635
- declaredDependencies: [],
133636
- stableDependencies,
133637
- externalDependencies,
133638
- isEffect
133639
- }).suggestedDependencies);
133640
- (function() {
133641
- if (declaredDependencies.length === 0)
133642
- return true;
133643
- var declaredDepKeys = declaredDependencies.map(function(dep2) {
133644
- return dep2.key;
133645
- }), sortedDeclaredDepKeys = declaredDepKeys.slice().sort();
133646
- return declaredDepKeys.join(",") === sortedDeclaredDepKeys.join(",");
133647
- })() && suggestedDeps.sort();
133648
- _collectRecommendatio2 = "";
133649
- if (0 < currentScope.size) {
133650
- var badRef = null;
133651
- Array.from(currentScope.keys()).forEach(function(key) {
133652
- badRef === null && key.endsWith(".current") && (badRef = key);
133653
- });
133654
- if (badRef !== null)
133655
- _collectRecommendatio2 = " Mutable values like '" + badRef + "' aren't valid dependencies because mutating them doesn't re-render the component.";
133656
- else if (0 < externalDependencies.size) {
133657
- var dep = Array.from(externalDependencies)[0];
133658
- scope.set.has(dep) || (_collectRecommendatio2 = " Outer scope values like '" + dep + "' aren't valid dependencies because mutating them doesn't re-render the component.");
133659
- }
133660
- }
133661
- if (!_collectRecommendatio2 && missingDependencies.has("props")) {
133662
- scope = dependencies.get("props");
133663
- if (scope == null)
133664
- return;
133665
- scope = scope.references;
133666
- if (!Array.isArray(scope))
133667
- return;
133668
- dep = true;
133669
- for (var i$jscomp$0 = 0;i$jscomp$0 < scope.length; i$jscomp$0++) {
133670
- var id = fastFindReferenceWithParent(componentScope.block, scope[i$jscomp$0].identifier);
133671
- if (!id) {
133672
- dep = false;
133673
- break;
133674
- }
133675
- id = id.parent;
133676
- if (id == null) {
133677
- dep = false;
133678
- break;
133679
- }
133680
- if (id.type !== "MemberExpression" && id.type !== "OptionalMemberExpression") {
133681
- dep = false;
133682
- break;
133683
- }
133684
- }
133685
- dep && (_collectRecommendatio2 = " However, 'props' will change when *any* prop changes, so the preferred fix is to destructure the 'props' object outside of the " + (reactiveHookName + " call and refer to those specific props inside ") + (getSource(reactiveHook) + "."));
133686
- }
133687
- if (!_collectRecommendatio2 && 0 < missingDependencies.size) {
133688
- var missingCallbackDep = null;
133689
- missingDependencies.forEach(function(missingDep) {
133690
- if (!missingCallbackDep) {
133691
- var topScopeRef = componentScope.set.get(missingDep), usedDep = dependencies.get(missingDep);
133692
- if (usedDep.references[0].resolved === topScopeRef && (topScopeRef = topScopeRef.defs[0], topScopeRef != null && topScopeRef.name != null && topScopeRef.type === "Parameter")) {
133693
- topScopeRef = false;
133694
- for (var id2, i$14 = 0;i$14 < usedDep.references.length; i$14++)
133695
- if (id2 = usedDep.references[i$14].identifier, id2 != null && id2.parent != null && (id2.parent.type === "CallExpression" || id2.parent.type === "OptionalCallExpression") && id2.parent.callee === id2) {
133696
- topScopeRef = true;
133697
- break;
133698
- }
133699
- topScopeRef && (missingCallbackDep = missingDep);
133700
- }
133701
- }
133702
- });
133703
- missingCallbackDep !== null && (_collectRecommendatio2 = " If '" + missingCallbackDep + "' changes too often, find the parent component that defines it and wrap that definition in useCallback.");
133704
- }
133705
- if (!_collectRecommendatio2 && 0 < missingDependencies.size) {
133706
- var setStateRecommendation = null;
133707
- missingDependencies.forEach(function(missingDep) {
133708
- if (setStateRecommendation === null)
133709
- for (var references = dependencies.get(missingDep).references, id2, maybeCall, i$15 = 0;i$15 < references.length; i$15++) {
133710
- id2 = references[i$15].identifier;
133711
- for (maybeCall = id2.parent;maybeCall != null && maybeCall !== componentScope.block; ) {
133712
- if (maybeCall.type === "CallExpression") {
133713
- var correspondingStateVariable = setStateCallSites.get(maybeCall.callee);
133714
- if (correspondingStateVariable != null) {
133715
- correspondingStateVariable.name === missingDep ? setStateRecommendation = {
133716
- missingDep,
133717
- setter: maybeCall.callee.name,
133718
- form: "updater"
133719
- } : stateVariables.has(id2) ? setStateRecommendation = {
133720
- missingDep,
133721
- setter: maybeCall.callee.name,
133722
- form: "reducer"
133723
- } : (id2 = references[i$15].resolved, id2 != null && (id2 = id2.defs[0], id2 != null && id2.type === "Parameter" && (setStateRecommendation = {
133724
- missingDep,
133725
- setter: maybeCall.callee.name,
133726
- form: "inlineReducer"
133727
- })));
133728
- break;
133729
- }
133730
- }
133731
- maybeCall = maybeCall.parent;
133732
- }
133733
- if (setStateRecommendation !== null)
133734
- break;
133735
- }
133736
- });
133737
- if (setStateRecommendation !== null)
133738
- switch (setStateRecommendation.form) {
133739
- case "reducer":
133740
- _collectRecommendatio2 = " You can also replace multiple useState variables with useReducer if '" + (setStateRecommendation.setter + "' needs the current value of '") + (setStateRecommendation.missingDep + "'.");
133741
- break;
133742
- case "inlineReducer":
133743
- _collectRecommendatio2 = " If '" + setStateRecommendation.setter + "' needs the current value of '" + (setStateRecommendation.missingDep + "', you can also switch to useReducer instead of useState and read '") + (setStateRecommendation.missingDep + "' in the reducer.");
133744
- break;
133745
- case "updater":
133746
- _collectRecommendatio2 = " You can also do a functional update '" + setStateRecommendation.setter + "(" + setStateRecommendation.missingDep.slice(0, 1) + " => ...)' if you only need '" + setStateRecommendation.missingDep + "' in the '" + (setStateRecommendation.setter + "' call.");
133747
- break;
133748
- default:
133749
- throw Error("Unknown case.");
133750
- }
133751
- }
133752
- reportProblem({
133753
- node: declaredDependenciesNode,
133754
- message: "React Hook " + getSource(reactiveHook) + " has " + (getWarningMessage(missingDependencies, "a", "missing", "include") || getWarningMessage(currentScope, "an", "unnecessary", "exclude") || getWarningMessage(duplicateDependencies, "a", "duplicate", "omit")) + _collectRecommendatio2,
133755
- suggest: [
133756
- {
133757
- desc: "Update the dependencies array to be: [" + suggestedDeps.map(formatDependency).join(", ") + "]",
133758
- fix: function(fixer) {
133759
- return fixer.replaceText(declaredDependenciesNode, "[" + suggestedDeps.map(formatDependency).join(", ") + "]");
133760
- }
133761
- }
133762
- ]
133763
- });
133764
- }
133765
- } else {
133766
- var setStateInsideEffectWithoutDeps = null;
133767
- dependencies.forEach(function(_ref3, key) {
133768
- setStateInsideEffectWithoutDeps || _ref3.references.forEach(function(reference) {
133769
- if (!setStateInsideEffectWithoutDeps && setStateCallSites.has(reference.identifier)) {
133770
- for (reference = reference.from;reference.type !== "function"; )
133771
- reference = reference.upper;
133772
- reference.block === node && (setStateInsideEffectWithoutDeps = key);
133773
- }
133774
- });
133775
- });
133776
- if (setStateInsideEffectWithoutDeps) {
133777
- var suggestedDependencies$13 = collectRecommendations({
133778
- dependencies,
133779
- declaredDependencies: [],
133780
- stableDependencies,
133781
- externalDependencies: new Set,
133782
- isEffect: true
133783
- }).suggestedDependencies;
133784
- reportProblem({
133785
- node: reactiveHook,
133786
- message: "React Hook " + reactiveHookName + " contains a call to '" + setStateInsideEffectWithoutDeps + "'. Without a list of dependencies, this can lead to an infinite chain of updates. To fix this, pass [" + suggestedDependencies$13.join(", ") + ("] as a second argument to the " + reactiveHookName + " Hook."),
133787
- suggest: [
133788
- {
133789
- desc: "Add dependencies array: [" + suggestedDependencies$13.join(", ") + "]",
133790
- fix: function(fixer) {
133791
- return fixer.insertTextAfter(node, ", [" + suggestedDependencies$13.join(", ") + "]");
133792
- }
133793
- }
133794
- ]
133795
- });
133796
- }
133797
- }
133798
- }
133799
- }
133800
- var enableDangerousAutofixThisMayCauseInfiniteLoops = context.options && context.options[0] && context.options[0].enableDangerousAutofixThisMayCauseInfiniteLoops || false, options = {
133801
- additionalHooks: context.options && context.options[0] && context.options[0].additionalHooks ? new RegExp(context.options[0].additionalHooks) : undefined,
133802
- enableDangerousAutofixThisMayCauseInfiniteLoops
133803
- }, getSource = typeof context.getSource === "function" ? function(node) {
133804
- return context.getSource(node);
133805
- } : function(node) {
133806
- return context.sourceCode.getText(node);
133807
- }, getScope = typeof context.getScope === "function" ? function() {
133808
- return context.getScope();
133809
- } : function(node) {
133810
- return context.sourceCode.getScope(node);
133811
- }, scopeManager = context.getSourceCode().scopeManager, setStateCallSites = new WeakMap, stateVariables = new WeakSet, stableKnownValueCache = new WeakMap, functionWithoutCapturedValueCache = new WeakMap, useEffectEventVariables = new WeakSet;
133812
- return {
133813
- CallExpression: function(node) {
133814
- var callbackIndex = getReactiveHookCallbackIndex(node.callee, options);
133815
- if (callbackIndex !== -1) {
133816
- var callback = node.arguments[callbackIndex], reactiveHook = node.callee, reactiveHookName = getNodeWithoutReactNamespace(reactiveHook).name;
133817
- node = node.arguments[callbackIndex + 1];
133818
- var declaredDependenciesNode = !node || node.type === "Identifier" && node.name === "undefined" ? undefined : node;
133819
- node = /Effect($|[^a-z])/g.test(reactiveHookName);
133820
- if (callback)
133821
- if (declaredDependenciesNode || node) {
133822
- for (;callback.type === "TSAsExpression" || callback.type === "AsExpression"; )
133823
- callback = callback.expression;
133824
- switch (callback.type) {
133825
- case "FunctionExpression":
133826
- case "ArrowFunctionExpression":
133827
- visitFunctionWithDependencies(callback, declaredDependenciesNode, reactiveHook, reactiveHookName, node);
133828
- return;
133829
- case "Identifier":
133830
- if (!declaredDependenciesNode || declaredDependenciesNode.elements && declaredDependenciesNode.elements.some(function(el) {
133831
- return el && el.type === "Identifier" && el.name === callback.name;
133832
- }))
133833
- return;
133834
- callbackIndex = getScope(callback).set.get(callback.name);
133835
- if (callbackIndex == null || callbackIndex.defs == null)
133836
- return;
133837
- callbackIndex = callbackIndex.defs[0];
133838
- if (!callbackIndex || !callbackIndex.node)
133839
- break;
133840
- if (callbackIndex.type === "Parameter") {
133841
- reportProblem({
133842
- node: reactiveHook,
133843
- message: getUnknownDependenciesMessage(reactiveHookName)
133844
- });
133845
- return;
133846
- }
133847
- if (callbackIndex.type !== "Variable" && callbackIndex.type !== "FunctionName")
133848
- break;
133849
- switch (callbackIndex.node.type) {
133850
- case "FunctionDeclaration":
133851
- visitFunctionWithDependencies(callbackIndex.node, declaredDependenciesNode, reactiveHook, reactiveHookName, node);
133852
- return;
133853
- case "VariableDeclarator":
133854
- if (callbackIndex = callbackIndex.node.init)
133855
- switch (callbackIndex.type) {
133856
- case "ArrowFunctionExpression":
133857
- case "FunctionExpression":
133858
- visitFunctionWithDependencies(callbackIndex, declaredDependenciesNode, reactiveHook, reactiveHookName, node);
133859
- return;
133860
- }
133861
- }
133862
- break;
133863
- default:
133864
- reportProblem({
133865
- node: reactiveHook,
133866
- message: getUnknownDependenciesMessage(reactiveHookName)
133867
- });
133868
- return;
133869
- }
133870
- reportProblem({
133871
- node: reactiveHook,
133872
- message: "React Hook " + reactiveHookName + " has a missing dependency: '" + callback.name + "'. Either include it or remove the dependency array.",
133873
- suggest: [
133874
- {
133875
- desc: "Update the dependencies array to be: [" + callback.name + "]",
133876
- fix: function(fixer) {
133877
- return fixer.replaceText(declaredDependenciesNode, "[" + callback.name + "]");
133878
- }
133879
- }
133880
- ]
133881
- });
133882
- } else
133883
- reactiveHookName !== "useMemo" && reactiveHookName !== "useCallback" || reportProblem({
133884
- node: reactiveHook,
133885
- message: "React Hook " + reactiveHookName + " does nothing when called with only one argument. Did you forget to pass an array of dependencies?"
133886
- });
133887
- else
133888
- reportProblem({
133889
- node: reactiveHook,
133890
- message: "React Hook " + reactiveHookName + " requires an effect callback. Did you forget to pass a callback to the hook?"
133891
- });
133892
- }
133893
- }
133894
- };
133895
- }
133896
- }
134630
+ "rules-of-hooks": rule$1,
134631
+ "exhaustive-deps": rule2
133897
134632
  };
133898
134633
  var configRules = {
133899
134634
  "react-hooks/rules-of-hooks": "error",
133900
134635
  "react-hooks/exhaustive-deps": "warn"
133901
134636
  };
133902
- var legacyRecommendedConfig = { plugins: ["react-hooks"], rules: configRules };
133903
- var reactHooksPlugin = {
133904
- meta: { name: "eslint-plugin-react-hooks" },
133905
- rules
134637
+ var legacyRecommendedConfig = {
134638
+ plugins: ["react-hooks"],
134639
+ rules: configRules
133906
134640
  };
133907
- var configs = {
133908
- "recommended-legacy": legacyRecommendedConfig,
133909
- "recommended-latest": {
133910
- name: "react-hooks/recommended",
133911
- plugins: { "react-hooks": reactHooksPlugin },
133912
- rules: configRules
133913
- },
133914
- recommended: legacyRecommendedConfig
134641
+ var plugin = {
134642
+ meta: { name: "eslint-plugin-react-hooks" },
134643
+ rules,
134644
+ configs: {
134645
+ "recommended-legacy": legacyRecommendedConfig,
134646
+ recommended: legacyRecommendedConfig,
134647
+ "recommended-latest": {
134648
+ name: "react-hooks/recommended",
134649
+ plugins: {
134650
+ get "react-hooks"() {
134651
+ return plugin;
134652
+ }
134653
+ },
134654
+ rules: configRules
134655
+ }
134656
+ }
133915
134657
  };
133916
- assign({}, reactHooksPlugin, { configs });
134658
+ var configs = plugin.configs;
134659
+ var meta = plugin.meta;
133917
134660
  exports.configs = configs;
134661
+ exports.meta = meta;
133918
134662
  exports.rules = rules;
133919
134663
  });
133920
134664
 
133921
- // ../../node_modules/.pnpm/eslint-plugin-react-hooks@5.2.0-canary-de1eaa26-20250124_eslint@9.19.0/node_modules/eslint-plugin-react-hooks/index.js
134665
+ // ../../node_modules/.pnpm/eslint-plugin-react-hooks@5.2.0_eslint@9.19.0/node_modules/eslint-plugin-react-hooks/index.js
133922
134666
  var require_eslint_plugin_react_hooks = __commonJS((exports, module) => {
133923
134667
  if (true) {
133924
134668
  module.exports = require_eslint_plugin_react_hooks_production();
@@ -403575,7 +404319,7 @@ var require_getWrappingFixer = __commonJS((exports) => {
403575
404319
  }
403576
404320
  });
403577
404321
 
403578
- // ../../node_modules/.pnpm/ts-api-utils@2.0.0_typescript@5.5.4/node_modules/ts-api-utils/lib/index.cjs
404322
+ // ../../node_modules/.pnpm/ts-api-utils@2.0.1_typescript@5.5.4/node_modules/ts-api-utils/lib/index.cjs
403579
404323
  var require_lib15 = __commonJS((exports) => {
403580
404324
  var ts9 = require_typescript();
403581
404325
  function _interopDefault(e) {
@@ -404441,8 +405185,8 @@ var require_lib15 = __commonJS((exports) => {
404441
405185
  if (!prop.name.startsWith(prefix)) {
404442
405186
  continue;
404443
405187
  }
404444
- const declaration = prop.valueDeclaration ?? prop.getDeclarations()[0];
404445
- if (!isNamedDeclarationWithName(declaration) || declaration.name === undefined || !ts9__default.default.isComputedPropertyName(declaration.name)) {
405188
+ const declaration = prop.valueDeclaration ?? prop.getDeclarations()?.[0];
405189
+ if (!declaration || !isNamedDeclarationWithName(declaration) || declaration.name === undefined || !ts9__default.default.isComputedPropertyName(declaration.name)) {
404446
405190
  continue;
404447
405191
  }
404448
405192
  const globalSymbol = typeChecker.getApparentType(typeChecker.getTypeAtLocation(declaration.name.expression)).symbol;
@@ -448268,7 +449012,7 @@ var makeConfig = ({
448268
449012
  "remotion.config.ts",
448269
449013
  "remotion.config.js"
448270
449014
  ]
448271
- }, import_js.default.configs.recommended, import_typescript_eslint.default.configs.recommended, {
449015
+ }, import_js.default.configs.recommended, import_typescript_eslint.default.configs.eslintRecommended, import_typescript_eslint.default.configs.recommended, {
448272
449016
  plugins: {
448273
449017
  react: import_eslint_plugin_react.default,
448274
449018
  "react-hooks": import_eslint_plugin_react_hooks.default
@@ -448277,7 +449021,7 @@ var makeConfig = ({
448277
449021
  ...import_eslint_plugin_react.default.configs.flat.recommended.languageOptions,
448278
449022
  parser: import_typescript_eslint.default.parser,
448279
449023
  parserOptions: {
448280
- projectService: true
449024
+ projectService: false
448281
449025
  }
448282
449026
  },
448283
449027
  rules: {
@@ -448300,9 +449044,6 @@ var makeConfig = ({
448300
449044
  },
448301
449045
  rules: esm_default.configs.recommended.rules,
448302
449046
  ...remotionDir ? { files: [remotionDir] } : {}
448303
- }, {
448304
- files: ["**/*.js"],
448305
- extends: [import_typescript_eslint.default.configs.disableTypeChecked]
448306
449047
  });
448307
449048
  var config = makeConfig({
448308
449049
  remotionDir: undefined