@@ -113,26 +113,16 @@ let hasNestedJsxOrMoreThanOneChild expr =
113113 in
114114 loop false expr
115115
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-
131116let hasCommentsInside tbl loc =
132117 match Hashtbl. find_opt tbl.CommentTable. inside loc with
133118 | None -> false
134119 | _ -> true
135120
121+ let hasTrailingComments tbl loc =
122+ match Hashtbl. find_opt tbl.CommentTable. trailing loc with
123+ | None -> false
124+ | _ -> true
125+
136126let printMultilineCommentContent txt =
137127 (* Turns
138128 * |* first line
@@ -4058,18 +4048,15 @@ and printJsxExpression ~customLayout lident args cmtTbl =
40584048 when isSelfClosing ->
40594049 Doc. text " />"
40604050 | _ ->
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
40624052 <A
4063- // single line comment
4053+ // comments
40644054 >
40654055 </A>
40664056 *)
4067- if hasTailSingleLineComment cmtTbl lident.Asttypes. loc then
4057+ if hasTrailingComments cmtTbl lident.Asttypes. loc then
40684058 Doc. concat [Doc. softLine; Doc. greaterThan]
4069- else
4070- Doc. ifBreaks
4071- (Doc. lineSuffix Doc. greaterThan)
4072- Doc. greaterThan);
4059+ else Doc. greaterThan);
40734060 ]);
40744061 (if isSelfClosing then Doc. nil
40754062 else
@@ -4216,7 +4203,7 @@ and printJsxProps ~customLayout args cmtTbl :
42164203 {loc with loc_end = expr.pexp_loc.loc_end}
42174204 | _ -> expr.pexp_loc
42184205 in
4219- let tailSingleLineCommentPresent = hasTailSingleLineComment cmtTbl loc in
4206+ let trailingCommentsPresent = hasTrailingComments cmtTbl loc in
42204207 let propDoc = printJsxProp ~custom Layout lastProp cmtTbl in
42214208 let formattedProps =
42224209 Doc. concat
@@ -4228,8 +4215,8 @@ and printJsxProps ~customLayout args cmtTbl :
42284215 Doc. group
42294216 (Doc. join ~sep: Doc. line (propDoc :: props |> List. rev));
42304217 ]);
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
42334220 (* we always put /> on a new line when a self-closing tag breaks *)
42344221 | true , _ -> Doc. line
42354222 | false , true -> Doc. softLine
0 commit comments