@@ -249,6 +249,7 @@ module.exports = {
249
249
function _isDeclaredInComponent ( declaredPropTypes , keyList ) {
250
250
for ( let i = 0 , j = keyList . length ; i < j ; i ++ ) {
251
251
const key = keyList [ i ] ;
252
+
252
253
const propType = (
253
254
declaredPropTypes && (
254
255
// Check if this key is declared
@@ -261,7 +262,7 @@ module.exports = {
261
262
// If it's a computed property, we can't make any further analysis, but is valid
262
263
return key === '__COMPUTED_PROP__' ;
263
264
}
264
- if ( propType === true ) {
265
+ if ( propType === true || typeof propType === 'object' && Object . keys ( propType ) . length === 0 ) {
265
266
return true ;
266
267
}
267
268
// Consider every children as declared
@@ -308,6 +309,7 @@ module.exports = {
308
309
function isDeclaredInComponent ( node , names ) {
309
310
while ( node ) {
310
311
const component = components . get ( node ) ;
312
+
311
313
const isDeclared =
312
314
component && component . confidence === 2 &&
313
315
_isDeclaredInComponent ( component . declaredPropTypes || { } , names )
@@ -483,7 +485,7 @@ module.exports = {
483
485
* Creates the representation of the React props type annotation for the component.
484
486
* The representation is used to verify nested used properties.
485
487
* @param {ASTNode } annotation Type annotation for the props class property.
486
- * @return {Object|Boolean } The representation of the declaration, true means
488
+ * @return {Object } The representation of the declaration, empty object means
487
489
* the property is declared without the need for further analysis.
488
490
*/
489
491
function buildTypeAnnotationDeclarationTypes ( annotation ) {
@@ -492,7 +494,7 @@ module.exports = {
492
494
if ( typeScope ( annotation . id . name ) ) {
493
495
return buildTypeAnnotationDeclarationTypes ( typeScope ( annotation . id . name ) ) ;
494
496
}
495
- return true ;
497
+ return { } ;
496
498
case 'ObjectTypeAnnotation' :
497
499
let containsObjectTypeSpread = false ;
498
500
const shapeTypeDefinition = {
@@ -509,7 +511,7 @@ module.exports = {
509
511
510
512
// nested object type spread means we need to ignore/accept everything in this object
511
513
if ( containsObjectTypeSpread ) {
512
- return true ;
514
+ return { } ;
513
515
}
514
516
return shapeTypeDefinition ;
515
517
case 'UnionTypeAnnotation' :
@@ -520,7 +522,7 @@ module.exports = {
520
522
for ( let i = 0 , j = annotation . types . length ; i < j ; i ++ ) {
521
523
const type = buildTypeAnnotationDeclarationTypes ( annotation . types [ i ] ) ;
522
524
// keep only complex type
523
- if ( type !== true ) {
525
+ if ( Object . keys ( type ) . length > 0 ) {
524
526
if ( type . children === true ) {
525
527
// every child is accepted for one type, abort type analysis
526
528
unionTypeDefinition . children = true ;
@@ -532,7 +534,7 @@ module.exports = {
532
534
}
533
535
if ( unionTypeDefinition . children . length === 0 ) {
534
536
// no complex type found, simply accept everything
535
- return true ;
537
+ return { } ;
536
538
}
537
539
return unionTypeDefinition ;
538
540
case 'ArrayTypeAnnotation' :
@@ -544,7 +546,7 @@ module.exports = {
544
546
} ;
545
547
default :
546
548
// Unknown or accepts everything.
547
- return true ;
549
+ return { } ;
548
550
}
549
551
}
550
552
@@ -726,6 +728,7 @@ module.exports = {
726
728
ignorePropsValidation = true ;
727
729
return ;
728
730
}
731
+
729
732
declaredPropTypes [ key ] = buildTypeAnnotationDeclarationTypes ( value ) ;
730
733
} ) ;
731
734
0 commit comments