compress RegExp() in unsafe (#2735)
This commit is contained in:
@@ -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, {
|
||||
|
||||
@@ -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]',
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user