-
Notifications
You must be signed in to change notification settings - Fork 48
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
NUglifyJsMinifierFactory with RenamePairs does not consitently rename properties and methods of JS classes #175
Comments
Hello, Marcel! I tried to minify your code by using the original library (NUglify): using NUglify;
using NUglify.JavaScript;
namespace TestNUglify
{
class Program
{
static void Main(string[] args)
{
const string input = @"class MyClass
{
constructor(field)
{
this.field = field;
}
method()
{
this.field++;
}
get property()
{
return this.field;
}
}
var myVar = new MyClass();
myVar.method();
var property = myVar.property;";
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
};
UglifyResult minifiedResult = Uglify.Js(input, settings);
if (!minifiedResult.HasErrors)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Minification success!");
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine(minifiedResult.Code);
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Minification failed!");
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.White;
foreach (UglifyError error in minifiedResult.Errors)
{
Console.WriteLine(error);
}
}
}
}
} And got a similar result: var e,
d;
class a
{
constructor(b)
{
this.b = b
}
method()
{
this.b++
}
get property()
{
return this.b
}
}
e = new a;
e.c();
d = e.d If you refuse the var myVar,
property;
class MyClass
{
constructor(n)
{
this.field = n
}
method()
{
this.field++
}
get property()
{
return this.field
}
}
myVar = new MyClass;
myVar.method();
property = myVar.property If you are not satisfied with this result, then I recommend that you report about this problem to author of the original library. |
By the way, you can also get a working code by using the |
The effect that you are trying to get by using the (function () {
class MyClass
{
constructor(field)
{
this.field = field;
}
method()
{
this.field++;
}
get property()
{
return this.field;
}
}
var myVar = new MyClass();
myVar.method();
var property = myVar.property;
})(); And after minification you will get the following result: (function()
{
var n,
i;
class t
{
constructor(n)
{
this.field = n
}
method()
{
this.field++
}
get property()
{
return this.field
}
}
n = new t;
n.method();
i = n.property
})() |
Hi @Taritsyn, Thank you for your reply. Both solutions that you gave prevent uglyfying the properties and methods of a class, which is what I want. I have submitted an issue in the original repo (trullock/NUglify#406) |
Thank you for this reply. I will have a look at this. |
Hi @Taritsyn, I took a closer look at the result of the minification you posted after putting the code inside an IIFE, but still the method and property are not minified, which is what I want to achieve anyway. So let's see what the developer's of NUglify say. |
Consider JavaScript like this:
Then I configure the WebMarkupMin minification as follows (irrelevant options left out for brevity):
Now, the resulting uglified JavaScript will become (indentation kept for readability):
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.
Preferrably, the methods and properties of the class are also renamed (just like the fields), but at least the renaming should be consistent to not break the uglified JavaScript
The text was updated successfully, but these errors were encountered: