Skip to content

Commit 46ee751

Browse files
fgnasstmcw
authored andcommitted
test: flow comment types
1 parent 85d50f9 commit 46ee751

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// @flow
2+
3+
/*::
4+
type Foo = {
5+
foo: number,
6+
bar: boolean,
7+
baz: string
8+
};
9+
*/
10+
11+
class MyClass {
12+
/*:: prop: Foo; */
13+
14+
method(value /*: Foo */) /*: boolean */ {
15+
return value.bar;
16+
}
17+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const fs = require('fs');
2+
const {
3+
commentToFlow,
4+
parseToAst
5+
} = require('../../../src/parsers/parse_to_ast');
6+
7+
describe('flow comments', () => {
8+
const f = require.resolve('../../fixture/flow/comment-types');
9+
const src = fs.readFileSync(f, 'utf8');
10+
11+
test('preserve line numbers', () => {
12+
const out = commentToFlow(src);
13+
const linesSrc = src.split(/\n/);
14+
const linesOut = out.split(/\n/);
15+
16+
expect(linesOut).toHaveLength(linesSrc.length);
17+
expect(linesSrc[14]).toEqual(linesOut[14]);
18+
});
19+
20+
test('valid js', () => {
21+
expect(() => parseToAst(src)).not.toThrowError();
22+
});
23+
});

src/parsers/parse_to_ast.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const opts = {
2828
* @param {*} source code with flow type comments
2929
* @returns {string} code with flow annotations
3030
*/
31-
function commentToFlow(source) {
31+
export function commentToFlow(source: string) {
3232
if (!/@flow/.test(source)) return source;
3333
return source
3434
.replace(/\/\*::([^]+?)\*\//g, '$1')

0 commit comments

Comments
 (0)