Add debug option to mangle_properties()#1274
Conversation
Causes name mangling to perform "name" -> "_$name$_".
|
For the tests, it might be fine to add a compress test for this something like: mangle_to_debug_properties: {
mangle_props = {
debug: true
};
input: {
// input
}
expect: { // or `expect_exact:`, but the output is a string, not code between brackets
// output
}
} |
|
This debug prop feature would be useful. However, the implementation does not interact with the property mangle cache correctly. It would be possible to create prop name collisions. Please copy the tests Should also document the new option the README. Edit: Another new test demonstrating that a debug prop name collision can not take place should be added as well. |
| if (!should_mangle(name)) { | ||
| return name; | ||
| } | ||
|
|
There was a problem hiding this comment.
remove trailing whitespace seen in red in git diff
|
Is this new debug option for mangle props available from |
|
The cli interface needs to be updated as well to make that working no? |
|
Longer term |
|
I agree, uglifyJS must eats it's own dog food. The |
Property mangling provides great compression and also helps make reverse engineering more difficult. However it easily breaks code and when it does it's often semi-impossible to figure out what happened. For example even after beautification, you just see "undefined is not a function" on a line like
a.b().To mitigate this, this PR adds a new 'debug' option that can be passed to the mangle_properties options. When specified, mangling predictably transforms
nameto_$name$_. This means in the former example you now get an error on a line that looks likea._$toastWaffles$_(). Now you know you need to do something to protect the nametoastWaffles, e.g. use quoted syntax, add it to your reserved properties list, etc. Basically since the mangled name is changed but contains the original name, you can see what's broken by mangling and easily debug it.Closure Compiler has a similar debug mode.