|  | 
| 1 | 1 | module Comment = Res_comment | 
| 2 | 2 | module Doc = Res_doc | 
|  | 3 | +module ParsetreeViewer = Res_parsetree_viewer | 
| 3 | 4 | 
 | 
| 4 | 5 | type t = { | 
| 5 | 6 |   leading: (Location.t, Comment.t list) Hashtbl.t; | 
| @@ -1310,9 +1311,43 @@ and walkExpression expr t comments = | 
| 1310 | 1311 |         walkExpression callExpr t inside; | 
| 1311 | 1312 |         after) | 
| 1312 | 1313 |     in | 
| 1313 |  | -    let afterExpr, rest = partitionAdjacentTrailing callExpr.pexp_loc after in | 
| 1314 |  | -    attach t.trailing callExpr.pexp_loc afterExpr; | 
| 1315 |  | -    walkList (arguments |> List.map (fun (_, e) -> ExprArgument e)) t rest | 
|  | 1314 | +    if ParsetreeViewer.isJsxExpression expr then ( | 
|  | 1315 | +      let props = | 
|  | 1316 | +        arguments | 
|  | 1317 | +        |> List.filter (fun (label, _) -> | 
|  | 1318 | +               match label with | 
|  | 1319 | +               | Asttypes.Labelled "children" -> false | 
|  | 1320 | +               | Asttypes.Nolabel -> false | 
|  | 1321 | +               | _ -> true) | 
|  | 1322 | +      in | 
|  | 1323 | +      let maybeChildren = | 
|  | 1324 | +        arguments | 
|  | 1325 | +        |> List.find_opt (fun (label, _) -> | 
|  | 1326 | +               label = Asttypes.Labelled "children") | 
|  | 1327 | +      in | 
|  | 1328 | +      match maybeChildren with | 
|  | 1329 | +      (* There is no need to deal with this situation as the children cannot be NONE *) | 
|  | 1330 | +      | None -> () | 
|  | 1331 | +      | Some (_, children) -> | 
|  | 1332 | +        let leading, inside, _ = partitionByLoc after children.pexp_loc in | 
|  | 1333 | +        if props = [] then | 
|  | 1334 | +          (* All comments inside a tag are trailing comments of the tag if there are no props | 
|  | 1335 | +             <A | 
|  | 1336 | +             // comment | 
|  | 1337 | +             // comment | 
|  | 1338 | +             /> | 
|  | 1339 | +          *) | 
|  | 1340 | +          let afterExpr, _ = | 
|  | 1341 | +            partitionAdjacentTrailing callExpr.pexp_loc after | 
|  | 1342 | +          in | 
|  | 1343 | +          attach t.trailing callExpr.pexp_loc afterExpr | 
|  | 1344 | +        else | 
|  | 1345 | +          walkList (props |> List.map (fun (_, e) -> ExprArgument e)) t leading; | 
|  | 1346 | +        walkExpression children t inside) | 
|  | 1347 | +    else | 
|  | 1348 | +      let afterExpr, rest = partitionAdjacentTrailing callExpr.pexp_loc after in | 
|  | 1349 | +      attach t.trailing callExpr.pexp_loc afterExpr; | 
|  | 1350 | +      walkList (arguments |> List.map (fun (_, e) -> ExprArgument e)) t rest | 
| 1316 | 1351 |   | Pexp_fun (_, _, _, _) | Pexp_newtype _ -> ( | 
| 1317 | 1352 |     let _, parameters, returnExpr = funExpr expr in | 
| 1318 | 1353 |     let comments = | 
|  | 
0 commit comments