Skip to content

Commit

Permalink
handle case correctly under reduce_vars (#2993)
Browse files Browse the repository at this point in the history
fixes #2992
  • Loading branch information
alexlamsl committed Mar 11, 2018
1 parent fc6ebd0 commit b9f72a4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
21 changes: 15 additions & 6 deletions lib/compress.js
Expand Up @@ -517,6 +517,15 @@ merge(Compressor.prototype, {
pop(tw);
return true;
});
def(AST_Case, function(tw) {
push(tw);
this.expression.walk(tw);
pop(tw);
push(tw);
walk_body(this, tw);
pop(tw);
return true;
});
def(AST_Conditional, function(tw) {
this.condition.walk(tw);
push(tw);
Expand All @@ -527,6 +536,12 @@ merge(Compressor.prototype, {
pop(tw);
return true;
});
def(AST_Default, function(tw, descend) {
push(tw);
descend();
pop(tw);
return true;
});
def(AST_Defun, function(tw, descend, compressor) {
this.inlined = false;
var save_ids = tw.safe_ids;
Expand Down Expand Up @@ -624,12 +639,6 @@ merge(Compressor.prototype, {
pop(tw);
return true;
});
def(AST_SwitchBranch, function(tw, descend) {
push(tw);
descend();
pop(tw);
return true;
});
def(AST_SymbolCatch, function() {
this.definition().fixed = false;
});
Expand Down
30 changes: 30 additions & 0 deletions test/compress/reduce_vars.js
Expand Up @@ -5545,3 +5545,33 @@ issue_2919: {
}
expect_stdout: "function"
}

issue_2992: {
options = {
evaluate: true,
reduce_vars: true,
}
input: {
var c = "PASS";
(function f(b) {
switch (0) {
case 0:
case b = 1:
b && (c = "FAIL");
}
})();
console.log(c);
}
expect: {
var c = "PASS";
(function f(b) {
switch (0) {
case 0:
case b = 1:
b && (c = "FAIL");
}
})();
console.log(c);
}
expect_stdout: "PASS"
}

0 comments on commit b9f72a4

Please sign in to comment.