Allen Wirfs-Brock (2013-11-09T00:15:46.000Z)
On Nov 8, 2013, at 3:35 PM, Ian Halliday wrote:

> Hello es-discuss,
>  
> I’m having difficulty figuring out where the ES6 draft spec specifies that a “use before declaration” error should be thrown.  My last understanding of the temporal dead zone was that ECMAScript would always issue a “use before declaration” error at runtime, regardless whether it can be statically determined or not.  However it seems like the evaluation semantics of var declarations, for example, do not lead to any line that throws a ReferenceError.


>  
> That is, consider this code:
>  
> function f() {
>     {
>         var x = 5;
>         let x;
declaring the same name using a let and a var is an early error: http://people.mozilla.org/~jorendorff/es6-draft.html#sec-block-static-semantics-early-errors  
or for the function level http://people.mozilla.org/~jorendorff/es6-draft.html#sec-function-definitions-static-semantics-early-errors 


>     }
> }
> 
> f();
> 
> I think the var declaration creates a binding for x in the function’s lexical environment, but then binds to the x in the block’s environment for the initialization.  As such, the initialization should throw a “use before declaration” error.  But this is what I cannot find in the spec.  Maybe I am wrong about the semantics here?

because an early error exists, the surround script or module is never evaluated.

Allen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20131108/5f01edd6/attachment.html>
domenic at domenicdenicola.com (2013-11-13T16:54:33.961Z)
On Nov 8, 2013, at 3:35 PM, Ian Halliday wrote:

> That is, consider this code:
>  
> ```js
> function f() {
>     {
>         var x = 5;
>         let x;
> ```

declaring the same name using a let and a var is an early error: http://people.mozilla.org/~jorendorff/es6-draft.html#sec-block-static-semantics-early-errors or for the function level http://people.mozilla.org/~jorendorff/es6-draft.html#sec-function-definitions-static-semantics-early-errors 


> I think the var declaration creates a binding for x in the function’s lexical environment, but then binds to the x in the block’s environment for the initialization.  As such, the initialization should throw a “use before declaration” error.  But this is what I cannot find in the spec.  Maybe I am wrong about the semantics here?

because an early error exists, the surround script or module is never evaluated.