File tree Expand file tree Collapse file tree 4 files changed +28
-1
lines changed
Expand file tree Collapse file tree 4 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -353,6 +353,10 @@ let tuple_equal = ((csu, mgd)) =>
353353 */
354354let fun_def_comment_inline = () => {/* */ };
355355
356+ let fun_def_comment_newline = () => {
357+ //
358+ };
359+
356360let fun_def_comment_long = () => {
357361 /* longer comment inside empty function body */
358362};
Original file line number Diff line number Diff line change @@ -361,6 +361,10 @@ let tuple_equal((csu, mgd)) =
361361 */
362362let fun_def_comment_inline = () => { /* */ };
363363
364+ let fun_def_comment_newline = () => {
365+ //
366+ };
367+
364368let fun_def_comment_long = () => { /* longer comment inside empty function body */ };
365369
366370let trueThing = true ;
Original file line number Diff line number Diff line change @@ -48,3 +48,7 @@ let is_doc t =
4848
4949let make ~location category text =
5050 { text; category; location }
51+
52+ let isLineComment {category; text} = match category with
53+ | SingleLine -> Reason_syntax_util. isLineComment text
54+ | EndOfLine | Regular -> false
Original file line number Diff line number Diff line change @@ -1487,7 +1487,22 @@ let rec insertSingleLineComment layout comment =
14871487 | Easy _ ->
14881488 prependSingleLineComment comment layout
14891489 | Sequence (listConfig , subLayouts ) when subLayouts == [] ->
1490- (* If there are no subLayouts (empty body), create a Sequence of just the comment *)
1490+ (* If there are no subLayouts (empty body), create a Sequence of just the
1491+ * comment. We need to be careful when the empty body contains a //-style
1492+ * comment. Example:
1493+ * let make = () => {
1494+ * //
1495+ * };
1496+ * It is clear that the sequence needs to always break here, otherwise
1497+ * we get a parse error: let make = () => { // };
1498+ * The closing brace and semicolon `};` would become part of the comment…
1499+ *)
1500+ let listConfig =
1501+ if Reason_comment. isLineComment comment then
1502+ {listConfig with break = Always_rec }
1503+ else
1504+ listConfig
1505+ in
14911506 Sequence (listConfig, [formatComment comment])
14921507 | Sequence (listConfig , subLayouts ) ->
14931508 let (beforeComment, afterComment) =
You can’t perform that action at this time.
0 commit comments