From 185d95c722b7b40d927e99c9c1dcbb23df4d5c72 Mon Sep 17 00:00:00 2001 From: Chiawen Chen Date: Sat, 29 Feb 2020 20:34:02 +0800 Subject: [PATCH] [Fix] `displayName`: avoid a crash when using React.memo --- lib/util/Components.js | 4 +++- tests/lib/rules/display-name.js | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/util/Components.js b/lib/util/Components.js index 515a39dd00..96b149d78b 100644 --- a/lib/util/Components.js +++ b/lib/util/Components.js @@ -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; }, diff --git a/tests/lib/rules/display-name.js b/tests/lib/rules/display-name.js index d92bd7a2f6..f3a8a89aef 100644 --- a/tests/lib/rules/display-name.js +++ b/tests/lib/rules/display-name.js @@ -463,6 +463,14 @@ ruleTester.run('display-name', rule, { return
Hello {world}
}) ` + }, { + code: ` + import React from 'react'; + + const Hello = React.memo(function Hello() { + return; + }); + ` }, { code: ` import React from 'react'