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

Allow trailing comma in argument list #1989

Closed
back2dos opened this issue Jul 15, 2013 · 9 comments
Closed

Allow trailing comma in argument list #1989

back2dos opened this issue Jul 15, 2013 · 9 comments

Comments

@back2dos
Copy link
Member

While it's not particularly important, I would think it would be rather comfortable to allow trailing commas in argument lists. It's allowed for array and object literals, so I think it would be rather consistent and I don't see it causing any problems.

@Simn
Copy link
Member

Simn commented Jul 24, 2013

Is this allowed in ECMA?

@back2dos
Copy link
Member Author

Nope. But ECMA and Haxe have rather different approaches to optionality of delimiters anyway ;)
Trailing commas in arrays and objects are not allowed in ECMA either.

But I do quite appreciate them, because if you have this:

[
    "foo",
    "bar",
    "baz",
]

You can comment out/transpose any entries without breaking syntax.

@rockswang
Copy link

Agreed, the trailing comma in array definition is valid in Java & Haxe.
If it's proved there's no any side-effect I'd like the similiar tolerance also apply to function argument list.

@ncannasse
Copy link
Member

I'm not sure about the potential side effects, since we're in a ( ) block instead of a { } , I guess this have more chances of causing some issues such as letting pass some code while the user didn't meant it. I vote that we don't touch this now.

@back2dos
Copy link
Member Author

After the parser encounters a comma in the argument list, it expects an expression. If the next token is a closing parenthesis instead, it could just act as though the comma had not existed. There is simply no room for unintended side effects.

@Aurel300
Copy link
Member

Aurel300 commented Sep 21, 2020

I would like to see this, both in the argument lists and function calls.

function a(
  arg1:X,
  arg2:Y,
):Z { ... }
a(
  arg1,
  arg2,
);

It is just very convenient to be able to reorder or easily add/delete lines in examples like the ones above. It's also nice when you want to enable/disable arguments to functions with conditional compilation. And finally it would be consistent with our array and map literals now.

(Just realised I'm basically restating @back2dos 's points x)

@Simn
Copy link
Member

Simn commented Sep 21, 2020

I kinda hate how that trailing comma looks, but I acknowledge that it's very useful for copy & pasting.

@Simn Simn reopened this Sep 21, 2020
@RealyUniqueName RealyUniqueName added this to the Backlog milestone Sep 21, 2020
@dpomier
Copy link
Contributor

dpomier commented Sep 21, 2020

Could the code editor automatically add/remove the trailing comma when commenting out/transposing? It would reconcile nice-looking comma with very easy manipulations.

@RblSb RblSb mentioned this issue Dec 10, 2021
3 tasks
@back2dos
Copy link
Member Author

Closing in favor of #10159

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants