ASI is not performed if the inserted semicolon would be parsed as:
- one of the two semicolons in the header of a ForStatement
- an empty statement
I can sort of see why we need (1) - in a ForStatement header, the semicolon is more of a separator than a statement terminator, so we shouldn't interpret any intervening line breaks between the header expressions as statement-terminating line breaks.
But I'm not sure why (2) is needed. Say, we had a for-loop without a body:
for(let i = 0; i < 9; i++) // SyntaxError - expected expression, got end of script
I was expecting ASI to kick in here but it doesn't because of exception (2).
Why can't the above be interpreted as a
Statement is an unterminated
EmptyStatement? Under this interpretation, ASI should kick in and terminate it:
for(let i = 0; i < 9; i++); // ^ ASI terminating the empty statement