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

Uglyfying with RenamePairs does not consitently rename properties and methods of JS classes #406

Open
MarcelVersteeg opened this issue Oct 2, 2024 · 2 comments

Comments

@MarcelVersteeg
Copy link

Describe the bug
Consider JavaScript like this:

class MyClass
{
    constructor(field)
    {
        this.field = field;
    }

    method()
    {
        field++;
    }

    get property()
    {
        return field;
    }
}

var myVar = new MyClass();
myVar.method();
var property = myVar.property;

Then I configure the Uglifier as follows (irrelevant options left out for brevity):

var settings = new CodeSettings
            {
                OutputMode = OutputMode.MultipleLines,

                // Your settings
                LocalRenaming = LocalRenaming.CrunchAll,
                PreserveFunctionNames = false,
                PreserveImportantComments = false,
                QuoteObjectLiteralProperties = false,
                RemoveFunctionExpressionNames = true,
                RemoveUnneededCode = true,
                RenamePairs = @"MyClass=a,field=b,method=c,property=d,myVar=e",
                ReorderScopeDeclarations = true,
                StrictMode = false,
                StripDebugStatements = true,
                TermSemicolons = false,
                WarningLevel = int.MaxValue
            };

Now, the resulting uglified JavaScript will become (indentation kept for readability):

class a
{
    constructor(b)
    {
        this.b = b;
    }

    method()
    {
        b++;
    }

    get property()
    {
        return b;
    }
}

var e = new a();
e.c();
var d = e.d

This code does not run correctly, as the actual method and property in the class are not renamed, but the locations where they are called are renamed.

To Reproduce
See the code example

Minified output or stack trace
See the description

Excepted output code

class a
{
    constructor(b)
    {
        this.b = b;
    }

    c()
    {
        b++;
    }

    get d()
    {
        return b;
    }
}

var e = new a();
e.c();
var d = e.d
@MarcelVersteeg
Copy link
Author

As a side note: configuration properties that would rename all global variables and methods and properties of a class would also be great

@trullock
Copy link
Owner

trullock commented Oct 2, 2024

Thanks for the clear bug report

PRs welcome, the issue will probably lie in one of the Analyzers

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

2 participants