madskristensen / BundlerMinifier

Visual Studio extension
Other
615 stars 172 forks source link

renameLocals breaks js, func parameter same name as nested function name #603

Open omuleanu opened 9 months ago

omuleanu commented 9 months ago

In bundleconfig.js if I set

    "minify": {
      "enabled": true,
      "renameLocals": true
    },

My js will break. I tried to isolate/reproduce it, this is the closest I got, input js:

var aaa = function () {
    function startLoadPage(p, act, instant) {
        if (!p) return;        

        function f() {
            var loadOpt = {
                page: p // here instead of "p" value, I'll get undefined because 
                //"mergeGroupView" func will have the same name as "p" parameter
            };

            if (act) {

                function mergeGroupView(gv1, gv2, key) { 
                    return gv1 + gv2 + key;
                }

                loadOpt.setRows = function (rcon) {
                    return rcon + mergeGroupView(rcon, rcon, rcon);
                }
            }

            remLoaders();
            o.api.load(loadOpt);
        }

        f();
    }

    return {
        start: startLoadPage
    };
}();

Output result js:

var aaa = function() {
    function n(n, t) {
        function i() {
            var i = {
                page: n
            };
            if (t) {
                function r(n, t, i) { // in non isolated version this func has the name "n", same as first parameter of outer func
                    return n + t + i
                }
                i.setRows = function(n) {
                    return n + r(n, n, n)
                }
            }
            remLoaders();
            o.api.load(i)
        }
        n && i()
    }
    return {
        start: n
    }
}();

(I've also explained in the code comments) in my non isolated code the name of the 1st function startLoadPage parameter becomes the same as the name of the function nested inside the if { } block, and because of this loadOpt.page becomes undefined.