File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed
Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,11 @@ var oneToOne = {
1111 }
1212} ;
1313
14+ var literalTypes = {
15+ 'StringLiteralTypeAnnotation' : 'StringLiteral' ,
16+ 'NumberLiteralTypeAnnotation' : 'NumberLiteral'
17+ } ;
18+
1419function flowDoctrine ( type ) {
1520
1621 if ( type . type in namedTypes ) {
@@ -56,6 +61,13 @@ function flowDoctrine(type) {
5661 name : type . id . name
5762 } ;
5863 }
64+
65+ if ( type . type in literalTypes ) {
66+ return {
67+ type : literalTypes [ type . type ] ,
68+ name : type . value
69+ } ;
70+ }
5971}
6072
6173module . exports = flowDoctrine ;
Original file line number Diff line number Diff line change @@ -112,6 +112,22 @@ test('flowDoctrine', function (t) {
112112 name : 'undefined'
113113 } , 'undefined' ) ;
114114
115+ t . deepEqual ( flowDoctrine ( toComment (
116+ "/** add */function add(a: \"value\") { }"
117+ ) . context . ast . value . params [ 0 ] . typeAnnotation . typeAnnotation ) ,
118+ {
119+ type : 'StringLiteral' ,
120+ name : 'value'
121+ } , 'StringLiteral' ) ;
122+
123+ t . deepEqual ( flowDoctrine ( toComment (
124+ "/** add */function add(a: 1) { }"
125+ ) . context . ast . value . params [ 0 ] . typeAnnotation . typeAnnotation ) ,
126+ {
127+ type : 'NumberLiteral' ,
128+ name : '1'
129+ } , 'NumberLiteral' ) ;
130+
115131 t . end ( ) ;
116132} ) ;
117133/* eslint-enable */
You can’t perform that action at this time.
0 commit comments