Skip to content

Commit 9aa6b1a

Browse files
committed
Check for dotdotdot in args
1 parent 8a28daf commit 9aa6b1a

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

jscomp/syntax/src/res_printer.ml

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4193,7 +4193,7 @@ and print_pexp_apply ~state expr cmt_tbl =
41934193
args_doc;
41944194
]
41954195
else
4196-
let args_doc = print_arguments ~state ~partial args cmt_tbl in
4196+
let args_doc = print_arguments ~state ~partial:true args cmt_tbl in
41974197
Doc.concat
41984198
[print_attributes ~state attrs cmt_tbl; call_expr_doc; args_doc]
41994199
| _ -> assert false
@@ -4730,6 +4730,20 @@ and print_arguments ~state ?(partial = false)
47304730
in
47314731
Doc.concat [Doc.lparen; arg_doc; Doc.rparen]
47324732
| args ->
4733+
(* Avoid printing trailing comma when there is ... in function application *)
4734+
let hasDotDotDot, printed_args =
4735+
List.fold_right
4736+
(fun arg (flag, acc) ->
4737+
let arg_lbl, _ = arg in
4738+
let hasDotDotDot =
4739+
match arg_lbl with
4740+
| Asttypes.Labelled "..." -> true
4741+
| _ -> false
4742+
in
4743+
let doc = print_argument ~state arg cmt_tbl in
4744+
(flag || hasDotDotDot, doc :: acc))
4745+
args (false, [])
4746+
in
47334747
Doc.group
47344748
(Doc.concat
47354749
[
@@ -4738,13 +4752,9 @@ and print_arguments ~state ?(partial = false)
47384752
(Doc.concat
47394753
[
47404754
Doc.soft_line;
4741-
Doc.join
4742-
~sep:(Doc.concat [Doc.comma; Doc.line])
4743-
(List.map
4744-
(fun arg -> print_argument ~state arg cmt_tbl)
4745-
args);
4755+
Doc.join ~sep:(Doc.concat [Doc.comma; Doc.line]) printed_args;
47464756
]);
4747-
(if partial then Doc.nil else Doc.trailing_comma);
4757+
(if partial || hasDotDotDot then Doc.nil else Doc.trailing_comma);
47484758
Doc.soft_line;
47494759
Doc.rparen;
47504760
])

0 commit comments

Comments
 (0)