Skip to content

Commit

Permalink
[Fix] displayName: avoid a crash when using React.memo
Browse files Browse the repository at this point in the history
  • Loading branch information
golopot authored and ljharb committed Feb 29, 2020
1 parent e2ed536 commit 185d95c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/util/Components.js
Expand Up @@ -483,7 +483,9 @@ function componentRule(rule, context) {
}
if (body.type === 'BlockStatement') {
const jsxElement = body.body.find(item => item.type === 'ReturnStatement');
return jsxElement && this.getComponentNameFromJSXElement(jsxElement.argument);
return jsxElement &&
jsxElement.argument &&
this.getComponentNameFromJSXElement(jsxElement.argument);
}
return null;
},
Expand Down
8 changes: 8 additions & 0 deletions tests/lib/rules/display-name.js
Expand Up @@ -463,6 +463,14 @@ ruleTester.run('display-name', rule, {
return <div>Hello {world}</div>
})
`
}, {
code: `
import React from 'react';
const Hello = React.memo(function Hello() {
return;
});
`
}, {
code: `
import React from 'react'
Expand Down

0 comments on commit 185d95c

Please sign in to comment.