Skip to content

Commit 91c283e

Browse files
committed
WIP: Fix unary tag comments handling
1 parent ff1bb65 commit 91c283e

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

compiler/syntax/src/res_comments_table.ml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ let copy tbl =
2424

2525
let empty = make ()
2626

27-
let print_loc (k : Warnings.loc) =
27+
let print_location (k : Warnings.loc) =
2828
Doc.concat
2929
[
3030
Doc.lbracket;
@@ -41,7 +41,7 @@ let print_loc (k : Warnings.loc) =
4141
let print_entries tbl =
4242
Hashtbl.fold
4343
(fun (k : Location.t) (v : Comment.t list) acc ->
44-
let loc = print_loc k in
44+
let loc = print_location k in
4545
let doc =
4646
Doc.breakable_group ~force_break:true
4747
(Doc.concat
@@ -1472,9 +1472,22 @@ and walk_expression expr t comments =
14721472
in
14731473
let xs = exprs |> List.map (fun e -> Expression e) in
14741474
walk_list xs t rest
1475-
| Pexp_jsx_unary_element _ ->
1476-
(* TODO: save me shulhi, not sure what needs to be done here *)
1477-
()
1475+
| Pexp_jsx_unary_element {jsx_unary_element_props = props} ->
1476+
let xs = List.filter_map (fun prop ->
1477+
match prop with
1478+
| Parsetree.JSXPropPunning (_, _) -> None
1479+
| Parsetree.JSXPropValue ({txt; loc}, _, expr) ->
1480+
let () = print_endline txt in
1481+
let () = print_location loc |> Doc.to_string ~width:80 |> print_endline in
1482+
let () = print_location expr.pexp_loc|> Doc.to_string ~width:80 |> print_endline in
1483+
let () = log t in
1484+
let (_leading, _inside, trailing) = partition_by_loc comments expr.pexp_loc in
1485+
let after_expr, _ = partition_adjacent_trailing expr.pexp_loc trailing in
1486+
attach t.trailing expr.pexp_loc after_expr;
1487+
Some (Expression expr)
1488+
| Parsetree.JSXPropSpreading (_loc, expr) -> Some (Expression expr)
1489+
) props in
1490+
walk_list xs t []
14781491
| Pexp_jsx_container_element
14791492
{
14801493
jsx_container_element_opening_tag_end = opening_greater_than;

0 commit comments

Comments
 (0)