Part of the JavaScript auto-install algorithm is the so-called "limited production". These are syntactic forms that prohibit the appearance of a newline at a specific point. To specify the ECMAScript 2015 specification:
If the phrase “[No LineTerminator here]” appears on the right side of the syntax grammar production, this indicates that the production is a limited production: it cannot be used if the LineTerminator stream is present at the input in the specified position.
In the ECMAScript 2015 specification, there are 10 limited productions:
- PostfixExpression [Yield] : LeftHandSideExpression [? Yield] [no LineTerminator here]
++ - PostfixExpression [Yield] : LeftHandSideExpression [? Yield] [no LineTerminator here]
-- - ContinueStatement [Yield] :
continue [no LineTerminator here] LabelIdentifier [? Yield] ; - BreakStatement [Yield] :
break [no LineTerminator here] LabelIdentifier [? Yield] ; - ReturnStatement [Yield] :
return [no LineTerminator here] Expression ; - ReturnStatement [Yield] :
return [no LineTerminator here] Expression [In ,? Yield] ; - ThrowStatement [Yield] :
throw [no LineTerminator here] Expression [In ,? Yield] ; - ArrowFunction [In, Yield] : ArrowParameters [? Yield] [no LineTerminator here]
=> ConciseBody [? In] sub> - YieldExpression [In] :
yield [no LineTerminator here] * Assignment allocation [? In, Yield] - YieldExpression [In] :
yield [no LineTerminator here] AssignmentExpression [? In, Yield]
From these productions, I understand that most of them are limited. Production for PostfixExpression is limited to preventing disambiguation using PrefixExpression. ContinueStatement, BreakStatement and ReturnStatement are limited to production because there are corresponding derivatives where break and continue do not accept labels, and return does not accept expressions. I can’t say that I know enough about the functions of the arrows or I am developing expressions to know why they are limited, but I assume that this prevents some kind of similar intelligibility.
The production I don’t understand is ThrowExpression. As far as I can tell, there is no parsing parsing in using throw , as it is when using break , return and continue : after all, throw; JavaScript is not valid. I thought it might be for historical reasons, but as far as I can tell, throw; never allowed in any JavaScript specification.
The practical consequence of this is that, as with return , you cannot put an expression to be selected on the next line, for example. it is not right:
throw new Error("some error");
However, unlike return , this has no other behavior than placing new Error() on the same line. This is just a syntax error: Chrome reports this as
Uncaught SyntaxError: illegal new line after throw
Is production for ThrowExpression limited only to ensure consistency with similar structures? Or is there some kind of ambiguity that I don't see?