ECMA-262: ElementList : ... AssignmentExpression? Wtf?
The first example was meant to be [ a, b ]. Sorry.
Expression is .comma expression so can't be used without fatal ambiguity: is [a,,b] [(a,b)] or [(a), (b)]? It's the latter by using AssignmentExpression. If it were PrimaryExpression, ever expression using a binary operator would need to be parenthesized.
Is the "Dragon Book" still in print? Recommended.
Assuming I'm following your question, it seems like the confusion here is
that AssignmentExpression
, name-wise, seems like it is only for
assignment, but in reality most of the other expression grammars are nested
inside it? If you look at
www.ecma-international.org/ecma-262/8.0/#sec-expressions you can
see for instance
[image: Inline image 1]
and the ConditionalExpression
drills down even further, eventually
reaching all of the normal "expression" types that you'd expect in JS.
AssignmentExpression
in the ECMAScript grammar essentially translates to
"any expression except comma expressions.
Why does a ArrayLiteral element use AssignmentExpression, but on any implementation works like a PrimitiveExpression? E.g.:
[ a = b ]
*AssignmentExpression *is something very different. I'm just confused.
[ x = y ]
What is this, my boys?