This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.
Could we allow trailing commas in Web IDL? Trailing commas are desired by many stylistically (for consistency and clearer diffs), and also make automated output of lists easier. Further, trailing commas being not allowed are a frequent cause of syntax errors, notably in ECMAScript 3 and in JSON. I've just been fixing trailing commas in Chromium; this is fiddly to fix and many developers would prefer that trailing commas be allowed. Relevant bug: Chromium 242800 https://code.google.com/p/chromium/issues/detail?id=242800 Hixie also suggested this over at Bug 21589 - SelectionMode enum should not have a trailing comma ...in Comment 2: https://www.w3.org/Bugs/Public/show_bug.cgi?id=21589#c2 Concretely, I think we just need to replace [[ | ε ]] with [[ | "," | ε ]] ...in any production rule for the tail of a list. Alternatively, we could add a "CommaOrNone" rule: [[ CommaOrNone → "," | ε ]] So long as the tail of the list can't be empty, this does not introduce any ambiguity. Looking at the grammar http://dev.w3.org/2006/webapi/WebIDL/#idl-grammar ...I see the following rules for tails of lists: [[ [22] EnumValues [36] Identifiers [54] Arguments [62] ExtendedAttributes ]] ...and in all cases the tail current must be non-empty, so allowing trailing commas would be ok. Of these, [62] ExtendedAttributes and [22] EnumValues seem the most important cases, as these are often rather long vertical lists, but for consistency it seems best to allow a trailing comma for any of these. For reference, ES5 added support for trailing commas (though ES3 did not allow them, and this is a very common cause of errors), and JSON does not allow trailing commas, while many languages allow them (C, Java, Python). References http://en.wikipedia.org/wiki/Coding_conventions#Lists http://stackoverflow.com/questions/7246618/trailing-commas-in-javascript http://stackoverflow.com/questions/201782/can-you-use-a-trailing-comma-in-a-json-object ES3 and ES5 spec: ES3: [[ ObjectLiteral : { } { PropertyNameAndValueList } ]] ES5: [[ ObjectLiteral : { } { PropertyNameAndValueList } { PropertyNameAndValueList , } ]]
This subsumes the bug: Bug 17508 - Let enum lists end with a comma ...which is only about enums.
Trailing commas for enums were allowed in the other bug, but I'm not doing it for extended attributes unless there is more demand.
Thanks Cameron - understood. In Chromium (specifically Blink) we have high demand for trailing commas on extended attributes, due to using them extensively in the bindings, but if these aren't widely used outside of Chromium, I understand not having it in the spec (we can have a dialect difference). If other users turn out to use these, we can revisit the issue, otherwise ok with WONTFIX.
(In reply to comment #2) > Trailing commas for enums were allowed in the other bug, but I'm not doing > it for extended attributes unless there is more demand. It's pretty bizarre if a language allows trailing commas in *some* comma-separated syntax constructs, but not others.
(In reply to comment #4) > (In reply to comment #2) > > Trailing commas for enums were allowed in the other bug, but I'm not doing > > it for extended attributes unless there is more demand. > > It's pretty bizarre if a language allows trailing commas in *some* > comma-separated syntax constructs, but not others. Not unheard of that only some comma-separated syntax constructs in a language allow a trailing comma. In JS [1,2,] is fine yet function(a,b,){} isn't. *shrug*
Note that the JS trailing comma inconsistency argument will be invalid in ES7, after the following proposal makes its way through the committee: https://github.com/jeffmo/es-trailing-function-commas I also support this feature request. It is odd that trailing commas are allowed in some contexts and not others. Is there any argument against this feature other than "I'm not doing it"?