scope bug in loop body: "i is already declared"
$ buble -v
Bublé version 0.15.2
$ cat l5.js
function parser(input) {
this.pos = 0;
this.input = input;
}
parser.prototype.readInt = function(t, e) {
let i = this.pos, s = 0;
for (let i = 0, n = e == null ? Infinity : e; i < n; ++i) {
let e = this.input.charCodeAt(this.pos), i;
if (e >= 97) {
i = e - 97 + 10;
} else if (e >= 65) {
i = e - 65 + 10;
} else if (e >= 48 && e <= 57) {
i = e - 48;
} else {
i = Infinity;
}
if (i >= t) {
break;
}
++this.pos;
s = s * t + i;
}
if (this.pos === i || e != null && this.pos - i !== e) {
return null;
}
return s;
};
let result = new parser("ABC").readInt(16, 3);
console.log(result);
The unmodified ES6 code works fine with node 6:
$ node l5.js
2748
But buble
has an incorrect variable reuse check:
$ buble l5.js
---
4 : }
5 : parser.prototype.readInt = function(t, e) {
6 : let i = this.pos, s = 0;
7 : for (let i = 0, n = e == null ? Infinity : e; i < n; ++i) {
8 : let e = this.input.charCodeAt(this.pos), i;
^
i is already declared (8:49)
This is the line where the buble error is thrown:
https://gitlab.com/Rich-Harris/buble/blob/v0.15.2/src/program/Scope.js#L31