ASI: Clarification of practical advice for assignment statements beginning with left paren `(`

The last example in §12.9.2 - 'Examples of Automatic Semicolon Insertion' shows how something like:

a = b + c
(d + e).print()

...can be misparsed as:

a = b + c(d + e).print()

It then provides the following advice:

In the circumstance that an assignment statement must begin with a left parenthesis, it is a good idea for the programmer to provide an explicit semicolon at the end of the preceding statement rather than to rely on automatic semicolon insertion.

This makes sense but how is (d + e).print() an "assignment statement"? Isn't it a CallExpression?

1 Like

Looks like a typo. Should be expression statement.

1 Like

Yea I was wondering if it meant expression statement or even assignment expression since that would cover the d + e bit in the parens. Thank you for clearing that up @lightmare.

AssignmentExpression would also cover the whole of (d + e).print(). That is, it's a CallExpression as you point out, but it's about 18 other things as well. (There are a lot of unit productions in ECMAScript's expression grammar.)

@jmdyck yes, that was just me trying to tie the "assignment statement must begin with a left parenthesis" part of the advice back to that example as I didn't know it was a typo. I wondered if maybe it was referring to the d + e portion because it begins with a (, but it still didn't make sense to call it an assignment statement, so I thought it best to ask here.

Replacing "assignment statement" with "expression statement" clears it up and fits in with what I thought the example was trying to convey.

If it helps, 1. it's non-normative (so precision isn't required) and 2. "assignment statement" is being used as a shorthand for "expression statement whose expression is an assignment expression". So while not fully technically accurate (there's no AssignmentStatement syntactic production), I wouldn't consider it ambiguous, either.

That's a stretch. What would be the point of excluding expression statement whose expression is not an assignment expression, for which the advice applies just as well?

Now that I'm taking a closer look, yeah, it's an editorial bug. It should say "expression statement", not "assignment statement".

Thanks @claudiameadows, I've opened an issue.