Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.mixmin.net!news2.arglkargh.de!noris.net!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="UTF-8" Message-ID: <9690906.pQKyqEuMBg@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Thu, 30 Aug 2012 12:37:51 +0200 User-Agent: KNode/4.4.11 Content-Transfer-Encoding: 8Bit X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&. <4191624.W6QT1uhmCP@PointedEars.de> Followup-To: comp.lang.javascript MIME-Version: 1.0 Lines: 119 NNTP-Posting-Date: 30 Aug 2012 12:37:52 CEST NNTP-Posting-Host: cc8eefe8.newsspool3.arcor-online.net X-Trace: DXC=Q4ZZXMW1jj;^8FBo0_81f>McF=Q^Z^V384Fo<]lROoR18kF 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: "", 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