@@ -11,6 +11,7 @@ const has = require('has');
11
11
const Components = require ( '../util/Components' ) ;
12
12
const variable = require ( '../util/variable' ) ;
13
13
const annotations = require ( '../util/annotations' ) ;
14
+ const versionUtil = require ( '../util/version' ) ;
14
15
15
16
// ------------------------------------------------------------------------------
16
17
// Constants
@@ -134,17 +135,23 @@ module.exports = {
134
135
}
135
136
136
137
/**
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.
138
+ * Resolve the type annotation for a given class declaration node with superTypeParameters.
142
139
*
143
140
* @param {ASTNode } node The annotation or a node containing the type annotation.
144
141
* @returns {ASTNode } The resolved type annotation for the node.
145
142
*/
146
- function resolveTypeAnnotation ( node ) {
147
- let annotation = node . typeAnnotation || node ;
143
+ function resolveSuperParameterPropsType ( node ) {
144
+ let propsParameterPosition ;
145
+ try {
146
+ // Flow <=0.52 had 3 required TypedParameters of which the second one is the Props.
147
+ // Flow >=0.53 has 2 optional TypedParameters of which the first one is the Props.
148
+ propsParameterPosition = versionUtil . testFlowVersion ( context , '0.53.0' ) ? 0 : 1 ;
149
+ } catch ( e ) {
150
+ // In case there is no flow version defined, we can safely assume that when there are 3 Props we are dealing with version <= 0.52
151
+ propsParameterPosition = node . superTypeParameters . params . length <= 2 ? 0 : 1 ;
152
+ }
153
+
154
+ let annotation = node . superTypeParameters . params [ propsParameterPosition ] ;
148
155
while ( annotation && ( annotation . type === 'TypeAnnotation' || annotation . type === 'NullableTypeAnnotation' ) ) {
149
156
annotation = annotation . typeAnnotation ;
150
157
}
0 commit comments