Variable clobbers function with babel-plugin-minify-mangle-names and babel-preset-env 🐛 [bug]
- Dominant language
- JavaScript
- Stars
- 4.4k
- Forks
- 217
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
Inner loop variable `a` in `doit` clobbers the `theFunction` function.
**To Reproduce**
```js
'use strict'; (() => {
function theFunction() {}
function doit() {
for (let b = 0; b < 4; ++b) {
for (let a = 0; a < 42; ++a) {
}
}
for (let vark = 0; vark < 1; ++vark) {
console.log('theFunction = ' + theFunction);
theFunction();
}
}
doit();
for (let a = 1; a <= 5; ++a) {
}
})();
```
**Actual Output**
```js
"use strict";(function(){function b(){}(function(){for(var c=0;4>c;++c)for(var b=0;42>b;++b);
for(var a=0;1>a;++a)console.log("theFunction = "+b),b()})();for(var c=1;5>=c;++c);})();
//theFunction = 42
//TypeError: b is not a function
```
**Expected Output**
```js
"use strict";(function(){function b(){}(function(){for(var c=0;4>c;++c)for(var d=0;42>d;++d);
for(var a=0;1>a;++a)console.log("theFunction = "+b),b()})();for(var c=1;5>=c;++c);})();
//theFunction = function b(){}
```
**Configuration**
`babel-plugin-minify-mangle-names` version 367cc048be5b16a78444dd17ab10f360a2479e48.
`babel-preset-env` version a955efa3e3d52f3f9f51978969a390abafc2b444.
**Additional context**
If renaming either `a` variable, or renaming the `b` variable, it doesn't trigger. Still triggers if removing the `console.log` line.
Contributor guide
Assessment
This issue has not been assessed yet.