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

Function name collides with variable name #405

Open
seth-drf opened this issue Aug 22, 2024 · 2 comments
Open

Function name collides with variable name #405

seth-drf opened this issue Aug 22, 2024 · 2 comments

Comments

@seth-drf
Copy link

I'm using version 1.21.9.

Describe the bug
NUglify is giving a function inside a block the same name as a variable in a closure.

To Reproduce
How I'm running it:

var result = Uglify.Js(js);
var output = result.Code;
Console.WriteLine(output);

JavaScript inside js variable:

(function(){
    var v1 = true;
    function someFunction() {
        if (true) {
            myFunction();
            function myFunction() {
            }
        }
        function otherFunction() {
            console.log({v1});
        }
        otherFunction();
    }
    someFunction();
})();

Minified output
Before formatting:

(function(){function t(){function t(){console.log({v1:n})}if(1){n();function n(){}}t()}var n=!0;t()})()

After formatting:

(function() {
    function t() {
        function t() {
            console.log({
                v1: n
            })
        }
        if (1) {
            n();
            function n() {}
        }
        t()
    }
    var n = !0;
    t()
}
)()

Excepted output code
The v1 variable and the myFunction function should have different names.

Running the original JavaScript puts an object with v1 set to true into the console. Running the minified JavaScript puts an object with v1 set to the function.

@aravindvemulaa
Copy link

aravindvemulaa commented Aug 22, 2024

(function(){
var v1 = true;
function someFunction() {
if (true) {
useMyFunction(); // Renamed to avoid collision
function useMyFunction() { // Renamed to avoid collision
}
}
function displayFunction() { // Renamed to avoid collision
console.log({v1});
}
displayFunction();
}
someFunction();
})();

Changes ensure that function names are unique and do not conflict with other variable or function names, which could lead to issues in minification or during execution.

@trullock
Copy link
Owner

(function(){ var v1 = true; function someFunction() { if (true) { useMyFunction(); // Renamed to avoid collision function useMyFunction() { // Renamed to avoid collision } } function displayFunction() { // Renamed to avoid collision console.log({v1}); } displayFunction(); } someFunction(); })(); Changes ensure that function names are unique and do not conflict with other variable or function names, which could lead to issues in minification or during execution.

Pretty sure this wont help at all

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants