Skip to content

Commit

Permalink
[eslint-plugin-react-hooks] Fixed crash when referencing arguments in…
Browse files Browse the repository at this point in the history
… arrow functions. (#16356)

* Fixed issue with def being undefined while referencing arguments.

* Removed todo comment.

* Skip exhaustive deps check if def is null.

* Fixed code formatting in ExhaustiveDeps.

* Removed unneeded comment in ExhaustiveDeps.
  • Loading branch information
hristo-kanchev authored and gaearon committed Aug 14, 2019
1 parent e308a03 commit 9e64bf1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,28 @@ const tests = {
}
`,
},
// Ignore arguments keyword for arrow functions.
{
code: `
function Example() {
useEffect(() => {
arguments
}, [])
}
`,
},
{
code: `
function Example() {
useEffect(() => {
const bar = () => {
arguments;
};
bar();
}, [])
}
`,
},
],
invalid: [
{
Expand Down
13 changes: 7 additions & 6 deletions packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,13 +397,14 @@ export default {
});
}

// Ignore references to the function itself as it's not defined yet.
const def = reference.resolved.defs[0];
if (
def != null &&
def.node != null &&
def.node.init === node.parent
) {

if (def == null) {
continue;
}

// Ignore references to the function itself as it's not defined yet.
if (def.node != null && def.node.init === node.parent) {
continue;
}

Expand Down

0 comments on commit 9e64bf1

Please sign in to comment.