Source file comment_utils.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
let loc =
let rec helper loc acc = function
| ((c_loc, _) as ) :: rest when Loc.compare c_loc loc < 0 ->
helper loc (comment :: acc) rest
| _ -> List.rev acc
in
helper loc [] comments
class ['loc] =
object
inherit ['loc] Flow_ast_mapper.mapper
method! syntax_opt
: 'internal.
('loc, 'internal) Flow_ast.Syntax.t option -> ('loc, 'internal) Flow_ast.Syntax.t option =
(fun _ -> None)
end
let p = (new inline_comments_stripper)#program p
let expr = (new inline_comments_stripper)#expression expr
let
?(preserve_docblock = false) ((loc, program) : ('loc, 'loc) Flow_ast.Program.t) =
let { ; _ } = program in
( loc,
{
program with
Flow_ast.Program.all_comments =
( if preserve_docblock then
comments_before_loc loc all_comments
else
[]
);
}
)
let ?(preserve_docblock = false) p =
p |> strip_comments_list ~preserve_docblock |> strip_inlined_comments