reduce overlap of sequences & side_effects (#5344)
This commit is contained in:
@@ -3637,9 +3637,7 @@ Compressor.prototype.compress = function(node) {
|
|||||||
var stat = statements[i];
|
var stat = statements[i];
|
||||||
if (stat instanceof AST_SimpleStatement) {
|
if (stat instanceof AST_SimpleStatement) {
|
||||||
if (seq.length >= compressor.sequences_limit) push_seq();
|
if (seq.length >= compressor.sequences_limit) push_seq();
|
||||||
var body = stat.body;
|
merge_sequence(seq, stat.body);
|
||||||
if (seq.length > 0) body = body.drop_side_effect_free(compressor);
|
|
||||||
if (body) merge_sequence(seq, body);
|
|
||||||
} else if (is_declaration(stat)) {
|
} else if (is_declaration(stat)) {
|
||||||
statements[n++] = stat;
|
statements[n++] = stat;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -3358,6 +3358,7 @@ issue_4806_1: {
|
|||||||
issue_4806_2: {
|
issue_4806_2: {
|
||||||
options = {
|
options = {
|
||||||
sequences: true,
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6135,6 +6135,7 @@ issue_4265: {
|
|||||||
dead_code: true,
|
dead_code: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f() {
|
function f() {
|
||||||
|
|||||||
@@ -2631,13 +2631,14 @@ issue_3999: {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_4001: {
|
issue_4001_1: {
|
||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
ie: true,
|
ie: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
|
side_effects: false,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
@@ -2660,7 +2661,42 @@ issue_4001: {
|
|||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
var a;
|
var a;
|
||||||
console.log((a = 42, void f()[42], void function a() {}));
|
console.log((a = 42, f()[42], void f, void function a() {}));
|
||||||
|
}
|
||||||
|
expect_stdout: "undefined"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_4001_2: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
ie: true,
|
||||||
|
inline: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function(a) {
|
||||||
|
function f() {
|
||||||
|
return a;
|
||||||
|
var b;
|
||||||
|
}
|
||||||
|
var c = f();
|
||||||
|
(function g() {
|
||||||
|
c[42];
|
||||||
|
f;
|
||||||
|
})();
|
||||||
|
(function a() {});
|
||||||
|
}(42));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f() {
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
var a;
|
||||||
|
console.log((a = 42, void f()[42]));
|
||||||
}
|
}
|
||||||
expect_stdout: "undefined"
|
expect_stdout: "undefined"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -317,7 +317,35 @@ iife: {
|
|||||||
typeof function g() {}();
|
typeof function g() {}();
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
x = 42, function a() {}(), function b() {}(), function c() {}(),
|
x = 42,
|
||||||
function d() {}(), function e() {}(), function f() {}(), typeof function g() {}();
|
function a() {}(),
|
||||||
|
!function b() {}(),
|
||||||
|
~function c() {}(),
|
||||||
|
+function d() {}(),
|
||||||
|
-function e() {}(),
|
||||||
|
void function f() {}(),
|
||||||
|
typeof function g() {}();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
iife_drop_side_effect_free: {
|
||||||
|
options = {
|
||||||
|
expression: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
x = 42;
|
||||||
|
(function a() {})();
|
||||||
|
!function b() {}();
|
||||||
|
~function c() {}();
|
||||||
|
+function d() {}();
|
||||||
|
-function e() {}();
|
||||||
|
void function f() {}();
|
||||||
|
typeof function g() {}();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
x = 42,
|
||||||
|
typeof void 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -253,6 +253,7 @@ read_before_assign_1: {
|
|||||||
inline: true,
|
inline: true,
|
||||||
merge_vars: true,
|
merge_vars: true,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
|
|||||||
@@ -122,13 +122,41 @@ negate_iife_4: {
|
|||||||
sequences: true,
|
sequences: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
(function(){ return t })() ? console.log(true) : console.log(false);
|
(function() {
|
||||||
(function(){
|
return t;
|
||||||
|
})() ? console.log(true) : console.log(false);
|
||||||
|
(function() {
|
||||||
console.log("something");
|
console.log("something");
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
!function(){ return t }() ? console.log(false) : console.log(true), function(){
|
!function() {
|
||||||
|
return t;
|
||||||
|
}() ? console.log(false) : console.log(true), !function() {
|
||||||
|
console.log("something");
|
||||||
|
}();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
negate_iife_4_drop_side_effect_free: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
negate_iife: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
return t;
|
||||||
|
})() ? console.log(true) : console.log(false);
|
||||||
|
(function() {
|
||||||
|
console.log("something");
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
!function() {
|
||||||
|
return t;
|
||||||
|
}() ? console.log(false) : console.log(true), function() {
|
||||||
console.log("something");
|
console.log("something");
|
||||||
}();
|
}();
|
||||||
}
|
}
|
||||||
@@ -176,17 +204,49 @@ negate_iife_5: {
|
|||||||
sequences: true,
|
sequences: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
if ((function(){ return t })()) {
|
if (function() {
|
||||||
|
return t;
|
||||||
|
}()) {
|
||||||
foo(true);
|
foo(true);
|
||||||
} else {
|
} else {
|
||||||
bar(false);
|
bar(false);
|
||||||
}
|
}
|
||||||
(function(){
|
(function() {
|
||||||
console.log("something");
|
console.log("something");
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
!function(){ return t }() ? bar(false) : foo(true), function(){
|
!function() {
|
||||||
|
return t;
|
||||||
|
}() ? bar(false) : foo(true), !function() {
|
||||||
|
console.log("something");
|
||||||
|
}();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
negate_iife_5_drop_side_effect_free: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
negate_iife: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
if (function() {
|
||||||
|
return t;
|
||||||
|
}()) {
|
||||||
|
foo(true);
|
||||||
|
} else {
|
||||||
|
bar(false);
|
||||||
|
}
|
||||||
|
(function() {
|
||||||
|
console.log("something");
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
!function() {
|
||||||
|
return t;
|
||||||
|
}() ? bar(false) : foo(true), function() {
|
||||||
console.log("something");
|
console.log("something");
|
||||||
}();
|
}();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1289,6 +1289,7 @@ issue_2878: {
|
|||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
pure_getters: true,
|
pure_getters: true,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var c = 0;
|
var c = 0;
|
||||||
|
|||||||
@@ -289,8 +289,34 @@ iife: {
|
|||||||
typeof function g() {}();
|
typeof function g() {}();
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
x = 42, function a() {}(), function b() {}(), function c() {}(),
|
x = 42,
|
||||||
function d() {}(), function e() {}(), function f() {}(), function g() {}();
|
function a() {}(),
|
||||||
|
!function b() {}(),
|
||||||
|
~function c() {}(),
|
||||||
|
+function d() {}(),
|
||||||
|
-function e() {}(),
|
||||||
|
void function f() {}(),
|
||||||
|
typeof function g() {}();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
iife_drop_side_effect_free: {
|
||||||
|
options = {
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
x = 42;
|
||||||
|
(function a() {})();
|
||||||
|
!function b() {}();
|
||||||
|
~function c() {}();
|
||||||
|
+function d() {}();
|
||||||
|
-function e() {}();
|
||||||
|
void function f() {}();
|
||||||
|
typeof function g() {}();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
x = 42;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1045,11 +1071,102 @@ call: {
|
|||||||
b.c = function() {
|
b.c = function() {
|
||||||
console.log(this === b ? "bar" : "baz");
|
console.log(this === b ? "bar" : "baz");
|
||||||
},
|
},
|
||||||
|
a,
|
||||||
b(),
|
b(),
|
||||||
|
a,
|
||||||
b.c(),
|
b.c(),
|
||||||
(a, b.c)(),
|
(a, b.c)(),
|
||||||
|
a,
|
||||||
b["c"](),
|
b["c"](),
|
||||||
(a, b["c"])(),
|
(a, b["c"])(),
|
||||||
|
a,
|
||||||
|
function() {
|
||||||
|
console.log(this === a);
|
||||||
|
}(),
|
||||||
|
a,
|
||||||
|
new b(),
|
||||||
|
a,
|
||||||
|
new b.c(),
|
||||||
|
a,
|
||||||
|
new b.c(),
|
||||||
|
a,
|
||||||
|
new b["c"](),
|
||||||
|
a,
|
||||||
|
new b["c"](),
|
||||||
|
a,
|
||||||
|
new function() {
|
||||||
|
console.log(this === a);
|
||||||
|
}(),
|
||||||
|
console.log((a, typeof b.c)),
|
||||||
|
console.log((a, typeof b["c"]));
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"foo",
|
||||||
|
"bar",
|
||||||
|
"baz",
|
||||||
|
"bar",
|
||||||
|
"baz",
|
||||||
|
"true",
|
||||||
|
"foo",
|
||||||
|
"baz",
|
||||||
|
"baz",
|
||||||
|
"baz",
|
||||||
|
"baz",
|
||||||
|
"false",
|
||||||
|
"function",
|
||||||
|
"function",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
call_drop_side_effect_free: {
|
||||||
|
options = {
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = function() {
|
||||||
|
return this;
|
||||||
|
}();
|
||||||
|
function b() {
|
||||||
|
console.log("foo");
|
||||||
|
}
|
||||||
|
b.c = function() {
|
||||||
|
console.log(this === b ? "bar" : "baz");
|
||||||
|
};
|
||||||
|
(a, b)();
|
||||||
|
(a, b).c();
|
||||||
|
(a, b.c)();
|
||||||
|
(a, b)["c"]();
|
||||||
|
(a, b["c"])();
|
||||||
|
(a, function() {
|
||||||
|
console.log(this === a);
|
||||||
|
})();
|
||||||
|
new (a, b)();
|
||||||
|
new (a, b).c();
|
||||||
|
new (a, b.c)();
|
||||||
|
new (a, b)["c"]();
|
||||||
|
new (a, b["c"])();
|
||||||
|
new (a, function() {
|
||||||
|
console.log(this === a);
|
||||||
|
})();
|
||||||
|
console.log(typeof (a, b).c);
|
||||||
|
console.log(typeof (a, b)["c"]);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = function() {
|
||||||
|
return this;
|
||||||
|
}();
|
||||||
|
function b() {
|
||||||
|
console.log("foo");
|
||||||
|
}
|
||||||
|
b.c = function() {
|
||||||
|
console.log(this === b ? "bar" : "baz");
|
||||||
|
},
|
||||||
|
b(),
|
||||||
|
b.c(),
|
||||||
|
(0, b.c)(),
|
||||||
|
b["c"](),
|
||||||
|
(0, b["c"])(),
|
||||||
function() {
|
function() {
|
||||||
console.log(this === a);
|
console.log(this === a);
|
||||||
}(),
|
}(),
|
||||||
@@ -1061,8 +1178,8 @@ call: {
|
|||||||
new function() {
|
new function() {
|
||||||
console.log(this === a);
|
console.log(this === a);
|
||||||
}(),
|
}(),
|
||||||
console.log((a, typeof b.c)),
|
console.log(typeof b.c),
|
||||||
console.log((a, typeof b["c"]));
|
console.log(typeof b["c"]);
|
||||||
}
|
}
|
||||||
expect_stdout: [
|
expect_stdout: [
|
||||||
"foo",
|
"foo",
|
||||||
@@ -1097,6 +1214,26 @@ missing_link: {
|
|||||||
expect: {
|
expect: {
|
||||||
var a = 100;
|
var a = 100;
|
||||||
a,
|
a,
|
||||||
|
a++ + (0, 1),
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
missing_link_drop_side_effect_free: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
evaluate: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 100;
|
||||||
|
a;
|
||||||
|
a++ + (0 ? 2 : 1);
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = 100;
|
||||||
a++,
|
a++,
|
||||||
console.log(a);
|
console.log(a);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user