@@ -6648,49 +6648,58 @@ Compressor.prototype.compress = function(node) {
|
|||||||
|
|
||||||
function walk_cond(condition, consequent, alternative) {
|
function walk_cond(condition, consequent, alternative) {
|
||||||
var save = segment;
|
var save = segment;
|
||||||
var segments = scan_branches(condition, consequent, alternative);
|
var segments = scan_branches(1, condition, consequent, alternative);
|
||||||
if (consequent) {
|
if (consequent) {
|
||||||
segment = segments[0];
|
segment = segments.consequent.segment;
|
||||||
pop();
|
for (var i = segments.consequent.level; --i >= 0;) pop();
|
||||||
if (segment !== save) return;
|
if (segment !== save) return;
|
||||||
}
|
}
|
||||||
if (alternative) {
|
if (alternative) {
|
||||||
segment = segments[1];
|
segment = segments.alternative.segment;
|
||||||
pop();
|
for (var i = segments.alternative.level; --i >= 0;) pop();
|
||||||
if (segment !== save) return;
|
if (segment !== save) return;
|
||||||
}
|
}
|
||||||
segment = save;
|
segment = save;
|
||||||
}
|
}
|
||||||
|
|
||||||
function scan_branches(condition, consequent, alternative) {
|
function scan_branches(level, condition, consequent, alternative) {
|
||||||
var segments = [ segment, segment ];
|
var segments = {
|
||||||
|
consequent: {
|
||||||
|
segment: segment,
|
||||||
|
level: level,
|
||||||
|
},
|
||||||
|
alternative: {
|
||||||
|
segment: segment,
|
||||||
|
level: level,
|
||||||
|
},
|
||||||
|
}
|
||||||
if (condition instanceof AST_Binary) switch (condition.operator) {
|
if (condition instanceof AST_Binary) switch (condition.operator) {
|
||||||
case "&&":
|
case "&&":
|
||||||
segments[0] = scan_branches(condition.left, condition.right)[0];
|
segments.consequent = scan_branches(level + 1, condition.left, condition.right).consequent;
|
||||||
break;
|
break;
|
||||||
case "||":
|
case "||":
|
||||||
case "??":
|
case "??":
|
||||||
segments[1] = scan_branches(condition.left, null, condition.right)[1];
|
segments.alternative = scan_branches(level + 1, condition.left, null, condition.right).alternative;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
condition.walk(tw);
|
condition.walk(tw);
|
||||||
break;
|
break;
|
||||||
} else if (condition instanceof AST_Conditional) {
|
} else if (condition instanceof AST_Conditional) {
|
||||||
scan_branches(condition.condition, condition.consequent, condition.alternative);
|
scan_branches(level + 1, condition.condition, condition.consequent, condition.alternative);
|
||||||
} else {
|
} else {
|
||||||
condition.walk(tw);
|
condition.walk(tw);
|
||||||
}
|
}
|
||||||
if (consequent) {
|
if (consequent) {
|
||||||
segment = segments[0];
|
segment = segments.consequent.segment;
|
||||||
push();
|
push();
|
||||||
consequent.walk(tw);
|
consequent.walk(tw);
|
||||||
segments[0] = segment;
|
segments.consequent.segment = segment;
|
||||||
}
|
}
|
||||||
if (alternative) {
|
if (alternative) {
|
||||||
segment = segments[1];
|
segment = segments.alternative.segment;
|
||||||
push();
|
push();
|
||||||
alternative.walk(tw);
|
alternative.walk(tw);
|
||||||
segments[1] = segment;
|
segments.alternative.segment = segment;
|
||||||
}
|
}
|
||||||
return segments;
|
return segments;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3942,3 +3942,61 @@ issue_5770_2: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_5772_1: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
merge_vars: true,
|
||||||
|
loops: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function(a) {
|
||||||
|
while (--a)
|
||||||
|
return;
|
||||||
|
var b = console.log("foo") && (c = 42) ? 0 : console.log(c);
|
||||||
|
var c = b;
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function(a) {
|
||||||
|
if (--a)
|
||||||
|
return;
|
||||||
|
var a = console.log("foo") && (c = 42) ? 0 : console.log(c);
|
||||||
|
var c = a;
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"foo",
|
||||||
|
"undefined",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_5772_2: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
merge_vars: true,
|
||||||
|
loops: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function(a) {
|
||||||
|
while (--a)
|
||||||
|
return;
|
||||||
|
var b;
|
||||||
|
var c = console.log("foo") && (b = 1) ? 2 : 3;
|
||||||
|
console.log(b, c);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function(a) {
|
||||||
|
if (--a)
|
||||||
|
return;
|
||||||
|
var b;
|
||||||
|
var a = console.log("foo") && (b = 1) ? 2 : 3;
|
||||||
|
console.log(b, a);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"foo",
|
||||||
|
"undefined 3",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user