aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2018-01-06 21:04:47 +0800
committerGitHub <noreply@github.com>2018-01-06 21:04:47 +0800
commit3564b4f20dfd2ec06dd162ce5c22b1b3f2e03c7f (patch)
treeb23de8cb9335c54831f00c5bb12d3ac14f174aa0 /lib
parent3505a3604a682138512a7e03964fb68c861b5cbd (diff)
downloadtracifyjs-3564b4f20dfd2ec06dd162ce5c22b1b3f2e03c7f.tar.gz
tracifyjs-3564b4f20dfd2ec06dd162ce5c22b1b3f2e03c7f.zip
compress `RegExp()` in `unsafe` (#2735)
Diffstat (limited to 'lib')
-rw-r--r--lib/compress.js21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 0f15eb7e..28d6a1c4 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, {