Microsoft/TypeScript — pull request #904 by mhegazy (2014-10-16 17:51:09+00:00)
Title: Let and const support

This change adds support for ES6-style block-scoped variable declarations. these are only available when targeting ES6. the change also adds a new target for ES6.

There are two variants, let and const. Generaly let and const behave like a var declarations with the following exceptions:

* Both let and const can not be re-declared:
```TypeScript
let a = 0;
a = 1;
let a; // Error: redeclaration
```
* It is an error to re-declare a block-scoped variable as 'var' in the same scope:
```TypeScript
let a = 0;
{
var a; // Error: redeclaration, as var is hoisted to the top of the scope, and re-declares a
}
```

* Let and const can not be declared in a non-guarded statements
```TypeScript
if (true) {
let a = 0; // OK
}

if (false)
let b = 0; // Error

for (let i = 0; i< 10; i++) // OK
console.log(i);
```

* Let and const declarations are block scoped, and not hoisted to the top of the function like other JS declarations:
```TypeScript
let a = 0;
{
let a = "local";
console.log(a) // local
}
console.log(a); // 0
```

* Let and const can not be used before they are defined, to avoid the lexical dead zone of vars.
```TypeScript
v = 2; // ok
var v;

a = 2;
let a; // Error, used before initialization
```

* Const declarations must have an initializer, unless in ambient context

* It is an error to write to a Const
```TypeScript
const c = 0;
console.log(c); // OK: 0

c = 2; // Error
c++; // Error

{
const c2 = 0;
var c2 = 0; // not a redeclaration, as the var is hoisted out, but still a write to c2
}
```

* Let and const can not be exported, only vars are allowed to.

What is left:
* Block emit if any of the let/const errors are reported, these may be syntactic, binding, or semantic errors
* Wire in Test262 for parser verification to ensure we are ES6 complaint