@@ -65,6 +65,7 @@ module.exports = {
65
65
// Used to track the type annotations in scope.
66
66
// Necessary because babel's scopes do not track type annotations.
67
67
let stack = null ;
68
+ const classExpressions = [ ] ;
68
69
69
70
const MISSING_MESSAGE = '\'{{name}}\' is missing in props validation' ;
70
71
@@ -872,6 +873,7 @@ module.exports = {
872
873
while ( annotation && ( annotation . type === 'TypeAnnotation' || annotation . type === 'NullableTypeAnnotation' ) ) {
873
874
annotation = annotation . typeAnnotation ;
874
875
}
876
+
875
877
if ( annotation . type === 'GenericTypeAnnotation' && typeScope ( annotation . id . name ) ) {
876
878
return typeScope ( annotation . id . name ) ;
877
879
}
@@ -921,9 +923,10 @@ module.exports = {
921
923
} ,
922
924
923
925
ClassExpression : function ( node ) {
924
- if ( isSuperTypeParameterPropsDeclaration ( node ) ) {
925
- markPropTypesAsDeclared ( node , resolveSuperParameterPropsType ( node ) ) ;
926
- }
926
+ // TypeParameterDeclaration need to be added to typeScope in order to handle ClassExpressions.
927
+ // This visitor is executed before TypeParameterDeclaration are scoped, therefore we postpone
928
+ // processing class expressions until when the program exists.
929
+ classExpressions . push ( node ) ;
927
930
} ,
928
931
929
932
ClassProperty : function ( node ) {
@@ -1017,6 +1020,14 @@ module.exports = {
1017
1020
typeScope ( node . id . name , node . right ) ;
1018
1021
} ,
1019
1022
1023
+ TypeParameterDeclaration : function ( node ) {
1024
+ const identifier = node . params [ 0 ] ;
1025
+
1026
+ if ( identifier . typeAnnotation ) {
1027
+ typeScope ( identifier . name , identifier . typeAnnotation . typeAnnotation ) ;
1028
+ }
1029
+ } ,
1030
+
1020
1031
Program : function ( ) {
1021
1032
stack = [ { } ] ;
1022
1033
} ,
@@ -1030,6 +1041,12 @@ module.exports = {
1030
1041
} ,
1031
1042
1032
1043
'Program:exit' : function ( ) {
1044
+ classExpressions . forEach ( node => {
1045
+ if ( isSuperTypeParameterPropsDeclaration ( node ) ) {
1046
+ markPropTypesAsDeclared ( node , resolveSuperParameterPropsType ( node ) ) ;
1047
+ }
1048
+ } ) ;
1049
+
1033
1050
stack = null ;
1034
1051
const list = components . list ( ) ;
1035
1052
// Report undeclared proptypes for all classes
0 commit comments