@@ -9858,7 +9858,7 @@ merge(Compressor.prototype, {
|
||||
OPT(AST_Sequence, function(self, compressor) {
|
||||
var expressions = filter_for_side_effects();
|
||||
var end = expressions.length - 1;
|
||||
merge_conditional_assignments();
|
||||
merge_assignments();
|
||||
trim_right_for_undefined();
|
||||
if (end == 0) {
|
||||
self = maintain_this_binding(compressor, compressor.parent(), compressor.self(), expressions[0]);
|
||||
@@ -9895,19 +9895,33 @@ merge(Compressor.prototype, {
|
||||
}
|
||||
}
|
||||
|
||||
function merge_conditional_assignments() {
|
||||
if (!compressor.option("conditionals")) return;
|
||||
function is_simple_assign(node) {
|
||||
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++) {
|
||||
var assign = expressions[i - 1];
|
||||
if (!(assign instanceof AST_Assign)) continue;
|
||||
if (assign.operator != "=") continue;
|
||||
if (!(assign.left instanceof AST_SymbolRef)) continue;
|
||||
var def = assign.left.definition();
|
||||
var cond = to_conditional_assignment(compressor, def, assign.right, expressions[i]);
|
||||
if (!cond) continue;
|
||||
assign.right = cond;
|
||||
expressions.splice(i, 1);
|
||||
end--;
|
||||
var prev = expressions[i - 1];
|
||||
var def = is_simple_assign(prev);
|
||||
if (!def) continue;
|
||||
var expr = expressions[i];
|
||||
if (compressor.option("conditionals")) {
|
||||
var cond = to_conditional_assignment(compressor, def, prev.right, expr);
|
||||
if (cond) {
|
||||
prev.right = cond;
|
||||
expressions.splice(i--, 1);
|
||||
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) {
|
||||
if (reachable) return true;
|
||||
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();
|
||||
if (parent instanceof AST_Call && parent.expression === node) return;
|
||||
}
|
||||
|
||||
@@ -1103,6 +1103,21 @@ last_assign_finally: {
|
||||
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: {
|
||||
options = {
|
||||
dead_code: true,
|
||||
@@ -1584,3 +1599,37 @@ issue_4570: {
|
||||
}
|
||||
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: {
|
||||
options = {
|
||||
inline: true,
|
||||
sequences: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
while (function(a = [ "PASS" ]) {
|
||||
@@ -432,10 +434,11 @@ inline_loop_2: {
|
||||
}());
|
||||
}
|
||||
expect: {
|
||||
while (a = [ "PASS" ], a = function f(b) {
|
||||
console.log(a[b]);
|
||||
}(0), void 0) ;
|
||||
var a;
|
||||
while (a = [ "PASS" ],
|
||||
b = void 0,
|
||||
b = 0,
|
||||
void (a = void console.log(a[b])));
|
||||
var a, b;
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
|
||||
Reference in New Issue
Block a user