@@ -33,15 +33,15 @@ function isPropTypesExpression(path) {
33
33
return false ;
34
34
}
35
35
36
- function amendPropTypes ( documentation , path ) {
36
+ function amendPropTypes ( getDescriptor , path ) {
37
37
if ( ! types . ObjectExpression . check ( path . node ) ) {
38
38
return ;
39
39
}
40
40
41
41
path . get ( 'properties' ) . each ( function ( propertyPath ) {
42
42
switch ( propertyPath . node . type ) {
43
43
case types . Property . name :
44
- var propDescriptor = documentation . getPropDescriptor (
44
+ var propDescriptor = getDescriptor (
45
45
getPropertyName ( propertyPath )
46
46
) ;
47
47
var valuePath = propertyPath . get ( 'value' ) ;
@@ -59,25 +59,42 @@ function amendPropTypes(documentation, path) {
59
59
var resolvedValuePath = resolveToValue ( propertyPath . get ( 'argument' ) ) ;
60
60
switch ( resolvedValuePath . node . type ) {
61
61
case types . ObjectExpression . name : // normal object literal
62
- amendPropTypes ( documentation , resolvedValuePath ) ;
62
+ amendPropTypes ( getDescriptor , resolvedValuePath ) ;
63
63
break ;
64
64
}
65
65
break ;
66
66
}
67
67
} ) ;
68
68
}
69
69
70
- export default function propTypeHandler (
71
- documentation : Documentation ,
72
- path : NodePath
73
- ) {
74
- var propTypesPath = getMemberValuePath ( path , 'propTypes' ) ;
75
- if ( ! propTypesPath ) {
76
- return ;
77
- }
78
- propTypesPath = resolveToValue ( propTypesPath ) ;
79
- if ( ! propTypesPath ) {
80
- return ;
70
+ export function getPropTypeHandler ( propName : string ) {
71
+ return function (
72
+ documentation : Documentation ,
73
+ path : NodePath
74
+ ) {
75
+ var propTypesPath = getMemberValuePath ( path , propName ) ;
76
+ if ( ! propTypesPath ) {
77
+ return ;
78
+ }
79
+ propTypesPath = resolveToValue ( propTypesPath ) ;
80
+ if ( ! propTypesPath ) {
81
+ return ;
82
+ }
83
+ let getDescriptor ;
84
+ switch ( propName ) {
85
+ case 'childContextTypes' :
86
+ getDescriptor = documentation . getChildContextDescriptor ;
87
+ break ;
88
+ case 'contextTypes' :
89
+ getDescriptor = documentation . getContextDescriptor ;
90
+ break ;
91
+ default :
92
+ getDescriptor = documentation . getPropDescriptor ;
93
+ }
94
+ amendPropTypes ( getDescriptor . bind ( documentation ) , propTypesPath ) ;
81
95
}
82
- amendPropTypes ( documentation , propTypesPath ) ;
83
96
}
97
+
98
+ export const propTypeHandler = getPropTypeHandler ( 'propTypes' )
99
+ export const contextTypeHandler = getPropTypeHandler ( 'contextTypes' )
100
+ export const childContextTypeHandler = getPropTypeHandler ( 'childContextTypes' )
0 commit comments