enhance unsafe evaluate (#2037)
This commit is contained in:
@@ -1665,6 +1665,26 @@ merge(Compressor.prototype, {
|
|||||||
}
|
}
|
||||||
throw def;
|
throw def;
|
||||||
});
|
});
|
||||||
|
def(AST_Call, function(compressor){
|
||||||
|
var exp = this.expression;
|
||||||
|
if (compressor.option("unsafe") && exp instanceof AST_PropAccess) {
|
||||||
|
var key = exp.property;
|
||||||
|
if (key instanceof AST_Node) {
|
||||||
|
key = ev(key, compressor);
|
||||||
|
}
|
||||||
|
var val = ev(exp.expression, compressor);
|
||||||
|
var fn = val[key];
|
||||||
|
if (typeof fn == "function") {
|
||||||
|
return fn.apply(val, this.args.map(function(arg) {
|
||||||
|
return ev(arg, compressor);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw def;
|
||||||
|
});
|
||||||
|
def(AST_New, function(compressor){
|
||||||
|
throw def;
|
||||||
|
});
|
||||||
})(function(node, func){
|
})(function(node, func){
|
||||||
node.DEFMETHOD("_eval", func);
|
node.DEFMETHOD("_eval", func);
|
||||||
});
|
});
|
||||||
@@ -3144,6 +3164,11 @@ merge(Compressor.prototype, {
|
|||||||
&& is_iife_call(self)) {
|
&& is_iife_call(self)) {
|
||||||
return self.negate(compressor, true);
|
return self.negate(compressor, true);
|
||||||
}
|
}
|
||||||
|
var ev = self.evaluate(compressor);
|
||||||
|
if (ev !== self) {
|
||||||
|
ev = make_node_from_constant(ev, self).optimize(compressor);
|
||||||
|
return best_of(compressor, ev, self);
|
||||||
|
}
|
||||||
return self;
|
return self;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1037,3 +1037,31 @@ issue_1964_2: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "b"
|
expect_stdout: "b"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
array_slice_index: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log([1,2,3].slice(1)[1]);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(3);
|
||||||
|
}
|
||||||
|
expect_stdout: "3"
|
||||||
|
}
|
||||||
|
|
||||||
|
string_charCodeAt: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log("foo".charCodeAt("bar".length));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(NaN);
|
||||||
|
}
|
||||||
|
expect_stdout: "NaN"
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user