@@ -113,26 +113,16 @@ let hasNestedJsxOrMoreThanOneChild expr =
113
113
in
114
114
loop false expr
115
115
116
- let hasTailSingleLineComment tbl loc =
117
- let rec getLastElement elements =
118
- match elements with
119
- | [] -> None
120
- | [element] -> Some element
121
- | _ :: rest -> getLastElement rest
122
- in
123
- match Hashtbl. find_opt tbl.CommentTable. trailing loc with
124
- | None -> false
125
- | Some comments -> (
126
- let lastComment = getLastElement comments in
127
- match lastComment with
128
- | None -> false
129
- | Some comment -> Comment. isSingleLineComment comment)
130
-
131
116
let hasCommentsInside tbl loc =
132
117
match Hashtbl. find_opt tbl.CommentTable. inside loc with
133
118
| None -> false
134
119
| _ -> true
135
120
121
+ let hasTrailingComments tbl loc =
122
+ match Hashtbl. find_opt tbl.CommentTable. trailing loc with
123
+ | None -> false
124
+ | _ -> true
125
+
136
126
let printMultilineCommentContent txt =
137
127
(* Turns
138
128
* |* first line
@@ -4058,18 +4048,15 @@ and printJsxExpression ~customLayout lident args cmtTbl =
4058
4048
when isSelfClosing ->
4059
4049
Doc. text " />"
4060
4050
| _ ->
4061
- (* if last trailing comment of tag is single line comment then put > on the next line
4051
+ (* if tag A has trailing comments then put > on the next line
4062
4052
<A
4063
- // single line comment
4053
+ // comments
4064
4054
>
4065
4055
</A>
4066
4056
*)
4067
- if hasTailSingleLineComment cmtTbl lident.Asttypes. loc then
4057
+ if hasTrailingComments cmtTbl lident.Asttypes. loc then
4068
4058
Doc. concat [Doc. softLine; Doc. greaterThan]
4069
- else
4070
- Doc. ifBreaks
4071
- (Doc. lineSuffix Doc. greaterThan)
4072
- Doc. greaterThan);
4059
+ else Doc. greaterThan);
4073
4060
]);
4074
4061
(if isSelfClosing then Doc. nil
4075
4062
else
@@ -4216,7 +4203,7 @@ and printJsxProps ~customLayout args cmtTbl :
4216
4203
{loc with loc_end = expr.pexp_loc.loc_end}
4217
4204
| _ -> expr.pexp_loc
4218
4205
in
4219
- let tailSingleLineCommentPresent = hasTailSingleLineComment cmtTbl loc in
4206
+ let trailingCommentsPresent = hasTrailingComments cmtTbl loc in
4220
4207
let propDoc = printJsxProp ~custom Layout lastProp cmtTbl in
4221
4208
let formattedProps =
4222
4209
Doc. concat
@@ -4228,8 +4215,8 @@ and printJsxProps ~customLayout args cmtTbl :
4228
4215
Doc. group
4229
4216
(Doc. join ~sep: Doc. line (propDoc :: props |> List. rev));
4230
4217
]);
4231
- (* print > on new line if last comment is single line comment *)
4232
- (match (isSelfClosing children, tailSingleLineCommentPresent ) with
4218
+ (* print > on new line if the last prop has trailing comments *)
4219
+ (match (isSelfClosing children, trailingCommentsPresent ) with
4233
4220
(* we always put /> on a new line when a self-closing tag breaks *)
4234
4221
| true , _ -> Doc. line
4235
4222
| false , true -> Doc. softLine
0 commit comments