From 8466625dee3ac366a575b27e3c380198733c0d42 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 28 Jul 2020 22:19:08 -0700 Subject: [PATCH] [Fix] `prop-types`/component detection: avoid a crash when a local `createElement` identifier exists Fixes #2733. --- lib/util/Components.js | 4 +++- tests/lib/rules/prop-types.js | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/util/Components.js b/lib/util/Components.js index 495d6f71f3..888f3ee59f 100644 --- a/lib/util/Components.js +++ b/lib/util/Components.js @@ -345,7 +345,9 @@ function componentRule(rule, context) { // check proper require. if ( - requireExpression.callee.name === 'require' + requireExpression + && requireExpression.callee + && requireExpression.callee.name === 'require' && requireExpression.arguments[0] && requireExpression.arguments[0].value === pragma.toLocaleLowerCase() ) { diff --git a/tests/lib/rules/prop-types.js b/tests/lib/rules/prop-types.js index 69b84cf7a7..f064d9a377 100644 --- a/tests/lib/rules/prop-types.js +++ b/tests/lib/rules/prop-types.js @@ -2574,6 +2574,28 @@ ruleTester.run('prop-types', rule, { code: ` export default function() {} ` + }, + { + code: ` + import * as React from 'react'; + + interface Props { + text: string; + } + + export const Test: React.FC = (props: Props) => { + const createElement = (text: string) => { + return ( +
+ {text} +
+ ); + }; + + return <>{createElement(props.text)}; + }; + `, + parser: parsers.TYPESCRIPT_ESLINT } ],