evaluate incorrectly evaluates variables to undefined
- Dominant language
- JavaScript
- Stars
- 4.4k
- Forks
- 217
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
When minifying angularjs I ran into an issue where valid variables were defined to `undefined`, and then `void 0`
**To Reproduce**
```js
function ngOptionsPostLink(scope, selectElement, attr, ctrls)
{
// if ngModel is not defined, we don't need to do anything
var ngModelCtrl = ctrls[1];
if (!ngModelCtrl) return;
var selectCtrl = ctrls[0];
var multiple = attr.multiple;
// The emptyOption allows the application developer to provide their own custom "empty"
// option when the viewValue does not match any of the option values.
var emptyOption;
for (var i = 0, children = selectElement.children(), ii = children.length; i < ii; i++)
{
if (children[i].value === '')
{
emptyOption = children.eq(i);
break;
}
}
return emptyOption;
}
```
**Actual Output**
```js
function ngOptionsPostLink(scope, selectElement, attr, ctrls)
{
var ngModelCtrl = ctrls[1];
if (ngModelCtrl)
for (var selectCtrl = ctrls[0], multiple = attr.multiple, i = 0, children = selectElement.children(), ii = (void 0).length; void 0 > i; i++)
if ('' === (void 0)[i].value)
{
(void 0).eq(i);
break
}
return emptyOption
}
```
**Expected Output**
```js
function ngOptionsPostLink(scope, selectElement, attr, ctrls)
{
var ngModelCtrl = ctrls[1];
if (ngModelCtrl)
{
for (var emptyOption, selectCtrl = ctrls[0], multiple = attr.multiple, i = 0, children = selectElement.children(), ii = children.length; i < ii; i++)
if ('' === children[i].value)
{
emptyOption = children.eq(i);
break
}
return emptyOption
}
}
```
**Configuration**
7.0.0 (@babel/core 7.0.0)
Babel cli and via grunt.
```json5
{
"presets": [
["minify", {
"builtIns": false,
"mangle": false,
"removeConsole": true,
"removeDebugger": true,
"evaluate": true
}]
]
}
```
Contributor guide
Assessment
This issue has not been assessed yet.