Destructuring: Add early errors for empty patterns?
IMO this is ok, if the pattern is empty, nothing is extracted and assigned. I see it similar to using = in expressions: it is probably an error, jshint/IDEs should issue a warning, but I would not make an error out of it (think for example cross-compilers who can produce dynamic destucturing assignments and they would need to parse it for "emptiness"); not consistent if special cases are errors.
Just noticed Allen filed this: tc39/ecma262#97
On 21 October 2015 at 20:19, Standards Zakas <standards at nczconsulting.com> wrote:
In playing with destructuring, it seems like there are some syntax gotchas that really should trigger some sort of error and instead fail silently. For instance:
let {} = foo;
This line does absolutely nothing
Not true. It checks that foo converts to an object, which may throw a type error for null or undefined.
In playing with destructuring, it seems like there are some syntax gotchas that really should trigger some sort of error and instead fail silently. For instance:
This line does absolutely nothing and is most likely an error on the developer's part. However, this is completely valid syntax and not a parsing error. Fortunately, it's pretty clear from looking at it that there's a problem. Another example isn't so clear:
This one, I'd argue, is even worse. It looks like it should do something, but silently does nothing.
Is there any possibility to add an early error for empty destructuring patterns (array and object)? It seems like this would save developers a lot of trouble in the long run.