NUglify icon indicating copy to clipboard operation
NUglify copied to clipboard

Object desctructuring compression is naive

Open trullock opened this issue 4 years ago • 2 comments

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

trullock avatar Apr 28 '21 19:04 trullock

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.

SteveChristyMidway avatar Sep 09 '22 19:09 SteveChristyMidway

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

trullock avatar Sep 16 '22 21:09 trullock