optimise binary operands with evaluate() (#1427)

- remove call to evaluate() in is_constant() and let nested optimize() does its job instead
- reject RegExp in is_constant() and remove special case logic under collapse_vars
- operands to conditionals optimisation are now always evaluate()-ed
- throw error in constant_value() instead of returning undefined to catch possible bugs, similar to make_node_from_constant()
- optimise binary boolean operators under `evaluate` instead of `conditionals`
This commit is contained in:
Alex Lam S.L
2017-01-26 19:16:50 +08:00
committed by Richard van Velzen
parent 0d7d4918eb
commit 0610c020b1
4 changed files with 290 additions and 220 deletions

View File

@@ -136,30 +136,30 @@ modified: {
}
function f2() {
var a = 1, b = 2, c = 3;
var b = 2, c = 3;
b = c;
console.log(a + b);
console.log(b + c);
console.log(1 + b);
console.log(b + 3);
console.log(4);
console.log(a + b + c);
console.log(1 + b + 3);
}
function f3() {
var a = 1, b = 2, c = 3;
var b = 2, c = 3;
b *= c;
console.log(a + b);
console.log(b + c);
console.log(1 + b);
console.log(b + 3);
console.log(4);
console.log(a + b + c);
console.log(1 + b + 3);
}
function f4() {
var a = 1, b = 2, c = 3;
var b = 2, c = 3;
b = c;
console.log(a + b);
console.log(1 + b);
console.log(b + c);
console.log(a + c);
console.log(a + b + c);
console.log(1 + c);
console.log(1 + b + c);
}
function f5(a) {