Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #15615
| Message-ID | <9690906.pQKyqEuMBg@PointedEars.de> (permalink) |
|---|---|
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Organization | PointedEars Software (PES) |
| Date | 2012-08-30 12:37 +0200 |
| Subject | Re: Semicolons and the do..while statement |
| Newsgroups | comp.lang.javascript |
| References | <88f8c6ba-bc50-4695-b442-10f1dc377363@o8g2000yqm.googlegroups.com> <k1lopg$qsm$1@news.albasani.net> <4191624.W6QT1uhmCP@PointedEars.de> <c9183673-3b9b-4c95-adbc-7b8d63da571a@k9g2000pbr.googlegroups.com> |
| Followup-To | comp.lang.javascript |
Followups directed to: comp.lang.javascript
RobG wrote:
> Thomas 'PointedEars' Lahn wrote:
>
> [breakdown of ASI]
That appears to be correct.
>> IOW,
>>
>> do {} while (false) var x = 3;
>>
>> *is* equivalent to
>>
>> do {} while (false); var x = 3;
>>
>> because `var' delimits a /VariableStatement/ and the parser is allowed,
>> in order to produce
>>
>> /Program/
>> → /SourceElements_opt/
>> → /SourceElements/ /SourceElement/
>> → /SourceElement/ /SourceElement/
>> → /Statement/ /Statement/
>> → /IterationStatement/ /VariableStatement/
>> → do /Statement/ while ( /Expression/ ); /VariableStatement/
>> → do /Block/ while ( /Expression/ ); /VariableStatement/
>> → …
>> → do {} while ( true ); var x = 3;
>>
>> to insert the semicolon before the /VariableStatement/.
To be precise, after the closing parenthesis of a supposed do-while
statement. Function serialization, although implementation-dependent, can
show this:
$ js
Rhino 1.7 release 2 2010 02 06
js> (function () { do {} while (true) var x = 3; }).toString()
function () {
do {
} while (true);
var x = 3;
}
>> It's not a bug,>it's a feature, and a standards-compliant feature at
>> that.
>
> I suppose I'm still missing something because my understanding of this
> explanation is that a semicolon should be inserted for
>
> /VariableStatement/ /VariableStatement/
>
> as it's one of the "certain statements", but it isn't. If the newline
> is removed from the variable statement example above:
>
> var x = 3 var y = 4
>
> then a syntax error is thrown.
ACK:
js> (function () { var x = 3 var y = 4; }).toString()
js: "<stdin>", line 3: missing ; before statement
js: (function () { var x = 3 var y = 4; }).toString()
js: ............................^
> I can't see how the second "var" can be interpreted as anything other than
> the start of a variable statement, and therefore that a semicolon can (or
> should) be inserted before it (per your logic above).
Good "question". I do not have a good answer to it yet. However:
> The only explanation I can think of is that the "v" at the start of
> the second "var" is interpreted as the start of an identifier, so
> either a semicolon, comma[1] or newline (which would force semicolon
> insertion) is required. Because of the ambiguity, an error results, so
> the whole "var" token is not read and the second variable statement
> isn't identified.
I think we can exclude that possibility. `var' is a /ReservedWord/, in
particular a /Keyword/, so explicitly _not_ an /Identifier/:
| 7.6.1 Reserved Words
|
| A reserved word is an IdentifierName that cannot be used as an Identifier.
|
| Syntax
|
| ReservedWord ::
| Keyword
| FutureReservedWord
| NullLiteral
| BooleanLiteral
|
| 7.6.1.1 Keywords
|
| The following tokens are ECMAScript keywords and may not be used as
| Identifiers in ECMAScript programs.
|
| Syntax
|
| Keyword :: one of
| break do instanceof typeof
| case else new var
| catch finally return void
| continue for switch while
| debugger function this with
| default if throw delete
| in try
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: Semicolons and the do..while statement BGB <cr88192@hotmail.com> - 2012-08-29 13:55 -0500
Re: Semicolons and the do..while statement Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-08-29 22:20 +0200
Re: Semicolons and the do..while statement BGB <cr88192@hotmail.com> - 2012-08-29 20:02 -0500
Re: Semicolons and the do..while statement RobG <rgqld@iinet.net.au> - 2012-08-29 18:27 -0700
Re: Semicolons and the do..while statement Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-08-30 12:37 +0200
Re: Semicolons and the do..while statement John G Harris <john@nospam.demon.co.uk> - 2012-08-30 14:24 +0100
Re: Semicolons and the do..while statement Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-08-30 15:59 +0200
Re: Semicolons and the do..while statement John G Harris <john@nospam.demon.co.uk> - 2012-08-30 16:26 +0100
Re: Semicolons and the do..while statement Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-08-30 17:47 +0200
Re: Semicolons and the do..while statement John G Harris <john@nospam.demon.co.uk> - 2012-09-01 11:40 +0100
Re: Semicolons and the do..while statement Dr J R Stockton <reply1235@merlyn.demon.co.uk.invalid> - 2012-09-02 19:54 +0100
Re: Semicolons and the do..while statement BGB <cr88192@hotmail.com> - 2012-08-30 11:17 -0500
Re: Semicolons and the do..while statement Gene Wirchenko <genew@ocis.net> - 2012-08-30 10:25 -0700
Re: Semicolons and the do..while statement Dr J R Stockton <reply1235@merlyn.demon.co.uk.invalid> - 2012-08-31 23:20 +0100
Re: Semicolons and the do..while statement Gene Wirchenko <genew@ocis.net> - 2012-08-31 16:03 -0700
Re: Semicolons and the do..while statement Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-08-29 22:30 +0200
csiph-web