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

Request: shrinking variables without obfuscating them #3201

Closed
qwertie opened this Issue Jun 27, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@qwertie
Copy link

qwertie commented Jun 27, 2018

As we all know --mangle shortens variable names, but it also obfuscates the code somewhat. For example mangling

function fruit(apple, banana, x, y) {}

produces

function fruit(n,f,o,t){}

instead of the more readable

function fruit(a,b,x,y){}

I would like to be able to minify my code while preserving some of the readability for variables with a unique first letter. As uglifyjs is not advertised as an obfuscator, this would make the most sense as default behavior, except that some users probably rely on --mangle to act as an obfuscator de-facto. I would propose

  1. A --1letter option that shortens names to one letter, such that if N names in a scope start with X, one of them will be X in the output.
  2. A --2letter option that shortens names to one or two letters, such that all names that start with X originally also start with X in the output, and abcd is shortened to something similar like ab (or just a) where possible. I'd suggest using a high digit suffix where possible to handle conflicts, e.g. var a, ap, app => var a, ap, a9. (Why start at 9 instead of 0 or 1? A normal variable name might plausibly be called x1 or x2 but names like a9 are unusual so someone looking at the minified code can more easily identify it as an artifact of uglify.)
@alexlamsl

This comment has been minimized.

Copy link
Collaborator

alexlamsl commented Jun 27, 2018

Try --rename.

@alexlamsl alexlamsl closed this Jun 27, 2018

@qwertie

This comment has been minimized.

Copy link
Author

qwertie commented Jun 27, 2018

There is no --rename option in the command line documentation.

I tried that option and it did not appear to do anything. But, you know, thanks for the dismissiveness.

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