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

JS minify produces broken code #445

Closed
jmooring opened this issue Nov 6, 2021 · 4 comments
Closed

JS minify produces broken code #445

jmooring opened this issue Nov 6, 2021 · 4 comments

Comments

@jmooring
Copy link
Contributor

jmooring commented Nov 6, 2021

Input

var a = 1;
function f() {
  return 1;
}
var { min, max } = Math;
function g() {
  return 2;
}

Output

var a=1,min,max;function f(){return 1}{min,max}=Math;function g(){return 2}

Reference (https://jscompress.com)

var a=1;function f(){return 1}var{min:min,max:max}=Math;function g(){return 2}

This is not a new issue. I tested 2.9.10 - 2.9.22. Only 2.9.21 was different (very different).

@tdewolff
Copy link
Owner

tdewolff commented Nov 9, 2021

This bug has been confirmed, working on a fix!

@tdewolff
Copy link
Owner

Still working on the fix, it is quite complex as it requires some restructuring of the code. I use the opportunity to push through related improvements for minification.

@tdewolff
Copy link
Owner

tdewolff commented Dec 7, 2021

The shortest output should be

a=1;function f(){return 1}var{min,max}=Math,a;function g(){return 2}

@tdewolff
Copy link
Owner

tdewolff commented Dec 7, 2021

I've pushed out a fix for your issue, and besides fixing a bug most benchmark targets get smaller still (improved minification). Unfortunately this comes at a 2% cost in time. Only complex (array or object) variable declarations don't get merged yet. Hopefully that gets fixed as soon as it is supported.

In the meanwhile, if you can please test the patch to see if your JS still runs as expected.

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