Destructuring: Add early errors for empty patterns?

Herby Vojčík herby at mailbox.sk
Wed Oct 21 18:25:11 UTC 2015


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.

Herby

Standards Zakas wrote:
> Hi all,
>
> 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 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:
>
> ```
> let { bar: {} } = foo;
> ```
>
> 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.
>
>
> --
> ________________________________________
> Nicholas C. Zakas
> http://www.nczonline.net
> @slicknet
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss


More information about the es-discuss mailing list