From 177c9a09ede777460903f597ae80de6e09a0318b Mon Sep 17 00:00:00 2001 From: alexlamsl Date: Fri, 14 Apr 2017 17:03:09 +0800 Subject: [PATCH] add `--mangle-props` --- README.md | 22 +++++++++++++--------- bin/uglifyjs | 17 +++++++++++------ 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 4599c5c1..fd1bfef1 100644 --- a/README.md +++ b/README.md @@ -57,9 +57,9 @@ a double dash to prevent input files being used as option arguments: The available options are: ``` - -h, --help output usage information - -V, --version output the version number - -p --parse Specify parser options: + -h, --help Print usage information. + -V, --version Print version number. + -p, --parse Specify parser options: `acorn` Use Acorn for parsing. `bare_returns` Allow return outside of functions. Useful when minifying CommonJS @@ -70,12 +70,16 @@ The available options are: a program (for parsing JSON). `spidermonkey` Assume input files are SpiderMonkey AST format (as JSON). - -c --compress [options] Enable compressor/specify compressor options: + -c, --compress [options] Enable compressor/specify compressor options: `pure_funcs` List of functions that can be safely removed when their return values are not used. - -m --mangle [options] Mangle names/specify mangler options. - -b --beautify [options] Beautify output/specify output options: + -m, --mangle [options] Mangle names/specify mangler options. + --mangle-props [options] Mangle properties/specify mangler options: + `debug` Add debug prefix and suffix. + `ignore_quoted` Only mangle unquoted properies. + `regex` Only mangle matched property names. + -b, --beautify [options] Beautify output/specify output options: `beautify` Enabled with `--beautify` by default. `preamble` Preamble to prepend to the output. You can use this to insert a comment, for @@ -90,7 +94,7 @@ The available options are: `wrap_iife` Wrap IIFEs in parenthesis. Note: you may want to disable `negate_iife` under compressor options. - -o --output Output file (default STDOUT). Specify "spidermonkey" + -o, --output Output file (default STDOUT). Specify "spidermonkey" to dump SpiderMonkey AST format (as JSON) to STDOUT. --comments [filter] Preserve copyright comments in the output. By default this works like Google Closure, keeping @@ -105,9 +109,9 @@ The available options are: code removal or cascading statements into sequences. --config-file Read `minify()` options from JSON file. - -d --define [=value] Global definitions. + -d, --define [=value] Global definitions. --ie8 Support non-standard Internet Explorer 8. - Equivalent to setting `screw_ie8: false` in `minify()` + Equivalent to setting `ie8: true` in `minify()` for `compress`, `mangle` and `output` options. By default UglifyJS will not try to be IE-proof. --keep-fnames Do not mangle/drop function names. Useful for diff --git a/bin/uglifyjs b/bin/uglifyjs index b154c3eb..b92fa0e3 100755 --- a/bin/uglifyjs +++ b/bin/uglifyjs @@ -18,14 +18,15 @@ program._name = info.name; program.version(info.version); program.parseArgv = program.parse; program.parse = undefined; -program.option("-p --parse ", "Specify parser options.", parseJS("parse", true)); -program.option("-c --compress [options]", "Enable compressor/specify compressor options.", parseJS("compress", true)); -program.option("-m --mangle [options]", "Mangle names/specify mangler options.", parseJS("mangle", true)); -program.option("-b --beautify [options]", "Beautify output/specify output options.", parseJS("beautify", true)); -program.option("-o --output ", "Output file (default STDOUT)."); +program.option("-p, --parse ", "Specify parser options.", parseJS("parse", true)); +program.option("-c, --compress [options]", "Enable compressor/specify compressor options.", parseJS("compress", true)); +program.option("-m, --mangle [options]", "Mangle names/specify mangler options.", parseJS("mangle", true)); +program.option("--mangle-props [options]", "Mangle properties/specify mangler options.", parseJS("mangle-props", true)); +program.option("-b, --beautify [options]", "Beautify output/specify output options.", parseJS("beautify", true)); +program.option("-o, --output ", "Output file (default STDOUT)."); program.option("--comments [filter]", "Preserve copyright comments in the output."); program.option("--config-file ", "Read minify() options from JSON file."); -program.option("-d --define [=value]", "Global definitions.", parseJS("define")); +program.option("-d, --define [=value]", "Global definitions.", parseJS("define")); program.option("--ie8", "Support non-standard Internet Explorer 8."); program.option("--keep-fnames", "Do not mangle/drop function names. Useful for code relying on Function.prototype.name."); program.option("--self", "Build UglifyJS2 as a library (implies --wrap UglifyJS)"); @@ -73,6 +74,10 @@ if (program.define) { if (program.keepFnames) { options.keep_fnames = true; } +if (program.mangleProps) { + if (typeof options.mangle != "object") options.mangle = {}; + options.mangle.properties = program.mangleProps; +} if (program.parse) { if (program.parse.acorn || program.parse.spidermonkey) { if (program.sourceMap) fatal("ERROR: inline source map only works with built-in parser");