aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/compress.js19
-rw-r--r--test/compress/functions.js4
2 files changed, 16 insertions, 7 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 5da07f71..32212688 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1159,10 +1159,10 @@ merge(Compressor.prototype, {
if (!expr.left.has_side_effects(compressor)) {
candidates.push(hit_stack.slice());
}
- } else if (expr instanceof AST_Unary) {
- if (expr.operator == "++" || expr.operator == "--") {
- candidates.push(hit_stack.slice());
- }
+ extract_candidates(expr.right);
+ } else if (expr instanceof AST_Binary) {
+ extract_candidates(expr.left);
+ extract_candidates(expr.right);
} else if (expr instanceof AST_Call) {
extract_candidates(expr.expression);
expr.args.forEach(extract_candidates);
@@ -1187,14 +1187,22 @@ merge(Compressor.prototype, {
} else if (expr instanceof AST_Switch) {
extract_candidates(expr.expression);
expr.body.forEach(extract_candidates);
+ } else if (expr instanceof AST_Unary) {
+ if (expr.operator == "++" || expr.operator == "--") {
+ candidates.push(hit_stack.slice());
+ }
} else if (expr instanceof AST_VarDef) {
- if (expr.value) candidates.push(hit_stack.slice());
+ if (expr.value) {
+ candidates.push(hit_stack.slice());
+ extract_candidates(expr.value);
+ }
}
hit_stack.pop();
}
function find_stop(node, level) {
var parent = scanner.parent(level);
+ if (parent instanceof AST_Binary) return node;
if (parent instanceof AST_Call) return node;
if (parent instanceof AST_Case) return node;
if (parent instanceof AST_Conditional) return node;
@@ -1202,6 +1210,7 @@ merge(Compressor.prototype, {
if (parent instanceof AST_If) return node;
if (parent instanceof AST_Sequence) return find_stop(parent, level + 1);
if (parent instanceof AST_Switch) return node;
+ if (parent instanceof AST_VarDef) return node;
return null;
}
diff --git a/test/compress/functions.js b/test/compress/functions.js
index 7acb7fde..dd98ba60 100644
--- a/test/compress/functions.js
+++ b/test/compress/functions.js
@@ -1285,7 +1285,7 @@ issue_2630_1: {
expect: {
var c = 0;
(function() {
- while (c++, void (c = 1 + c));
+ while (void (c = 1 + ++c));
})(),
console.log(c);
}
@@ -1316,7 +1316,7 @@ issue_2630_2: {
expect: {
var c = 0;
!function() {
- while (c += 1, void (c = 1 + c));
+ while (void (c = 1 + (c += 1)));
}(), console.log(c);
}
expect_stdout: "2"