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
let list = [];
for (let i = 0; i < 5; i++) {
list.push(() => i);
}
list.forEach(f => console.log(f()));
is compiled to:
var list = [];
var _loop_1 = function(i) {
list.push(function () { return i; });
};
for (var i = 0; i < 5; i++) {
_loop_1(i);
}
list.forEach(function (f) { return console.log(f()); });
And results in
0
1
2
3
4