Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
omuleanu opened this issue Jan 4, 2024 · 0 comments
Open
Labels

Comments

@omuleanu
Copy link

omuleanu commented Jan 4, 2024

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.

@omuleanu omuleanu added the bug label Jan 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant