babel / babel/minify

Replace well-defined variable with undefined in for statement

Open
#877 7 comments 6 reactions 0 assignees View on GitHub
needs info
Dominant language
JavaScript
Stars
4.4k
Forks
217
PR merge metrics
No merged PRs in 30d

Description

# Context
I use [Vue.js](https://vuejs.org/), and when I replace `process.env.NODE_ENV` with `'production'`, and minify my bundle with `babel-preset-minify` the resulting code is broken in this function [`actuallySetSelected`](https://github.com/vuejs/vue/blob/f7ca21eab1e0d661945aa6070fc988028c90966f/src/platforms/web/runtime/directives/model.js#L85), and more precisely the [`i < l`](https://github.com/vuejs/vue/blob/f7ca21eab1e0d661945aa6070fc988028c90966f/src/platforms/web/runtime/directives/model.js#L99) expression in the `for` statement is replaced with `i < undefined`.

# Steps to reproduce
I use:
- `@babel/core v7.0.0-beta.51`;
- `babel-preset-minify v0.4.3`.

With this config for `babel-preset-minify`:
```javascript
{
evaluate: true,
simplify: true,
mergeVars: true,

removeUndefined: false,
deadcode: false,
booleans: false,
builtIns: false,
consecutiveAdds: false,
flipComparisons: false,
guards: false,
infinity: false,
mangle: false,
memberExpressions: false,
numericLiterals: false,
propertyLiterals: false,
regexpConstructors: false,
replace: false,
simplifyComparisons: false,
typeConstructors: false,
undefinedToVoid: false
}
```

I've simplified the test case:
## Input
```javascript
function test () {
if (false) return
var i
for (var l=1; i < l; i++) {}
}
```
## Expected output
```javascript
function test(){if(true)for(var i,l=1;i

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.