Replace well-defined variable with undefined in for statement
See original GitHub issueContext
I use Vue.js, 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
, and more precisely the i < l
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
:
{
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
function test () {
if (false) return
var i
for (var l=1; i < l; i++) {}
}
Expected output
function test(){if(true)for(var i,l=1;i<l;i++);}
Actual output
function test(){if(true)for(var i,l=1;i<undefined;i++);}
It seems I’ve managed to reduce it to an interaction between those three plugins:
- babel-plugin-minify-simplify
- babel-plugin-transform-merge-sibling-variables
- babel-plugin-minify-constant-folding
You can pull this repo to test it for yourself.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:6
- Comments:7 (1 by maintainers)
Top Results From Across the Web
Is modifying a variable in its declaration statement well-defined?
I'd be concerned that the standard may permit i=0 to run, then i to be initialized to an unspecified state, then i initialized...
Read more >1.6 — Uninitialized variables and undefined behavior
Undefined behavior (often abbreviated UB) is the result of executing code whose behavior is not well defined by the C++ language.
Read more >undefined - JavaScript - MDN Web Docs - Mozilla
A variable that has not been assigned a value is of type undefined . A method or statement also returns undefined if the...
Read more >Managing Variables - UiPath Documentation Portal
If you remove or upgrade a package that may lead to a variable or argument being undefined, an Unknown Type is added in...
Read more >Undefined behavior in C and C++ programs - Project Nayuki
These strategies failed in a spectacular way: Just by moving a print statement up or down one line, I could change the program's...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@trevor-bliss and I just ran into the same issue.
I noticed version 0.5.0 just got out, I updated the test case here: https://github.com/tex0l/bug-report-babel
@boopathi : the bug still exists in the latest version.