Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minify Js error #687

Closed
han-jingyu opened this issue Apr 21, 2024 · 3 comments
Closed

Minify Js error #687

han-jingyu opened this issue Apr 21, 2024 · 3 comments

Comments

@han-jingyu
Copy link

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.

@tdewolff
Copy link
Owner

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?

@han-jingyu
Copy link
Author

han-jingyu commented Apr 22, 2024

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

@tdewolff
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants