From: Russell Potter on

I think I've been able to get my head
around ASI in JS, except for the
Restricted �throw" statement produ-
ction.

As I understand it, if a line termin-
ator appears immediately after the
having a "throw" keyword, the effect
is that of having an "implied"
(perhaps a better term than an "auto-
matically inserted"?) semi-colon
between it and the thrown expression,
which effectively creates a "throw"
keyword without a thrown expression ...
but, trouble is, there is no such prod-
uction in the JS grammar ...

Similarly, in the post-increment and
-decrement expression productions
in which these expressions are foll-
owed by a line-terminator followed
by a "++" or "--" token, this creates,
AFAIK, an expression followed by a
separate, stand-alone token of one
of these, which is also a syntax error.

Should these syntax errors be thrown,
"as-is" or otherwise somehow "corre-
cted"? to.. So, what should happen here?

Russell

From: John G Harris on
On Sun, 24 Jan 2010 at 08:15:40, in comp.lang.javascript, Russell Potter
wrote:
>
>I think I've been able to get my head
>around ASI in JS, except for the
>Restricted “throw" statement produ-
>ction.
>
>As I understand it, if a line termin-
>ator appears immediately after the
>having a "throw" keyword, the effect
>is that of having an "implied"
>(perhaps a better term than an "auto-
>matically inserted"?) semi-colon
>between it and the thrown expression,
<snip>

I don't think so. The standard says :

"When, as the program is parsed from left to right, a token (called the
offending token) is encountered that is not allowed by any production of
the grammar, then a semicolon is automatically inserted before the
offending token if one or more of the following conditions is true:

1. The offending token is separated from the previous token by at least
one LineTerminator.
2. " ...

throw followed by newline is a syntax error, but there is no newline
between them.

John
--
John Harris
From: Russell Potter on


> ... The standard says :
>
> "When, as the program is parsed from left to right, a token (called the
> offending token) is encountered that is not allowed by any production of
> the grammar, then a semicolon is automatically inserted before the
> offending token if one or more of the following conditions is true:
>
> 1. The offending token is separated from the previous token by at least
> one LineTerminator.
> 2. " ...

.... But the throw statement I'm talking about us a "restricted"
production, in which the opposite holds: the semi0colon is inserted even
when there is no syntax error

> throw followed by newline is a syntax error, but there is no newline
> between them.

But I'm talking about the case in which there is one. I
know a line-terminator at that point is against "best
practice", but I bkeeive it is stilll egalpossible to have one
there ...
From: John G Harris on
On Sun, 24 Jan 2010 at 22:35:35, in comp.lang.javascript, Russell Potter
wrote:
>
>
>> ... The standard says :
>>
>> "When, as the program is parsed from left to right, a token (called the
>> offending token) is encountered that is not allowed by any production of
>> the grammar, then a semicolon is automatically inserted before the
>> offending token if one or more of the following conditions is true:
>>
>> 1. The offending token is separated from the previous token by at least
>> one LineTerminator.
>> 2. " ...
>
>... But the throw statement I'm talking about us a "restricted"
>production, in which the opposite holds: the semi0colon is inserted
>even when there is no syntax error
>
>> throw followed by newline is a syntax error, but there is no newline
>> between them.
>
>But I'm talking about the case in which there is one. I
>know a line-terminator at that point is against "best
>practice", but I bkeeive it is stilll egalpossible to have one
>there ...

It really is a syntax error, not just best practice. The syntax
specification says :

ThrowStatement :
throw [no LineTerminator here] Expression ;

so 'throw' followed by a line terminator is not allowed, nor is 'throw'
followed by a semicolon.

You're right that restricted productions have a further rule that I'd
overlooked. It causes a lonely 'return' to be followed by a semicolon,
always, which is legal, and a lonely 'throw' to be turned into a syntax
error. What the browser, etc, does with the syntax error after reporting
it is outside the language spec, but it's preferable for it to refuse to
run the program.

John
--
John Harris
From: Thomas 'PointedEars' Lahn on
John G Harris wrote:

> [...] What the browser, etc, does with the syntax error after reporting
> it is outside the language spec, but it's preferable for it to refuse to
> run the program.

Incorrect. It is vice-versa: The browser (in general: the runtime
environment) runs a script engine, which must not (continue to) run the
source code as a /Program/ if it encounters a syntax error. However, how it
reports the syntax error, and how the runtime environment visualizes it, is
beyond the scope of the Specification. Cf. ES3F/ES5, sections 14 and 16.


PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann