failwyn / BundlerMinifier

Visual Studio extension
Other
41 stars 10 forks source link

Duplicate variable name used in minified code #38

Open plqplq opened 1 week ago

plqplq commented 1 week ago

Installed product versions

Description

Variable t is used by the minifier as the incoming parameter, but its also used to declare a const in the same function.

Steps to recreate

This is part of a large project so might not reproduce successfully.

Source javascript:

    this.getselectedtext = function (index) {
        if (selectmode === "multiple") {
            const allselected = $tree.find(".z");
            const thisone = allselected[index];
            return thisone.text();
        }
        else {
            const thisselected = $tree.find(".stn");
            return thisselected.text();
        }
    };

Compiled javascript with line feeds put in

this.getselectedtext=function(t)
{
if(u==="multiple")
{
const i=n.find(".z"),r=i[t];
return r.text()}
const t=n.find(".stn");
return t.text()
};

In the above, you can see we have function(t) and later we have const t, causing a compilation error.

After reinstalling, and giving the variable a slightly different name, this made it compile with an "else" statement, but the problem still exists

this.getselectedtext=function(t){if(u==="multiple"){const i=n.find(".z"),r=i[t];return r.text()}else{const t=n.find(".stn");return t.text()}};

Current behavior

It is declaring a const t using the same variable name t as in function(t)

Expected behavior

Choose a different name for internal variables to function names

I have been using this tool for production builds on the same code for several months and not seen any problems, so now surprised that it is doing this. I did not update the extension but it seems to be the latest.

plqplq commented 5 days ago

I was able to work around the problem by removing the extension and installing the nuget package.

I didn't revert to check if the fix was consistent, but it seems to be working now.