ArrayBindingPattern disallows trailing comma when BindingRestElement is present
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.
Actually, I guess I'm misreading that. It really doesn't allow trailing commas after a rest element. My bad =)
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.
Please file a bug, ASAP. Thanks,
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.
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.
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. ;-)
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?
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).
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