@@ -133,6 +133,42 @@ module.exports = {
133
133
return false ;
134
134
}
135
135
136
+ /**
137
+ * Resolve the type annotation for a given node.
138
+ * Flow annotations are sometimes wrapped in outer `TypeAnnotation`
139
+ * and `NullableTypeAnnotation` nodes which obscure the annotation we're
140
+ * interested in.
141
+ * This method also resolves type aliases where possible.
142
+ *
143
+ * @param {ASTNode } node The annotation or a node containing the type annotation.
144
+ * @returns {ASTNode } The resolved type annotation for the node.
145
+ */
146
+ function resolveTypeAnnotation ( node ) {
147
+ let annotation = node . typeAnnotation || node ;
148
+ while ( annotation && ( annotation . type === 'TypeAnnotation' || annotation . type === 'NullableTypeAnnotation' ) ) {
149
+ annotation = annotation . typeAnnotation ;
150
+ }
151
+ if ( annotation . type === 'GenericTypeAnnotation' && typeScope ( annotation . id . name ) ) {
152
+ return typeScope ( annotation . id . name ) ;
153
+ }
154
+ return annotation ;
155
+ }
156
+
157
+ /**
158
+ * Checks if we are declaring a props as a generic type in a flow-annotated class.
159
+ *
160
+ * @param {ASTNode } node the AST node being checked.
161
+ * @returns {Boolean } True if the node is a class with generic prop types, false if not.
162
+ */
163
+ function isSuperTypeParameterPropsDeclaration ( node ) {
164
+ if ( node && node . type === 'ClassDeclaration' ) {
165
+ if ( node . superTypeParameters && node . superTypeParameters . params . length > 0 ) {
166
+ return true ;
167
+ }
168
+ }
169
+ return false ;
170
+ }
171
+
136
172
/**
137
173
* Checks if we are declaring a prop
138
174
* @param {ASTNode } node The AST node being checked.
@@ -866,6 +902,12 @@ module.exports = {
866
902
// --------------------------------------------------------------------------
867
903
868
904
return {
905
+ ClassDeclaration : function ( node ) {
906
+ if ( isSuperTypeParameterPropsDeclaration ( node ) ) {
907
+ markPropTypesAsDeclared ( node , resolveSuperParameterPropsType ( node ) ) ;
908
+ }
909
+ } ,
910
+
869
911
ClassProperty : function ( node ) {
870
912
if ( isAnnotatedClassPropsDeclaration ( node ) ) {
871
913
markPropTypesAsDeclared ( node , resolveTypeAnnotation ( node ) ) ;
0 commit comments