tdewolff / minify

Go minifiers for web formats

Home Page:https://go.tacodewolff.nl/minify

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Minify Js error

han-jingyu opened this issue · comments

The source:

var div = document.createElement("div");
var c = "";
for (let i = 0; i < 5; i++) {
    c += '.....';
}
div.innerHTML = c;

Sometime, it will be compress to:

var div = document.createElement("div");
for (let c="", i = 0; i < 5; i++) {
    c += '.....';
}
div.innerHTML = c;

The c cannot be used outside for.

Hi Han, thank you for reporting this issue. I'm a bit confused by what you mean with "sometime", do you mean that the minification result changes every time you minify it, sometimes it is correct and sometimes not? Or do you mean that similar JS code in another part do work but this one doesn't? If it is non-deterministic, that would be really strange...

For me it outputs:

var div=document.createElement("div"),c="";for(let e=0;e<5;e++)c+=".....";div.innerHTML=c

As confirmed by https://go.tacodewolff.nl/minify?q=b21pbWU9dGV4dCUyRmphdmFzY3JpcHQmanMtcHJlY2lzaW9uPTAmanMtdmVyc2lvbj0wJnNyYz12YXIrZGl2KyUzRCtkb2N1bWVudC5jcmVhdGVFbGVtZW50KCUyMmRpdiUyMiklM0IlMEQlMEF2YXIrYyslM0QrJTIyJTIyJTNCJTBEJTBBZm9yKyhsZXQraSslM0QrMCUzQitpKyUzQys1JTNCK2klMkIlMkIpKyU3QiUwRCUwQSsrKytjKyUyQiUzRCsnLi4uLi4nJTNCJTBEJTBBJTdEJTBEJTBBZGl2LmlubmVySFRNTCslM0QrYyUzQg==

What version do you use of minify?

the similar JS code in another part do work but this one doesn't. I use v2.20.19.

Please try the code:

var div = document.createElement("div");
var c = "";
for (let i = 0; i < 5; i++) {
    c += '.....';
}
div.innerHTML = c;
var d = "";
for (let i = 0; i < 5; i++) {
    d += '.....';
}
div.innerHTML = d;
2024-04-22 12 18 12

Thanks again! This should now be fixed in the latest version, can you please verify?