[Pkg-javascript-commits] [uglifyjs] 401/491: compress `RegExp()` in `unsafe` (#2735)

Jonas Smedegaard dr at jones.dk
Wed Feb 14 19:51:57 UTC 2018


This is an automated email from the git hooks/post-receive script.

js pushed a commit to annotated tag debian/3.3.10-1
in repository uglifyjs.

commit 3564b4f20dfd2ec06dd162ce5c22b1b3f2e03c7f
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Sat Jan 6 21:04:47 2018 +0800

    compress `RegExp()` in `unsafe` (#2735)
---
 lib/compress.js            | 21 +++++++++++++++++++++
 test/compress/issue-269.js | 24 ++++++++++++++++++++++++
 2 files changed, 45 insertions(+)

diff --git a/lib/compress.js b/lib/compress.js
index 0f15eb7..28d6a1c 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -3869,6 +3869,27 @@ merge(Compressor.prototype, {
                     operator: "!"
                 }).optimize(compressor);
                 break;
+              case "RegExp":
+                var params = [];
+                if (all(self.args, function(arg) {
+                    var value = arg.evaluate(compressor);
+                    params.unshift(value);
+                    return arg !== value;
+                })) {
+                    try {
+                        return best_of(compressor, self, make_node(AST_RegExp, self, {
+                            value: RegExp.apply(RegExp, params),
+                        }));
+                    } catch (ex) {
+                        compressor.warn("Error converting {expr} [{file}:{line},{col}]", {
+                            expr: self.print_to_string(),
+                            file: self.start.file,
+                            line: self.start.line,
+                            col: self.start.col
+                        });
+                    }
+                }
+                break;
             } else if (exp instanceof AST_Dot) switch(exp.property) {
               case "toString":
                 if (self.args.length == 0) return make_node(AST_Binary, self, {
diff --git a/test/compress/issue-269.js b/test/compress/issue-269.js
index 1d41dea..a29e754 100644
--- a/test/compress/issue-269.js
+++ b/test/compress/issue-269.js
@@ -64,3 +64,27 @@ strings_concat: {
 		);
 	}
 }
+
+regexp: {
+	options = {
+		evaluate: true,
+		unsafe: true,
+	}
+	input: {
+		RegExp("foo");
+		RegExp("bar", "ig");
+		RegExp(foo);
+		RegExp("bar", ig);
+		RegExp("should", "fail");
+	}
+	expect: {
+		/foo/;
+		/bar/ig;
+		RegExp(foo);
+		RegExp("bar", ig);
+		RegExp("should", "fail");
+	}
+	expect_warnings: [
+		'WARN: Error converting RegExp("should","fail") [test/compress/issue-269.js:78,2]',
+	]
+}

-- 
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