Allow captured let/const in loops

Previously an error, now supported in TypeScript 1.8.let/const declarations within loops and captured in functions are now emitted to correctly match let/const freshness semantics.

Example
  1. let list = [];
  2. for (let i = 0; i < 5; i++) {
  3. list.push(() => i);
  4. }
  5. list.forEach(f => console.log(f()));

is compiled to:

  1. var list = [];
  2. var _loop_1 = function(i) {
  3. list.push(function () { return i; });
  4. };
  5. for (var i = 0; i < 5; i++) {
  6. _loop_1(i);
  7. }
  8. list.forEach(function (f) { return console.log(f()); });

And results in

  1. 0
  2. 1
  3. 2
  4. 3
  5. 4