archives

« Bugzilla Issues Index

#2653 — Trailing Comma in ArrayBindingPattern, ArrayAssignmentPattern


Generally, a trailing comma in array literals, object literals, array patterns, and object patterns is insignificant. However, under the current grammar, a trailing comma is not allowed after a rest element in an array pattern. Therefore, the following is invalid:

[
a,
b,
...c,
] = x;

For consistency, should a trailing comma be allowed after a rest element in ArrayBindingPattern and ArrayAssignmentPattern?


The general rationale for allowing the trailing commas has been that it is convenient for both human and mechanical code generator who don't necessarily know whether they are dealing with the last element of a list.

However, the rest element is a special case that is always at the end and can never be followed by anything else. In order to generate it, the code generator must know they are at the end of the list.

For that reason, I don't think that the consistency argument applies and and that allowing such a trailing comma would actually be misleading as it suggests that it would be ok to insert something after the comma.

I you still think it should be allowed, you should probably start an es-discuss thread about it.


I agree with your rationale.