Skip to content

Add debug option to mangle_properties()#1274

Closed
AshleyScirra wants to merge 1 commit into
mishoo:masterfrom
AshleyScirra:debug-property-mangling
Closed

Add debug option to mangle_properties()#1274
AshleyScirra wants to merge 1 commit into
mishoo:masterfrom
AshleyScirra:debug-property-mangling

Conversation

@AshleyScirra

@AshleyScirra AshleyScirra commented Aug 31, 2016

Copy link
Copy Markdown
Contributor

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 name to _$name$_. This means in the former example you now get an error on a line that looks like a._$toastWaffles$_(). Now you know you need to do something to protect the name toastWaffles, 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.

Causes name mangling to perform "name" -> "_$name$_".
@avdg

avdg commented Aug 31, 2016

Copy link
Copy Markdown
Contributor

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
    }
}

@kzc

kzc commented Aug 31, 2016

Copy link
Copy Markdown
Contributor

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 mangle_unquoted_properties and mangle_properties and add a _debug suffix to the test names and debug: true in mangle_props.

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.

Comment thread lib/propmangle.js
if (!should_mangle(name)) {
return name;
}

@kzc kzc Aug 31, 2016

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove trailing whitespace seen in red in git diff

@kzc

kzc commented Aug 31, 2016

Copy link
Copy Markdown
Contributor

Is this new debug option for mangle props available from bin/uglifyjs?

@avdg

avdg commented Sep 2, 2016

Copy link
Copy Markdown
Contributor

The cli interface needs to be updated as well to make that working no?

@kzc

kzc commented Sep 2, 2016

Copy link
Copy Markdown
Contributor

bin/uglifyjs has no equivalent of mangleProperties options for minify() so a new CLI flag would have to be created.

Longer term bin/uglifyjs really ought to solely use the minify() API so that uglify eats its own dog food and is consistent. It would probably lead to a more robust minify() API as well.

@avdg

avdg commented Sep 2, 2016

Copy link
Copy Markdown
Contributor

I agree, uglifyJS must eats it's own dog food. The cat can has it's own food by then and shouldn't be that verbose in uglifyJS anymore by then. Should resolve issues like #1234 as easy as one can count.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants