Josee9988 / MinifyAll

A 𝗩𝗦𝗖𝗼𝗱𝗲 𝗺𝗢𝗻𝗢𝗳𝗢𝗲𝗿 for JS, JSON/C, CSS, and HTML, you will love its simplicity! 🌟 π˜Ύπ™€π™’π™₯π™§π™šπ™¨π™¨ and π™œπ™―π™žπ™₯ files and folders πŸ“¦ Reduce your bundle and file sizes with lightning speed ⚑
https://minifyall.jgracia.es/
GNU General Public License v3.0
73 stars 13 forks source link

Minifying javascript file removes parts of simple if typeof condition and console output #117

Closed rencarl closed 3 years ago

rencarl commented 3 years ago

First of all, thank you very much for your great work!

This is my code:

...
FRONTEND.prototype = {
    con: function(obj){
        if(typeof console.log != "undefined")console.log(obj);
    },
    ....
}
...
frontend = new FRONTEND();
frontend.con('output to console');

In previous versions the code was minified to:

FRONTEND.prototype={con:function(n){void 0!==console.log&&console.log(n)},...

In version 2.7.0 the code is minified to:

FRONTEND.prototype={con:function(e){console.log},...

Can you fix this? If not, how do i have to change my code?

Best regards!

welcome[bot] commented 3 years ago

Thanks for opening your first issue in Josee9988/project-template! Be sure to follow the issue template and provide every bit of information to help the developers!

Josee9988 commented 3 years ago

I'll check it today or tomorrow

Thanks for contributing

Josee9988 commented 3 years ago

Hi @rencarl we updated all the packages in version 2.6.1 Screenshot from 2021-07-17 15-48-41

The minimization of JavaScript is done with a 3rd party package called Terser, you may want to post an issue thereafter I update all the packages again, which might solve this issue and other possible ones.

So as I said, I will update this third party package and hope that it does fix your issue because it seems like it is not MinifyAll's fault.

I will close this issue and notify you probably tomorrow when I update the extension with the new packages such as terser updated, then you can check if this issue persists, if so, you should notify the Terser team instead also in Github.

Thanks and stay tuned

Josee9988 commented 3 years ago

Hi @rencarl MinifyAll version 2.7.1 is now available. Please check it out and tell me if that problem persists, because I tried to minify your code and I didn't see any problem with it

Thanks!!!

rencarl commented 3 years ago

Sorry, the problem still persists.

I have simplified my code to:

function TEST(){ 
    // a comment
}

TEST.prototype = {
    con: function(obj){
        if(typeof console.log != "undefined")console.log(obj);
    }
}

window.onload = function(){
    var test = new TEST();
    test.con("test for console log");
    alert('test for alert');
}

And this is the minified version:

function TEST(){}TEST.prototype={con:function(o){console.log}},window.onload=function(){(new TEST).con("test for console log"),alert("test for alert")};

With the minified version i only get the "test for alert", "test for console.log" is missing. And the reason is the missing parameter when calling console.log. The if condition in the con function is also absent.

Best regards!

Josee9988 commented 3 years ago

Then you should maybe contact the terser team so they can better solve your problem.

Remember you have a MinifyAll setting called 'terserMinifyOptions' in which you can add and modify all the terser's settings or configurations in case this error is caused by a wrong setting.

Thanks again!

rencarl commented 3 years ago

Remember you have a MinifyAll setting called 'terserMinifyOptions' in which you can add and modify all the terser's settings

This was the hint i needed. I don't know why, but "drop_console" was set to "true". I changed it to "false" and everything works fine again.

Thank you for your help!

Josee9988 commented 3 years ago

Always happy to help @rencarl !!