File tree Expand file tree Collapse file tree 3 files changed +62
-5
lines changed Expand file tree Collapse file tree 3 files changed +62
-5
lines changed Original file line number Diff line number Diff line change @@ -4035,15 +4035,30 @@ and print_binary_expression ~state (expr : Parsetree.expression) cmt_tbl =
40354035and print_belt_array_concat_apply ~state sub_lists cmt_tbl =
40364036 let make_spread_doc comma_before_spread = function
40374037 | Some expr ->
4038+ (* Extract leading comments before dotdotdot *)
4039+ let leading_comments_doc =
4040+ print_leading_comments Doc. nil cmt_tbl.CommentTable. leading
4041+ expr.Parsetree. pexp_loc
4042+ in
4043+ (* Print expression without leading comments (they're already extracted) *)
4044+ let expr_doc =
4045+ let doc = print_expression ~state expr cmt_tbl in
4046+ match Parens. expr expr with
4047+ | Parens. Parenthesized -> add_parens doc
4048+ | Braced braces -> print_braces doc expr braces
4049+ | Nothing -> doc
4050+ in
4051+ (* Print trailing comments with the expression *)
4052+ let expr_with_trailing_comments =
4053+ print_trailing_comments expr_doc cmt_tbl.CommentTable. trailing
4054+ expr.Parsetree. pexp_loc
4055+ in
40384056 Doc. concat
40394057 [
40404058 comma_before_spread;
4059+ leading_comments_doc;
40414060 Doc. dotdotdot;
4042- (let doc = print_expression_with_comments ~state expr cmt_tbl in
4043- match Parens. expr expr with
4044- | Parens. Parenthesized -> add_parens doc
4045- | Braced braces -> print_braces doc expr braces
4046- | Nothing -> doc);
4061+ expr_with_trailing_comments;
40474062 ]
40484063 | None -> Doc. nil
40494064 in
Original file line number Diff line number Diff line change @@ -32,3 +32,23 @@ let _ = [
3232 // comment 2
3333 b , c
3434]
35+
36+ let _ = [
37+ // comment 0
38+ ... xs ,
39+ // comment 1
40+ a ,
41+ // comment 2
42+ b , c
43+ ]
44+
45+ let _ = [
46+ // comment 0
47+ ... xs ,
48+ // comment 1
49+ a ,
50+ // comment 2
51+ ... ys ,
52+ // comment 3
53+ b , c
54+ ]
Original file line number Diff line number Diff line change @@ -27,3 +27,25 @@ let _ = [
2727 b,
2828 c,
2929]
30+
31+ let _ = [
32+ // comment 0
33+ ...xs,
34+ // comment 1
35+ a,
36+ // comment 2
37+ b,
38+ c,
39+ ]
40+
41+ let _ = [
42+ // comment 0
43+ ...xs,
44+ // comment 1
45+ a,
46+ // comment 2
47+ ...ys,
48+ // comment 3
49+ b,
50+ c,
51+ ]
You can’t perform that action at this time.
0 commit comments