trullock / NUglify

NUglify is a HTML, JavaScript and CSS minification Library for .NET (fork of AjaxMin + new features)
Other
396 stars 78 forks source link

Object desctructuring compression is naive #247

Open trullock opened 3 years ago

trullock commented 3 years ago

this:

let y = ({ a, b, ...rest }) => a + b + rest.length;

becomes:

let y=({a:n,b:t,...i})=>n+t+i.length

It didn't need to rename a and b, this made it worse

SteveChristyMidway commented 2 years ago

I think this example is basically the same thing, but I just wanted to note it because it caused me a slight headache figuring out why my code wasn't working. Default parameters combined with the object destructuring can lead to issues/bugs.

function test1({ locale = "en-US" } = {}) {
    console.log(locale);
}

test1({ locale: "ja-JP" });

I would expect "ja-JP" to be logged, but "en-US" is logged because test1 is turned into test1({n="en-US"}={}){console.log(n)} And then of course something like test1({n:55}) could confusingly cause 55 to be logged.

trullock commented 2 years ago

This issue is just a compression enchancement, your example is a bug, can you open a new issue for it please