trullock / NUglify

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

Identifier has already been declared #365

Open o-serhiichyk opened 1 year ago

o-serhiichyk commented 1 year ago

Are you using the latest verion of NUglify, especially if used through BunderMinifier? Update before raising a bug as your issue is probably already fixed. I'm using the last version.

Describe the bug In specific scenario minifier uses the same variable name twice. It leads to an error like "Identifier 'n' has already been declared".

To Reproduce I have code like this:

define("SomeModule", [], function() {
    return {
        someProperty: [{
            property1: "SomeString",
            property2: async () => {
                if (someVariable) {
                    return;
                } else {
                    let service1 = new SomeService();
                    service1.someMethod();
                    const const1 = await someFunction1();
                    const const2 = await someFunction2();
                    // another code
                }
            }
        }, ],
    };
});

Code settings: ConstStatementsMozilla = true

Minified output or stack trace Minified code:

define("SomeModule",[],function(){return{someProperty:[{property1:"SomeString",property2:async()=>{if(someVariable)return;else{let n=new SomeService;n.someMethod();const n=await someFunction1(),t=await someFunction2()}}},]}})

Formatted version:

define("SomeModule", [], function() {
    return {
        someProperty: [{
            property1: "SomeString",
            property2: async () => {
                if (someVariable) return;
                else {
                    let n = new SomeService;
                    n.someMethod();
                    const n = await someFunction1(),
                        t = await someFunction2()
                }
            }
        }, ]
    }
})

As you can see, name n used for both variable service1 and const1 in the same block.

Excepted output code Another name instead of n for variable const1.