1 | # babel-plugin-flow-comments
|
2 |
|
3 | Turn flow type annotations into comments.
|
4 |
|
5 | You should be able to use this plugin instead of `babel-plugin-flow-strip-types` to preserve the `/* @flow */` directive and still use flow.
|
6 |
|
7 | http://flowtype.org/blog/2015/02/20/Flow-Comments.html
|
8 |
|
9 | ## Example
|
10 |
|
11 | **In**
|
12 |
|
13 | ```javascript
|
14 | function foo(bar?) {}
|
15 | function foo2(bar?: string) {}
|
16 | function foo(x: number): string {}
|
17 | type B = {
|
18 | name: string;
|
19 | };
|
20 | export type GraphQLFormattedError = number;
|
21 | import type A, { B, C } from './types';
|
22 | import typeof D, { E, F } from './types';
|
23 | ```
|
24 |
|
25 | **Out**
|
26 |
|
27 | ```javascript
|
28 | "use strict";
|
29 |
|
30 | function foo(bar /*:: ?*/) {}
|
31 | function foo2(bar /*:: ?: string*/) {}
|
32 | function foo(x /*: number*/) /*: string*/ {}
|
33 | /*:: type B = {
|
34 | name: string;
|
35 | };*/
|
36 | /*:: export type GraphQLFormattedError = number;*/
|
37 | /*:: import type A, { B, C } from './types';*/
|
38 | /*:: import typeof D, { E, F } from './types';*/
|
39 | ```
|
40 |
|
41 | ## Installation
|
42 |
|
43 | ```sh
|
44 | $ npm install babel-plugin-flow-comments
|
45 | ```
|
46 |
|
47 | ## Usage
|
48 |
|
49 | ### Via `.babelrc` (Recommended)
|
50 |
|
51 | **.babelrc**
|
52 |
|
53 | ```json
|
54 | {
|
55 | "plugins": ["flow-comments"]
|
56 | }
|
57 | ```
|
58 |
|
59 | ### Via CLI
|
60 |
|
61 | ```sh
|
62 | $ babel --plugins flow-comments script.js
|
63 | ```
|
64 |
|
65 | ### Via Node API
|
66 |
|
67 | ```javascript
|
68 | require("babel-core").transform("code", {
|
69 | plugins: ["flow-comments"]
|
70 | });
|
71 | ```
|