Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Unify comment formatting inside the empty blocks #647

Merged
merged 21 commits into from
Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
- Fix location issue in error messages with JSX V4 where the body of the component is an application https://github.com/rescript-lang/syntax/pull/633
- Fix issue where the printer would omit attributes for `->` and `|>` https://github.com/rescript-lang/syntax/pull/629
- Fix printing of optional fields in records https://github.com/rescript-lang/rescript-compiler/issues/5654
- Fix printing of comments inside empty blocks https://github.com/rescript-lang/syntax/pull/647
- Fix location issue in error messages with JSX V4 where the multiple props types are defined https://github.com/rescript-lang/syntax/pull/655

## ReScript 10.0
Expand Down
44 changes: 25 additions & 19 deletions src/res_comments_table.ml
Original file line number Diff line number Diff line change
Expand Up @@ -692,9 +692,11 @@ and walkTypeDeclaration (td : Parsetree.type_declaration) t comments =
| Ptype_abstract | Ptype_open -> rest
| Ptype_record labelDeclarations ->
let () =
walkList
(labelDeclarations |> List.map (fun ld -> LabelDeclaration ld))
t rest
if labelDeclarations = [] then attach t.inside td.ptype_loc rest
else
walkList
(labelDeclarations |> List.map (fun ld -> LabelDeclaration ld))
t rest
in
[]
| Ptype_variant constructorDeclarations ->
Expand Down Expand Up @@ -1023,22 +1025,26 @@ and walkExpression expr t comments =
| Pexp_array exprs | Pexp_tuple exprs ->
walkList (exprs |> List.map (fun e -> Expression e)) t comments
| Pexp_record (rows, spreadExpr) ->
let comments =
match spreadExpr with
| None -> comments
| Some expr ->
let leading, inside, trailing = partitionByLoc comments expr.pexp_loc in
attach t.leading expr.pexp_loc leading;
walkExpression expr t inside;
let afterExpr, rest =
partitionAdjacentTrailing expr.pexp_loc trailing
in
attach t.trailing expr.pexp_loc afterExpr;
rest
in
walkList
(rows |> List.map (fun (li, e) -> ExprRecordRow (li, e)))
t comments
if rows = [] then attach t.inside expr.pexp_loc comments
else
let comments =
match spreadExpr with
| None -> comments
| Some expr ->
let leading, inside, trailing =
partitionByLoc comments expr.pexp_loc
in
attach t.leading expr.pexp_loc leading;
walkExpression expr t inside;
let afterExpr, rest =
partitionAdjacentTrailing expr.pexp_loc trailing
in
attach t.trailing expr.pexp_loc afterExpr;
rest
in
walkList
(rows |> List.map (fun (li, e) -> ExprRecordRow (li, e)))
t comments
| Pexp_field (expr, longident) ->
let leading, inside, trailing = partitionByLoc comments expr.pexp_loc in
let trailing =
Expand Down
Loading