IsValidSimpleAssignmentTarget with parenthesized LHS expressions

# Isiah Meadows (7 years ago)

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.

  • The rules are applied recursively.

After we apply the previous two rules again, finally do IsValidSimpleAssignmentTarget of the identifier foo.

foo is neither arguments nor eval, 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:

  1. The recursion does not allow for the obvious extension of ({x}) = 1 as an expression.
  2. This is either a spec bug that it's allowed, a spec bug it's not allowed, or a bug in multiple self-hosted ESTree parsers.

Isiah Meadows me at isiahmeadows.com

# Kevin Gibbons (7 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 .