From b9f72a4a81d69a7dd782a5ee70f7eee1cb4aa0e0 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Sun, 11 Mar 2018 15:54:43 +0800 Subject: [PATCH] handle `case` correctly under `reduce_vars` (#2993) fixes #2992 --- lib/compress.js | 21 +++++++++++++++------ test/compress/reduce_vars.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index 2f109a17..1b52f83e 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -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); @@ -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; @@ -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; }); diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js index 836d7fe2..815dff32 100644 --- a/test/compress/reduce_vars.js +++ b/test/compress/reduce_vars.js @@ -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" +} -- 2.34.1