[Pkg-javascript-commits] [uglifyjs] 03/11: Change --mangle-regex to accept a full regex
Jonas Smedegaard
dr at jones.dk
Wed Aug 26 09:34:58 UTC 2015
This is an automated email from the git hooks/post-receive script.
js pushed a commit to tag v2.4.24
in repository uglifyjs.
commit 0b82e1cd5b29e348700472cc711020e477d5e81a
Author: Joao Carlos <mail at joao-carlos.com>
Date: Tue Jun 9 15:14:41 2015 +0300
Change --mangle-regex to accept a full regex
---
README.md | 2 +-
bin/uglifyjs | 14 +++++++++++---
2 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/README.md b/README.md
index 073a871..3b99441 100644
--- a/README.md
+++ b/README.md
@@ -253,7 +253,7 @@ cover most standard JS and DOM properties defined in various browsers. Pass
`--reserve-domprops` to read that in.
You can also use a regular expression to define which property names should be
-mangled. For example, `--mangle-regex="^_"` will only mangle property names
+mangled. For example, `--mangle-regex="/^_/"` will only mangle property names
that start with an underscore.
When you compress multiple files using this option, in order for them to
diff --git a/bin/uglifyjs b/bin/uglifyjs
index 9a1323f..4768f76 100755
--- a/bin/uglifyjs
+++ b/bin/uglifyjs
@@ -192,6 +192,15 @@ function writeNameCache(key, cache) {
return UglifyJS.writeNameCache(ARGS.name_cache, key, cache);
}
+function extractRegex(str) {
+ if (/^\/.*\/[a-zA-Z]*$/.test(str)) {
+ var regex_pos = str.lastIndexOf("/");
+ return new RegExp(str.substr(1, regex_pos - 1), str.substr(regex_pos + 1));
+ } else {
+ throw new Error("Invalid regular expression: " + str);
+ }
+}
+
if (ARGS.quotes === true) {
ARGS.quotes = 3;
}
@@ -218,9 +227,8 @@ if (BEAUTIFY)
if (ARGS.comments != null) {
if (/^\/.*\/[a-zA-Z]*$/.test(ARGS.comments)) {
- var regex_pos = ARGS.comments.lastIndexOf("/");
try {
- OUTPUT_OPTIONS.comments = new RegExp(ARGS.comments.substr(1, regex_pos - 1), ARGS.comments.substr(regex_pos + 1));
+ OUTPUT_OPTIONS.comments = extractRegex(ARGS.comments);
} catch (e) {
print_error("ERROR: Invalid --comments: " + e.message);
}
@@ -379,7 +387,7 @@ async.eachLimit(files, 1, function (file, cb) {
var regex;
try {
- regex = ARGS.mangle_regex ? new RegExp(ARGS.mangle_regex) : null;
+ regex = ARGS.mangle_regex ? extractRegex(ARGS.mangle_regex) : null;
} catch (e) {
print_error("ERROR: Invalid --mangle-regex: " + e.message);
process.exit(1);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/uglifyjs.git
More information about the Pkg-javascript-commits
mailing list