@@ -9858,7 +9858,7 @@ merge(Compressor.prototype, {
|
|||||||
OPT(AST_Sequence, function(self, compressor) {
|
OPT(AST_Sequence, function(self, compressor) {
|
||||||
var expressions = filter_for_side_effects();
|
var expressions = filter_for_side_effects();
|
||||||
var end = expressions.length - 1;
|
var end = expressions.length - 1;
|
||||||
merge_conditional_assignments();
|
merge_assignments();
|
||||||
trim_right_for_undefined();
|
trim_right_for_undefined();
|
||||||
if (end == 0) {
|
if (end == 0) {
|
||||||
self = maintain_this_binding(compressor, compressor.parent(), compressor.self(), expressions[0]);
|
self = maintain_this_binding(compressor, compressor.parent(), compressor.self(), expressions[0]);
|
||||||
@@ -9895,19 +9895,33 @@ merge(Compressor.prototype, {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function merge_conditional_assignments() {
|
function is_simple_assign(node) {
|
||||||
if (!compressor.option("conditionals")) return;
|
return node instanceof AST_Assign
|
||||||
|
&& node.operator == "="
|
||||||
|
&& node.left instanceof AST_SymbolRef
|
||||||
|
&& node.left.definition();
|
||||||
|
}
|
||||||
|
|
||||||
|
function merge_assignments() {
|
||||||
for (var i = 1; i < end; i++) {
|
for (var i = 1; i < end; i++) {
|
||||||
var assign = expressions[i - 1];
|
var prev = expressions[i - 1];
|
||||||
if (!(assign instanceof AST_Assign)) continue;
|
var def = is_simple_assign(prev);
|
||||||
if (assign.operator != "=") continue;
|
if (!def) continue;
|
||||||
if (!(assign.left instanceof AST_SymbolRef)) continue;
|
var expr = expressions[i];
|
||||||
var def = assign.left.definition();
|
if (compressor.option("conditionals")) {
|
||||||
var cond = to_conditional_assignment(compressor, def, assign.right, expressions[i]);
|
var cond = to_conditional_assignment(compressor, def, prev.right, expr);
|
||||||
if (!cond) continue;
|
if (cond) {
|
||||||
assign.right = cond;
|
prev.right = cond;
|
||||||
expressions.splice(i, 1);
|
expressions.splice(i--, 1);
|
||||||
end--;
|
end--;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (compressor.option("dead_code")
|
||||||
|
&& is_simple_assign(expr) === def
|
||||||
|
&& expr.right.is_constant_expression(def.scope.resolve())) {
|
||||||
|
expressions[--i] = prev.right;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -11143,7 +11157,7 @@ merge(Compressor.prototype, {
|
|||||||
var scan_scope = new TreeWalker(function(node) {
|
var scan_scope = new TreeWalker(function(node) {
|
||||||
if (reachable) return true;
|
if (reachable) return true;
|
||||||
if (node instanceof AST_Lambda && node !== self) {
|
if (node instanceof AST_Lambda && node !== self) {
|
||||||
if (!(is_async(node) || is_generator(node))) {
|
if (!(node.name || is_async(node) || is_generator(node))) {
|
||||||
var parent = scan_scope.parent();
|
var parent = scan_scope.parent();
|
||||||
if (parent instanceof AST_Call && parent.expression === node) return;
|
if (parent instanceof AST_Call && parent.expression === node) return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1103,6 +1103,21 @@ last_assign_finally: {
|
|||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
consecutive_assignments: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
while (a = void 0, a = "PASS", console.log(a));
|
||||||
|
var a;
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
while (void 0, a = "PASS", console.log(a));
|
||||||
|
var a;
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
issue_3578: {
|
issue_3578: {
|
||||||
options = {
|
options = {
|
||||||
dead_code: true,
|
dead_code: true,
|
||||||
@@ -1584,3 +1599,37 @@ issue_4570: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "NaN"
|
expect_stdout: "NaN"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_5030: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function(a, b) {
|
||||||
|
a = function f() {
|
||||||
|
if (a)
|
||||||
|
if (b--)
|
||||||
|
setImmediate(f);
|
||||||
|
else
|
||||||
|
console.log("FAIL");
|
||||||
|
else
|
||||||
|
console.log("PASS");
|
||||||
|
}();
|
||||||
|
})(42, 1);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function(a, b) {
|
||||||
|
a = function f() {
|
||||||
|
if (a)
|
||||||
|
if (b--)
|
||||||
|
setImmediate(f);
|
||||||
|
else
|
||||||
|
console.log("FAIL");
|
||||||
|
else
|
||||||
|
console.log("PASS");
|
||||||
|
}();
|
||||||
|
})(42, 1);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
node_version: ">=0.12"
|
||||||
|
}
|
||||||
|
|||||||
@@ -422,7 +422,9 @@ inline_loop_1: {
|
|||||||
inline_loop_2: {
|
inline_loop_2: {
|
||||||
options = {
|
options = {
|
||||||
inline: true,
|
inline: true,
|
||||||
|
sequences: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
while (function(a = [ "PASS" ]) {
|
while (function(a = [ "PASS" ]) {
|
||||||
@@ -432,10 +434,11 @@ inline_loop_2: {
|
|||||||
}());
|
}());
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
while (a = [ "PASS" ], a = function f(b) {
|
while (a = [ "PASS" ],
|
||||||
console.log(a[b]);
|
b = void 0,
|
||||||
}(0), void 0) ;
|
b = 0,
|
||||||
var a;
|
void (a = void console.log(a[b])));
|
||||||
|
var a, b;
|
||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
node_version: ">=6"
|
node_version: ">=6"
|
||||||
|
|||||||
Reference in New Issue
Block a user