Skip to content

Commit

Permalink
[Fix] prop-types/component detection: avoid a crash when a local `c…
Browse files Browse the repository at this point in the history
…reateElement` identifier exists

Fixes #2733.
  • Loading branch information
ljharb committed Jul 29, 2020
1 parent 530b0e8 commit 8466625
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/util/Components.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
) {
Expand Down
22 changes: 22 additions & 0 deletions tests/lib/rules/prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: Props) => {
const createElement = (text: string) => {
return (
<div>
{text}
</div>
);
};
return <>{createElement(props.text)}</>;
};
`,
parser: parsers.TYPESCRIPT_ESLINT
}
],

Expand Down

0 comments on commit 8466625

Please sign in to comment.