@@ -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' ) ;
@@ -60,25 +60,42 @@ function amendPropTypes(documentation, path) {
60
60
var resolvedValuePath = resolveToValue ( propertyPath . get ( 'argument' ) ) ;
61
61
switch ( resolvedValuePath . node . type ) {
62
62
case types . ObjectExpression . name : // normal object literal
63
- amendPropTypes ( documentation , resolvedValuePath ) ;
63
+ amendPropTypes ( getDescriptor , resolvedValuePath ) ;
64
64
break ;
65
65
}
66
66
break ;
67
67
}
68
68
} ) ;
69
69
}
70
70
71
- export default function propTypeHandler (
72
- documentation : Documentation ,
73
- path : NodePath
74
- ) {
75
- var propTypesPath = getMemberValuePath ( path , 'propTypes' ) ;
76
- if ( ! propTypesPath ) {
77
- return ;
78
- }
79
- propTypesPath = resolveToValue ( propTypesPath ) ;
80
- if ( ! propTypesPath ) {
81
- return ;
71
+ export function getPropTypeHandler ( propName : string ) {
72
+ return function (
73
+ documentation : Documentation ,
74
+ path : NodePath
75
+ ) {
76
+ var propTypesPath = getMemberValuePath ( path , propName ) ;
77
+ if ( ! propTypesPath ) {
78
+ return ;
79
+ }
80
+ propTypesPath = resolveToValue ( propTypesPath ) ;
81
+ if ( ! propTypesPath ) {
82
+ return ;
83
+ }
84
+ let getDescriptor ;
85
+ switch ( propName ) {
86
+ case 'childContextTypes' :
87
+ getDescriptor = documentation . getChildContextDescriptor ;
88
+ break ;
89
+ case 'contextTypes' :
90
+ getDescriptor = documentation . getContextDescriptor ;
91
+ break ;
92
+ default :
93
+ getDescriptor = documentation . getPropDescriptor ;
94
+ }
95
+ amendPropTypes ( getDescriptor . bind ( documentation ) , propTypesPath ) ;
82
96
}
83
- amendPropTypes ( documentation , propTypesPath ) ;
84
97
}
98
+
99
+ export const propTypeHandler = getPropTypeHandler ( 'propTypes' )
100
+ export const contextTypeHandler = getPropTypeHandler ( 'contextTypes' )
101
+ export const childContextTypeHandler = getPropTypeHandler ( 'childContextTypes' )
0 commit comments