Skip to content

Commit

Permalink
[Refactor] void-dom-elements-no-children: improve performance
Browse files Browse the repository at this point in the history
  • Loading branch information
golopot authored and ljharb committed Apr 28, 2021
1 parent 6cf3812 commit 1185b37
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -14,7 +14,9 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel

### Changed
* [Docs] [`jsx-newline`]: Fix minor spelling error on rule name ([#2974][] @DennisSkoko)
* [Refactor] [`void-dom-elements-no-children`]: improve performance

[#2977]: https://github.com/yannickcr/eslint-plugin-react/pull/2977
[#2975]: https://github.com/yannickcr/eslint-plugin-react/pull/2975
[#2974]: https://github.com/yannickcr/eslint-plugin-react/pull/2974
[#2972]: https://github.com/yannickcr/eslint-plugin-react/pull/2972
Expand Down
20 changes: 12 additions & 8 deletions lib/util/Components.js
Expand Up @@ -393,25 +393,29 @@ function componentRule(rule, context) {
* @returns {Boolean} True if createElement called from pragma
*/
isCreateElement(node) {
const calledOnPragma = (
// match `React.createElement()`
if (
node
&& node.callee
&& node.callee.object
&& node.callee.object.name === pragma
&& node.callee.property
&& node.callee.property.name === 'createElement'
);
) {
return true;
}

const calledDirectly = (
// match `createElement()`
if (
node
&& node.callee
&& node.callee.name === 'createElement'
);

if (this.isDestructuredFromPragmaImport('createElement')) {
return calledDirectly || calledOnPragma;
&& this.isDestructuredFromPragmaImport('createElement')
) {
return true;
}
return calledOnPragma;

return false;
},

/**
Expand Down

0 comments on commit 1185b37

Please sign in to comment.