@@ -13,6 +13,7 @@ const pragmaUtil = require('../util/pragma');
1313const report = require ( '../util/report' ) ;
1414const astUtil = require ( '../util/ast' ) ;
1515const getText = require ( '../util/eslint' ) . getText ;
16+ const isJSX = require ( '../util/jsx' ) . isJSX ;
1617
1718// ------------------------------------------------------------------------------
1819// Rule Definition
@@ -33,8 +34,6 @@ const messages = {
3334 nonUniqueKeys : '`key` prop must be unique' ,
3435} ;
3536
36- const shouldCheckNode = ( n ) => n && ( n . type === 'JSXElement' || n . type === 'JSXFragment' ) ;
37-
3837/** @type {import('eslint').Rule.RuleModule } */
3938module . exports = {
4039 meta : {
@@ -151,10 +150,10 @@ module.exports = {
151150 const argument = returnStatement . argument ;
152151
153152 if ( argument . type === 'ConditionalExpression' ) {
154- if ( shouldCheckNode ( argument . consequent ) ) {
153+ if ( isJSX ( argument . consequent ) ) {
155154 checkIteratorElement ( argument . consequent ) ;
156155 }
157- if ( shouldCheckNode ( argument . alternate ) ) {
156+ if ( isJSX ( argument . alternate ) ) {
158157 checkIteratorElement ( argument . alternate ) ;
159158 }
160159 } else {
@@ -172,17 +171,17 @@ module.exports = {
172171 */
173172 function checkArrowFunctionWithJSX ( node ) {
174173 const isArrFn = node && node . type === 'ArrowFunctionExpression' ;
175- if ( isArrFn && shouldCheckNode ( node . body ) ) {
174+ if ( isArrFn && isJSX ( node . body ) ) {
176175 checkIteratorElement ( node . body ) ;
177176 }
178177 if ( node . body . type === 'ConditionalExpression' ) {
179- if ( shouldCheckNode ( node . body . consequent ) ) {
178+ if ( isJSX ( node . body . consequent ) ) {
180179 checkIteratorElement ( node . body . consequent ) ;
181180 }
182- if ( shouldCheckNode ( node . body . alternate ) ) {
181+ if ( isJSX ( node . body . alternate ) ) {
183182 checkIteratorElement ( node . body . alternate ) ;
184183 }
185- } else if ( node . body . type === 'LogicalExpression' && shouldCheckNode ( node . body . right ) ) {
184+ } else if ( node . body . type === 'LogicalExpression' && isJSX ( node . body . right ) ) {
186185 checkIteratorElement ( node . body . right ) ;
187186 }
188187 }
0 commit comments