Skip to content

Commit 1185b37

Browse files
chiawendtljharb
authored andcommitted
[Refactor] void-dom-elements-no-children: improve performance
1 parent 6cf3812 commit 1185b37

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
1414

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

19+
[#2977]: https://github.com/yannickcr/eslint-plugin-react/pull/2977
1820
[#2975]: https://github.com/yannickcr/eslint-plugin-react/pull/2975
1921
[#2974]: https://github.com/yannickcr/eslint-plugin-react/pull/2974
2022
[#2972]: https://github.com/yannickcr/eslint-plugin-react/pull/2972

lib/util/Components.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -393,25 +393,29 @@ function componentRule(rule, context) {
393393
* @returns {Boolean} True if createElement called from pragma
394394
*/
395395
isCreateElement(node) {
396-
const calledOnPragma = (
396+
// match `React.createElement()`
397+
if (
397398
node
398399
&& node.callee
399400
&& node.callee.object
400401
&& node.callee.object.name === pragma
401402
&& node.callee.property
402403
&& node.callee.property.name === 'createElement'
403-
);
404+
) {
405+
return true;
406+
}
404407

405-
const calledDirectly = (
408+
// match `createElement()`
409+
if (
406410
node
407411
&& node.callee
408412
&& node.callee.name === 'createElement'
409-
);
410-
411-
if (this.isDestructuredFromPragmaImport('createElement')) {
412-
return calledDirectly || calledOnPragma;
413+
&& this.isDestructuredFromPragmaImport('createElement')
414+
) {
415+
return true;
413416
}
414-
return calledOnPragma;
417+
418+
return false;
415419
},
416420

417421
/**

0 commit comments

Comments
 (0)