Skip to content

Commit b8428cf

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

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

jscomp/syntax/src/res_printer.ml

+16-6
Original file line numberDiff line numberDiff line change
@@ -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)