Skip to content

Commit 94140dc

Browse files
committed
Merge pull request #325 from researchgate/master
Add support for Flow literal string/number types
2 parents 34b647f + 03df725 commit 94140dc

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

lib/flow_doctrine.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ var oneToOne = {
1111
}
1212
};
1313

14+
var literalTypes = {
15+
'StringLiteralTypeAnnotation': 'StringLiteral',
16+
'NumberLiteralTypeAnnotation': 'NumberLiteral'
17+
};
18+
1419
function 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

6173
module.exports = flowDoctrine;

test/lib/flow_doctrine.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff 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 */

0 commit comments

Comments
 (0)