15
15
16
16
var getMembers = require ( './getMembers' ) ;
17
17
var getPropertyName = require ( './getPropertyName' ) ;
18
+ var printValue = require ( './printValue' ) ;
18
19
var recast = require ( 'recast' ) ;
19
20
var resolveToValue = require ( './resolveToValue' ) ;
20
21
@@ -23,7 +24,7 @@ var types = recast.types.namedTypes;
23
24
function getEnumValues ( path ) {
24
25
return path . get ( 'elements' ) . map ( function ( elementPath ) {
25
26
return {
26
- value : recast . print ( elementPath ) . code ,
27
+ value : printValue ( elementPath ) ,
27
28
computed : ! types . Literal . check ( elementPath . node )
28
29
} ;
29
30
} ) ;
@@ -33,7 +34,7 @@ function getPropTypeOneOf(argumentPath) {
33
34
var type = { name : 'enum' } ;
34
35
if ( ! types . ArrayExpression . check ( argumentPath . node ) ) {
35
36
type . computed = true ;
36
- type . value = recast . print ( argumentPath ) . code ;
37
+ type . value = printValue ( argumentPath ) ;
37
38
} else {
38
39
type . value = getEnumValues ( argumentPath ) ;
39
40
}
@@ -44,7 +45,7 @@ function getPropTypeOneOfType(argumentPath) {
44
45
var type = { name : 'union' } ;
45
46
if ( ! types . ArrayExpression . check ( argumentPath . node ) ) {
46
47
type . computed = true ;
47
- type . value = recast . print ( argumentPath ) . code ;
48
+ type . value = printValue ( argumentPath ) ;
48
49
} else {
49
50
type . value = argumentPath . get ( 'elements' ) . map ( getPropType ) ;
50
51
}
@@ -56,7 +57,7 @@ function getPropTypeArrayOf(argumentPath) {
56
57
var subType = getPropType ( argumentPath ) ;
57
58
58
59
if ( subType . name === 'unknown' ) {
59
- type . value = recast . print ( argumentPath ) . code ;
60
+ type . value = printValue ( argumentPath ) ;
60
61
type . computed = true ;
61
62
} else {
62
63
type . value = subType ;
@@ -84,7 +85,7 @@ function getPropTypeShape(argumentPath) {
84
85
function getPropTypeInstanceOf ( argumentPath ) {
85
86
return {
86
87
name : 'instanceOf' ,
87
- value : recast . print ( argumentPath ) . code
88
+ value : printValue ( argumentPath )
88
89
} ;
89
90
}
90
91
@@ -144,7 +145,7 @@ function getPropType(path: NodePath): PropTypeDescriptor {
144
145
propTypes . hasOwnProperty ( node . callee . name ) ) {
145
146
descriptor = propTypes [ node . callee . name ] ( path . get ( 'arguments' , 0 ) ) ;
146
147
} else {
147
- descriptor = { name : 'custom' , raw : recast . print ( path ) . code } ;
148
+ descriptor = { name : 'custom' , raw : printValue ( path ) } ;
148
149
}
149
150
}
150
151
return descriptor ;
0 commit comments