File tree Expand file tree Collapse file tree 3 files changed +41
-1
lines changed
Expand file tree Collapse file tree 3 files changed +41
-1
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ } ) ;
Original file line number Diff line number Diff 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 ( ! / @ f l o w / . test ( source ) ) return source ;
3333 return source
3434 . replace ( / \/ \* : : ( [ ^ ] + ?) \* \/ / g, '$1' )
You can’t perform that action at this time.
0 commit comments