Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor] void-dom-elements-no-children: improve performance #2977

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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