Wrong variable name transpilation when let with overlapping variable name is used inside switch case
- Dominant language
- JavaScript
- Stars
- 874
- Forks
- 62
- PR merge metrics
- No merged PRs in 30d
Description
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.
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the issue with the supplied test.js example by running ./bin/buble test.js and comparing the result with direct Node execution. Trace the transpiler's handling of the switch-case binding and the later outer reference; done means the transpiled program preserves the original 4 then 1 output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100