@@ -2313,7 +2313,9 @@ merge(Compressor.prototype, {
|
|||||||
AST_Node.DEFMETHOD("evaluate", function(compressor){
|
AST_Node.DEFMETHOD("evaluate", function(compressor){
|
||||||
if (!compressor.option("evaluate")) return this;
|
if (!compressor.option("evaluate")) return this;
|
||||||
var val = this._eval(compressor, 1);
|
var val = this._eval(compressor, 1);
|
||||||
return !val || val instanceof RegExp || typeof val != "object" ? val : this;
|
if (!val || val instanceof RegExp) return val;
|
||||||
|
if (typeof val == "function" || typeof val == "object") return this;
|
||||||
|
return val;
|
||||||
});
|
});
|
||||||
var unaryPrefix = makePredicate("! ~ - + void");
|
var unaryPrefix = makePredicate("! ~ - + void");
|
||||||
AST_Node.DEFMETHOD("is_constant", function(){
|
AST_Node.DEFMETHOD("is_constant", function(){
|
||||||
@@ -2335,15 +2337,22 @@ merge(Compressor.prototype, {
|
|||||||
def(AST_Constant, function(){
|
def(AST_Constant, function(){
|
||||||
return this.getValue();
|
return this.getValue();
|
||||||
});
|
});
|
||||||
|
def(AST_Function, function(compressor) {
|
||||||
|
if (compressor.option("unsafe")) {
|
||||||
|
var node = this;
|
||||||
|
var fn = function() {};
|
||||||
|
fn.toString = function() {
|
||||||
|
return node.print_to_string();
|
||||||
|
};
|
||||||
|
return fn;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
});
|
||||||
def(AST_Array, function(compressor, depth) {
|
def(AST_Array, function(compressor, depth) {
|
||||||
if (compressor.option("unsafe")) {
|
if (compressor.option("unsafe")) {
|
||||||
var elements = [];
|
var elements = [];
|
||||||
for (var i = 0, len = this.elements.length; i < len; i++) {
|
for (var i = 0, len = this.elements.length; i < len; i++) {
|
||||||
var element = this.elements[i];
|
var element = this.elements[i];
|
||||||
if (element instanceof AST_Function) {
|
|
||||||
elements.push(element);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
var value = element._eval(compressor, depth);
|
var value = element._eval(compressor, depth);
|
||||||
if (element === value) return this;
|
if (element === value) return this;
|
||||||
elements.push(value);
|
elements.push(value);
|
||||||
|
|||||||
@@ -1489,3 +1489,16 @@ issue_2916_2: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_2919: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log([ function() {} ].toString());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log("function(){}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -5527,3 +5527,21 @@ issue_2869: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_2919: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unsafe: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var arr = [ function() {} ];
|
||||||
|
console.log(typeof arr[0]);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log("function");
|
||||||
|
}
|
||||||
|
expect_stdout: "function"
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user