trullock / NUglify

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

JS arrow functions wrong minification #337

Open xNaii opened 2 years ago

xNaii commented 2 years ago

Latest Nuglify

Code used ->

let ga1 = (t) => ({1: 'a', 2: 'b', 3: 'c', 4: 'd', 5: 'e'})[n]?? "";

let ga2 = (t) => {
    return ({
        1: 'a',
        2: 'b',
        3: 'c',
        4: 'd',
        5: 'e'
    })[t] ?? '';
};

GA1 Output: let ga1=()=>{1:"a",2:"b",3:"c",4:"d",5:"e"}[n]??""

GA2 Output let ga2=n=>{1:"a",2:"b",3:"c",4:"d",5:"e"}[n]??""

ga1 is missing function parameter and parentheses a ga2 is missing only parentheses

To Reproduce https://dotnetfiddle.net/ufddID

Excepted output code let variableName=n=>({1:"a",2:"b",3:"c",4:"d",5:"e"})[n]??""

trullock commented 1 year ago

t isnt used in GA1, so the output isnt incorrect. Arguably it would be better compression to leave it in as t is shorter than (), but thats a separate issue

Are the parenthesis required?

xNaii commented 1 year ago

Yes, the parentheses are required to return correct information otherwise browser treats inside as return value not as in line expression