From af42bbe9760324463f4335c26d507528f1d11c35 Mon Sep 17 00:00:00 2001 From: Shrey Banga Date: Mon, 13 Jun 2016 15:17:28 -0700 Subject: [PATCH] Set sane defaults when mangle_props=2 --- README.md | 12 +++++++----- bin/uglifyjs | 24 +++++++++++++++++------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 796d37b9..56f980a2 100644 --- a/README.md +++ b/README.md @@ -136,11 +136,13 @@ The available options are: --mangle-props Mangle property names (default `0`). Set to `true` or `1` to mangle all property names. Set to `2` to only mangle unquoted property names. - Use the `keep_quoted_props` beautifier option to - preserve the quotes around property names and set - the `properties` compressor option to `false` to - prevent rewriting quoted properties with dot - notation. + This also enables the `keep_quoted_props` + beautifier option to preserve the quotes around + property names and disables the `properties` + compressor option to prevent rewriting quoted + properties with dot notation. You can override + these by setting them explicitly on the command + line. --mangle-regex Only mangle property names matching the regex --name-cache File to hold mangled names mappings --pure-funcs List of functions that can be safely removed if diff --git a/bin/uglifyjs b/bin/uglifyjs index ec791b07..844c139c 100755 --- a/bin/uglifyjs +++ b/bin/uglifyjs @@ -212,12 +212,26 @@ if (ARGS.quotes === true) { ARGS.quotes = 3; } +if (ARGS.mangle_props === true) { + ARGS.mangle_props = 1; +} + +if (ARGS.mangle_props === "unquoted") { + ARGS.mangle_props = 2; +} + var OUTPUT_OPTIONS = { - beautify : BEAUTIFY ? true : false, - preamble : ARGS.preamble || null, - quote_style : ARGS.quotes != null ? ARGS.quotes : 0 + beautify : BEAUTIFY ? true : false, + preamble : ARGS.preamble || null, + quote_style : ARGS.quotes != null ? ARGS.quotes : 0, }; +if (ARGS.mangle_props == 2) { + OUTPUT_OPTIONS.keep_quoted_props = true; + if (COMPRESS && !("properties" in COMPRESS)) + COMPRESS.properties = false; +} + if (ARGS.screw_ie8) { if (COMPRESS) COMPRESS.screw_ie8 = true; if (MANGLE) MANGLE.screw_ie8 = true; @@ -387,10 +401,6 @@ async.eachLimit(files, 1, function (file, cb) { TOPLEVEL = TOPLEVEL.wrap_enclose(arg_parameter_list); } - if (ARGS.mangle_props === true) { - ARGS.mangle_props = 1; - } - if (ARGS.mangle_props || ARGS.name_cache) (function(){ var reserved = RESERVED ? RESERVED.props : null; var cache = readNameCache("props");