Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sloppy-mode let more incompatible than spec lets on (due to automatic semi-colon insertion) #259

Closed
saurik opened this issue Dec 16, 2015 · 2 comments
Labels
normative change Affects behavior required to correctly evaluate some ECMAScript source text

Comments

@saurik
Copy link

saurik commented Dec 16, 2015

In ES3/5, the code x=true;eval("var let;let\nx=false");x evaluates to false, while in ES6 the same code evaluates to true, as in earlier versions of ECMAScript automatic-semicolon insertion intervenes and breaks what is now a LexicalDeclaration into two separate ExpressionStatements. This seems like something that should be documented in Annex E.

FWIW, I can see that 13.5 under Annex E tries to talk about the case of a StatementListItem which begins with "let [", but the incompatibility is actually more pervasive (though likely harmless). Also, I will point out that I can actually see someone formatting their (ECMAScript 6) code in an ambiguous way: putting variables on their own lines after the let, such as "let\n\tx=0,\n\ty=1".

Legacy ECMAScript:

V8 version 2.2.23
> x=true;eval("var let;let\nx=false");x
false
Rhino 1.7 release 3 2012 05 18
js> x=true;eval("var let;let\nx=false");x
false
JavaScriptCore (Mac OS X 10.9)
>>> x=true;eval("var let;let\nx=false");x
false

ECMAScript 2015:

SpiderMonkey 5bcd1d1b 2015/12/05
js> x=true;eval("var let;let\nx=false");x
true
@saurik saurik changed the title loose-mode let more incompatible than spec lets on (due to automatic semi-colon insertion) sloppy-mode let more incompatible than spec lets on (due to automatic semi-colon insertion) Dec 16, 2015
@wycats
Copy link
Contributor

wycats commented Dec 16, 2015

@saurik what do you think is the solution?

@bterlson
Copy link
Member

This is a great catch. Right thing to do is document in Annex E:

13.2: In ECMAScript 2015, a |StatementList| beginning with the token let followed by the input elements |LineTerminator| |Identifier| is the start of a |LexicalDeclaration|. In previous editions, automatic semicolon insertion would always insert a semicolon before the |Identifier| input element.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
normative change Affects behavior required to correctly evaluate some ECMAScript source text
Projects
None yet
Development

No branches or pull requests

3 participants