aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorJoao Carlos <mail@joao-carlos.com>2015-06-09 15:14:41 +0300
committerJoao Carlos <mail@joao-carlos.com>2015-06-09 15:14:41 +0300
commit0b82e1cd5b29e348700472cc711020e477d5e81a (patch)
treea9079c9ada9bc7af0fdf38bd1f4188ddb4edcffd /bin
parent9aef34a8168f5de3bc00330a740c22de70314a70 (diff)
downloadtracifyjs-0b82e1cd5b29e348700472cc711020e477d5e81a.tar.gz
tracifyjs-0b82e1cd5b29e348700472cc711020e477d5e81a.zip
Change --mangle-regex to accept a full regex
Diffstat (limited to 'bin')
-rwxr-xr-xbin/uglifyjs14
1 files changed, 11 insertions, 3 deletions
diff --git a/bin/uglifyjs b/bin/uglifyjs
index 9a1323fd..4768f766 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);