Emit 'for...of' statements in ES3/ES5 by JsonFreeman · Pull Request #2207 · microsoft/TypeScript (original) (raw)
Not sure if the playground uses the most recent version but there is an inconsistency regarding the emitted ES3/ES5 code:
var x = [3, 3, 3]; for (var i of x) { x = [2, 2]; console.log(i); }
compiles to
var x = [3, 3, 3]; for (var _i = 0; _i < x.length; _i++) { var i = x[_i]; x = [2, 2]; console.log(i); }
printing
instead of (ES6 semantics)
On the other hand, merely adding parentheses:
var x = [3, 3, 3]; for (var i of (x)) { x = [2, 2]; console.log(i); }
correctly compiles to
var x = [3, 3, 3]; for (var _a = 0, _b = (x); _a < _b.length; _a++) { var i = _b[_a]; x = [2, 2]; console.log(i); }
giving the expected output.