bublejs / buble

https://buble.surge.sh
MIT License
871 stars 67 forks source link

Wrong variable name transpilation when let with overlapping variable name is used inside switch case #193

Open reischapa opened 5 years ago

reischapa commented 5 years ago

Hi there,

I've noticed that the following code, after transpilation, fails to accurately reproduce behaviour (let's call it test.js):

for (var r = 0; r < 1; r++) {
  let e = 1;
  let o = 2;
  switch (o) {
    case 2:
      let e = 4
      console.log(e)
      break;
  }
  console.log(e)
}

File after ./bin/buble test.js (master branch on buble, commit 1918c651a4c8e2220437ea3f5fe20d1baaa1865f)

for (var r = 0; r < 1; r++) {
  var e = 1;
  var o = 2;
  switch (o) {
    case 2:
      var e$1 = 4
      console.log(e$1)
      break;
  }
  console.log(e$1)
}

Output of node test.js (node 8):

4
1

Output of ./bin/buble test.js | node - (node 8)

4
4

I noticed that the later reference to e, that should refer to that declared outside the switch statement is incorrectly replaced to a reference to that present inside the switch statement.

If you need more information on the issue, please ask away. Thanks.

mourner commented 5 years ago

Probably related to #142. Might have the same root cause.