Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] displayName: avoid a crash when using React.memo #2587

Merged
merged 1 commit into from Mar 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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