ArrayBindingPattern disallows trailing comma when BindingRestElement is present

# Michael Ficarra (10 years ago)

Is there any reason why a trailing comma is not allowed in an ArrayBindingPattern when it has a BindingRestElement? I noticed yesterday that my parser was erroneously allowing these, but the inconsistency with both ArrayLiterals and ObjectBindingPatterns is bothering me. Is this simply a mistake in the grammar? I understand that we wouldn't want to allow holes or other BindingElements to follow the BindingRestElement, but I don't see a problem with a single trailing comma.

Michael Ficarra

# Caitlin Potter (10 years ago)

Is this simply a mistake in the grammar?

The grammar appears to allow trailing comma after rest elements, so I think it’s an implementation error.

# Caitlin Potter (10 years ago)

Actually, I guess I'm misreading that. It really doesn't allow trailing commas after a rest element. My bad =)

# Allen Wirfs-Brock (10 years ago)

On Feb 12, 2015, at 7:01 PM, Michael Ficarra wrote:

Is there any reason why a trailing comma is not allowed in an ArrayBindingPattern when it has a BindingRestElement? I noticed yesterday that my parser was erroneously allowing these, but the inconsistency with both ArrayLiterals and ObjectBindingPatterns is bothering me. Is this simply a mistake in the grammar? I understand that we wouldn't want to allow holes or other BindingElements to follow the BindingRestElement, but I don't see a problem with a single trailing comma.

This has been discussed in the past, if you should the archives of this list.

Trailing comma are intended to make it easy for for humans or machines to append additional items to the source code of a list. But, a rest item must always be the last (right-most) item of a list. There is no possibility of adding something to its right and hence no reason to allow a training comma.

# Brendan Eich (10 years ago)

Please file a bug, ASAP. Thanks,

# Michael Ficarra (10 years ago)

Even given what Allen said? I'm indifferent toward it at this point. Allen is right that it's not particularly useful to allow it, but disallowing it is also inconsistent with all related productions.

# Allen Wirfs-Brock (10 years ago)

On Feb 13, 2015, at 11:37 AM, Michael Ficarra wrote:

Even given what Allen said? I'm indifferent toward it at this point. Allen is right that it's not particularly useful to allow it, but disallowing it is also inconsistent with all related productions.

You can submit it, but I'll just mark it as deferred for ES7 consideration.

Syntax Errors like this are future proof in the sense, that they can always be related in the future without breaking anything.

# Brendan Eich (10 years ago)

Thanks, sounds good.

(Michael, my "file a bug" reply was to get it recorded, not to say it was stop-ship or even must-fix. ;-)

# Caitlin Potter (10 years ago)

Reading the spec today while working on a fix jshint/jshint/commit/7a2b713e9e874910890339660d4f00d16966e99d, it looks to me like trailing commas are not allowed at all in ArrayBindingPattern, whether there is a rest element or not.

Is this intentional?

# Kevin Smith (10 years ago)

Trailing commas are fine (but not after the rest element):

[ BindingElementList[?Yield, ?GeneratorParameter] , Elisionopt BindingRestElement[?Yield, ?GeneratorParameter]opt]

The BindingRestElement is optional in the above production, allowing Elision to be the final non-terminal (before the closing bracket).