diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/compress.js | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/compress.js b/lib/compress.js index fc11840d..5776fb88 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -77,6 +77,7 @@ function Compressor(options, false_by_default) { screw_ie8 : true, sequences : !false_by_default, side_effects : !false_by_default, + switches : !false_by_default, top_retain : null, toplevel : !!(options && options["top_retain"]), unsafe : false, @@ -1054,7 +1055,7 @@ merge(Compressor.prototype, { stat.value = cons_seq(stat.value); } else if (stat instanceof AST_Exit) { - stat.value = cons_seq(make_node(AST_Undefined, stat)); + stat.value = cons_seq(make_node(AST_Undefined, stat).transform(compressor)); } else if (stat instanceof AST_Switch) { stat.expression = cons_seq(stat.expression); @@ -2526,6 +2527,7 @@ merge(Compressor.prototype, { }); OPT(AST_Switch, function(self, compressor){ + if (!compressor.option("switches")) return self; var branch; var value = self.expression.evaluate(compressor); if (value !== self.expression) { @@ -2599,7 +2601,15 @@ merge(Compressor.prototype, { has_break = true; }); self.walk(tw); - if (!has_break) return make_node(AST_BlockStatement, self, body[0]).optimize(compressor); + if (!has_break) { + body = body[0].body.slice(); + body.unshift(make_node(AST_SimpleStatement, self.expression, { + body: self.expression + })); + return make_node(AST_BlockStatement, self, { + body: body + }).optimize(compressor); + } } return self; @@ -2904,7 +2914,7 @@ merge(Compressor.prototype, { if (name instanceof AST_SymbolRef && name.name == "console" && name.undeclared()) { - return make_node(AST_Undefined, self).transform(compressor); + return make_node(AST_Undefined, self).optimize(compressor); } } } |