IsValidSimpleAssignmentTarget with parenthesized LHS expressions
# Kevin Gibbons (8 years ago)
Your reading of the spec is correct; ({x}) = 1
is disallowed. And indeed
every major engine disallows it.
Esprima just has a bug. See e.g. jquery/esprima#1164.
Shift gets this; so do acorn and babylon astexplorer.net/#/gist/e8ff5de6b9c8c56e00b6b654cc84a0f9/7ef6401d8b4ce934da425095c8662637edf6707e .
Is my understanding correct in interpreting that
((foo)) = 1
is a valid expression in both strict and sloppy mode, but({x}) = 1
is not?Here's my logic:
This tells me that when the LHS is neither an array nor object literal pattern, an early error occurs if and only if IsValidSimpleAssignmentTarget of the left hand side is false.
In the second rule, it gets the covered expression and returns IsValidSimpleAssignmentTarget of its subexpression.
The covered expression is the expression in parentheses.
After we apply the previous two rules again, finally do IsValidSimpleAssignmentTarget of the identifier
foo
.foo
is neitherarguments
noreval
, so IsValidSimpleAssignmentTarget is true.So because the rules are applied recursively, and it recurses into
foo
and{x}
respectively, it validates the former and invalidates the latter. Is my reasoning correct in this study? Or did I miss something important.In addition, if this is the case, there are two issues I see right off:
({x}) = 1
as an expression.Isiah Meadows me at isiahmeadows.com