We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 976e484 commit 85d50f9Copy full SHA for 85d50f9
src/parsers/parse_to_ast.js
@@ -21,6 +21,20 @@ const opts = {
21
]
22
};
23
24
+/**
25
+ * Convert flow comment types into flow annotations so that
26
+ * they end up in the final AST. If the source does not contain
27
+ * a flow pragma, the code is returned verbatim.
28
+ * @param {*} source code with flow type comments
29
+ * @returns {string} code with flow annotations
30
+ */
31
+function commentToFlow(source) {
32
+ if (!/@flow/.test(source)) return source;
33
+ return source
34
+ .replace(/\/\*::([^]+?)\*\//g, '$1')
35
+ .replace(/\/\*:\s*([^]+?)\s*\*\//g, ':$1');
36
+}
37
+
38
export function parseToAst(source: string) {
- return babylon.parse(source, opts);
39
+ return babylon.parse(commentToFlow(source), opts);
40
}
0 commit comments