Skip to content
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 @@ -23,6 +23,7 @@
#### :bug: Bug fix

- Fix directive `@warning("-102")` not working. https://github.com/rescript-lang/rescript/pull/8322
- Fix duplicated comments in `for`..`of` formatter. https://github.com/rescript-lang/rescript/pull/8395

#### :memo: Documentation

Expand Down
25 changes: 22 additions & 3 deletions compiler/syntax/src/res_comments_table.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1825,9 +1825,28 @@ and walk_expression expr t comments =
| Pexp_await expr -> walk_expression expr t comments
| Pexp_for_of (pattern, expr1, expr2)
| Pexp_for_await_of (pattern, expr1, expr2) ->
walk_pattern pattern t comments;
walk_expression expr1 t comments;
walk_expression expr2 t comments
let leading, inside, trailing =
partition_by_loc comments pattern.ppat_loc
in
attach t.leading pattern.ppat_loc leading;
walk_pattern pattern t inside;
let after_pattern, rest =
partition_adjacent_trailing pattern.ppat_loc trailing
in
attach t.trailing pattern.ppat_loc after_pattern;
let leading, inside, trailing = partition_by_loc rest expr1.pexp_loc in
attach t.leading expr1.pexp_loc leading;
walk_expression expr1 t inside;
let after_expr, rest =
partition_adjacent_trailing expr1.pexp_loc trailing
in
attach t.trailing expr1.pexp_loc after_expr;
if is_block_expr expr2 then walk_expression expr2 t rest
else
let leading, inside, trailing = partition_by_loc rest expr2.pexp_loc in
attach t.leading expr2.pexp_loc leading;
walk_expression expr2 t inside;
attach t.trailing expr2.pexp_loc trailing
| Pexp_send _ -> ()

and walk_expr_parameter (_attrs, _argLbl, expr_opt, pattern) t comments =
Expand Down
12 changes: 12 additions & 0 deletions tests/syntax_tests/data/printer/comments/expected/expr.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,18 @@ for /* c0 */ i /* c1 */ in /* c2 */ 0 /* c3 */ to /* c4 */ 10 /* c5 */ {
/* c6 */ doStuff() /* c7 */
} // trailing

// Pexp_for_of
for /* c0 */ x /* c1 */ of /* c2 */ xs /* c3 */ {
// c4
doStuff()
} // trailing

// Pexp_for_await_of
for await /* c0 */ x /* c1 */ of /* c2 */ xs /* c3 */ {
// c4
doStuff()
} // trailing

// Pexp_pack
/* c0 */ module(/* c1 */ ModExpr /* c2 */) /* c3 */
/* c0 */ let /* c1 */ three /* c2 */ = /* c3 */ module(/* c4 */ Three /* c5 */) /* c6 */
Expand Down
12 changes: 12 additions & 0 deletions tests/syntax_tests/data/printer/comments/expr.res
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,18 @@ for /* c0 */ i /* c1 */ in /* c2 */ 0 /* c3 */ to /* c4 */ 10 /* c5 */ {
/* c6 */ doStuff() /* c7 */
} // trailing

// Pexp_for_of
for /* c0 */ x /* c1 */ of /* c2 */ xs /* c3 */ {
// c4
doStuff()
} // trailing

// Pexp_for_await_of
for await /* c0 */ x /* c1 */ of /* c2 */ xs /* c3 */ {
// c4
doStuff()
} // trailing

// Pexp_pack
/* c0 */ module(/* c1 */ ModExpr /* c2 */) /* c3 */
/* c0 */ let /* c1 */ three /* c2 */ = /* c3 */ module( /* c4 */Three /* c5 */) /* c6 */
Expand Down
Loading