Parenthesized destructuring assignment should error
See original GitHub issueWas working with @hzoo on trying to get babel-eslint’s tests running with the ESLint test suite and came across this in our test suite. This passes in ESLint using Espree, but Babylon (babel-eslint’s parser) throws with the following error:
You’re trying to assign to a parenthesized expression, eg. instead of
({a}) = 0
use({a} = 0)
I did a little digging, and it does seem like this shouldn’t be parsed by Espree. Some findings that back this up:
- https://github.com/babel/babel/pull/3260
- http://whereswalden.com/2015/06/20/new-changes-to-make-spidermonkeys-and-firefoxs-parsing-of-destructuring-patterns-more-spec-compliant/
- https://bugzilla.mozilla.org/show_bug.cgi?id=1146136
I also tested in Chrome:
and Firefox:
If this is accepted I’ll also file an issue for Espree (and probably ultimately Acorn as well), but I wanted to have an issue open here so we could discuss and track this issue as well as fix the tests if and when this gets fixed in the parser.
Issue Analytics
- State:
- Created 7 years ago
- Comments:12 (12 by maintainers)
Top Results From Across the Web
4662 - Parenthesized patterns in destructuring assignment - v8
Issue 4662 : Parenthesized patterns in destructuring assignment ... I would expect that parentheses around patterns (at least in assignments, if ...
Read more >SyntaxError: Invalid destructuring assignment target or ...
It is a Syntax Error if LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral and IsValidSimpleAssignmentTarget( ...
Read more >Destructuring assignment - JavaScript - MDN Web Docs
The destructuring assignment syntax is a JavaScript expression that makes it possible to unpack values from arrays, or properties from ...
Read more >declaration or statement expected. this '=' follows a block of ...
Declaration or statement expected. This '=' follows a block of statements, so if you intended to write a destructuring assignment, you might need...
Read more >Destructuring assignment - OnlyKiosk Dev Tech - Medium
Destructuring assignment also works with objects. But you need to wrap the assignment expression using a set of parenthesis.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Issue filed with Acorn: https://github.com/ternjs/acorn/issues/429
Closing because this was fixed in
acorn@4.0.5
.