Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip trailing comma in explicit partial application #6949

Merged
Changes from 1 commit
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
22 changes: 16 additions & 6 deletions jscomp/syntax/src/res_printer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4730,6 +4730,20 @@ and print_arguments ~state ?(partial = false)
in
Doc.concat [Doc.lparen; arg_doc; Doc.rparen]
| args ->
(* Avoid printing trailing comma when there is ... in function application *)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it matters whether to check if ... happens at the end because that's already considered as syntax error.

let hasDotDotDot, printed_args =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would you do a little search if this functionality already exists somewhere else?
I kind of don't even remember using ... verbatim as label, instead of some other attribute.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what I see in the parser let attrs = if is_partial then [res_partial_attr] else [] in
so I'm not sure your code runs? In any case, adding a test will answer this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The label does not exist. In the ast.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think of it as app1(f, args) vs app2(f, args)

One being total and the other partial.
Internally the distinction is only the presence of the attribute.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So "..." only exists as string in the source, but that's not how it's represented in the AST.

List.fold_right
(fun arg (flag, acc) ->
let arg_lbl, _ = arg in
let hasDotDotDot =
match arg_lbl with
| Asttypes.Labelled "..." -> true
| _ -> false
in
let doc = print_argument ~state arg cmt_tbl in
(flag || hasDotDotDot, doc :: acc))
args (false, [])
in
Doc.group
(Doc.concat
[
Expand All @@ -4738,13 +4752,9 @@ and print_arguments ~state ?(partial = false)
(Doc.concat
[
Doc.soft_line;
Doc.join
~sep:(Doc.concat [Doc.comma; Doc.line])
(List.map
(fun arg -> print_argument ~state arg cmt_tbl)
args);
Doc.join ~sep:(Doc.concat [Doc.comma; Doc.line]) printed_args;
]);
(if partial then Doc.nil else Doc.trailing_comma);
(if partial || hasDotDotDot then Doc.nil else Doc.trailing_comma);
Doc.soft_line;
Doc.rparen;
])
Expand Down