From e03c194bebdf31dc1f663f248d9f1c876642a033 Mon Sep 17 00:00:00 2001 From: alexlamsl Date: Fri, 14 Apr 2017 18:13:39 +0800 Subject: [PATCH] improve ease of use for `--mangle except` --- README.md | 5 ++--- bin/uglifyjs | 10 +++++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 7a3e961c..4ff8434d 100644 --- a/README.md +++ b/README.md @@ -142,7 +142,6 @@ The available options are: ``` TODOs: ``` - -r, --reserved Reserved names to exclude from mangling. --lint Display some scope warnings --reserved-file File containing reserved names --reserve-domprops Make (most?) DOM properties reserved for @@ -206,10 +205,10 @@ To enable the mangler you need to pass `--mangle` (`-m`). The following (disabled by default). When mangling is enabled but you want to prevent certain names from being -mangled, you can declare those names with `--reserved` (`-r`) — pass a +mangled, you can declare those names with `--mangle except` — pass a comma-separated list of names. For example: - uglifyjs ... -m -r '$,require,exports' + uglifyjs ... -m except=[$,require,exports] to prevent the `require`, `exports` and `$` names from being changed. diff --git a/bin/uglifyjs b/bin/uglifyjs index a3925bd4..6039352b 100755 --- a/bin/uglifyjs +++ b/bin/uglifyjs @@ -246,10 +246,10 @@ function parseJS(flag, constants) { var value = node.right; if (!constants) { options[name] = value; - } else if (value instanceof UglifyJS.AST_Constant) { - options[name] = value.getValue(); + } else if (value instanceof UglifyJS.AST_Array) { + options[name] = value.elements.map(to_string); } else { - options[name] = value.print_to_string(); + options[name] = to_string(value); } return true; } @@ -259,6 +259,10 @@ function parseJS(flag, constants) { return true; } if (!(node instanceof UglifyJS.AST_Sequence)) throw node; + + function to_string(value) { + return value instanceof UglifyJS.AST_Constant ? value.getValue() : value.print_to_string(); + } })); } catch(ex) { fatal("Error parsing arguments for '" + flag + "': " + value);