@@ -46,6 +46,30 @@ function mergeUsedPropTypes(propsList, newPropsList) {
4646 return propsList . concat ( propsToAdd ) ;
4747}
4848
49+ function isReturnsConditionalJSX ( node , property , strict ) {
50+ const returnsConditionalJSXConsequent = node [ property ] &&
51+ node [ property ] . type === 'ConditionalExpression' &&
52+ jsxUtil . isJSX ( node [ property ] . consequent ) ;
53+ const returnsConditionalJSXAlternate = node [ property ] &&
54+ node [ property ] . type === 'ConditionalExpression' &&
55+ jsxUtil . isJSX ( node [ property ] . alternate ) ;
56+ return strict ?
57+ ( returnsConditionalJSXConsequent && returnsConditionalJSXAlternate ) :
58+ ( returnsConditionalJSXConsequent || returnsConditionalJSXAlternate ) ;
59+ }
60+
61+ function isReturnsLogicalJSX ( node , property , strict ) {
62+ const returnsLogicalJSXLeft = node [ property ] &&
63+ node [ property ] . type === 'LogicalExpression' &&
64+ jsxUtil . isJSX ( node [ property ] . left ) ;
65+ const returnsLogicalJSXRight = node [ property ] &&
66+ node [ property ] . type === 'LogicalExpression' &&
67+ jsxUtil . isJSX ( node [ property ] . right ) ;
68+ return strict ?
69+ ( returnsLogicalJSXLeft && returnsLogicalJSXRight ) :
70+ ( returnsLogicalJSXLeft || returnsLogicalJSXRight ) ;
71+ }
72+
4973const Lists = new WeakMap ( ) ;
5074
5175/**
@@ -373,22 +397,15 @@ function componentRule(rule, context) {
373397 return false ;
374398 }
375399
376- const returnsConditionalJSXConsequent = node [ property ] &&
377- node [ property ] . type === 'ConditionalExpression' &&
378- jsxUtil . isJSX ( node [ property ] . consequent ) ;
379- const returnsConditionalJSXAlternate = node [ property ] &&
380- node [ property ] . type === 'ConditionalExpression' &&
381- jsxUtil . isJSX ( node [ property ] . alternate ) ;
382- const returnsConditionalJSX = strict ?
383- ( returnsConditionalJSXConsequent && returnsConditionalJSXAlternate ) :
384- ( returnsConditionalJSXConsequent || returnsConditionalJSXAlternate ) ;
400+ const returnsConditionalJSX = isReturnsConditionalJSX ( node , property , strict ) ;
401+ const returnsLogicalJSX = isReturnsLogicalJSX ( node , property , strict ) ;
385402
386- const returnsJSX = node [ property ] &&
387- jsxUtil . isJSX ( node [ property ] ) ;
403+ const returnsJSX = node [ property ] && jsxUtil . isJSX ( node [ property ] ) ;
388404 const returnsPragmaCreateElement = this . isCreateElement ( node [ property ] ) ;
389405
390- return Boolean (
406+ return ! ! (
391407 returnsConditionalJSX ||
408+ returnsLogicalJSX ||
392409 returnsJSX ||
393410 returnsPragmaCreateElement
394411 ) ;
0 commit comments