diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2017-12-01 14:32:00 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-01 14:32:00 +0800 |
commit | 7ac6fdcc9923e173522c4b94b919ac09049024f9 (patch) | |
tree | 0e926ef1b019f8dae6735bfb6ae20c0b4b398d03 /lib | |
parent | f6610baaa8c5c6acf8f4a52babf68d0439aead1f (diff) | |
download | tracifyjs-7ac6fdcc9923e173522c4b94b919ac09049024f9.tar.gz tracifyjs-7ac6fdcc9923e173522c4b94b919ac09049024f9.zip |
improve switch case compression (#2547)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/compress.js | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/lib/compress.js b/lib/compress.js index dfee94fc..adfbb793 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -3312,6 +3312,11 @@ merge(Compressor.prototype, { } } else if (!(value instanceof AST_Node)) { var exp = branch.expression.evaluate(compressor); + if (!(exp instanceof AST_Node) && exp !== value) { + eliminate_branch(branch, body[body.length - 1]); + continue; + } + if (exp instanceof AST_Node) exp = branch.expression.tail_node().evaluate(compressor); if (exp === value) { exact_match = branch; if (default_branch) { @@ -3320,9 +3325,6 @@ merge(Compressor.prototype, { eliminate_branch(default_branch, body[default_index - 1]); default_branch = null; } - } else if (exp !== branch.expression) { - eliminate_branch(branch, body[body.length - 1]); - continue; } } if (aborts(branch)) { @@ -3365,12 +3367,16 @@ merge(Compressor.prototype, { }); self.walk(tw); if (!has_break) { - body = body[0].body.slice(); - body.unshift(make_node(AST_SimpleStatement, self.expression, { - body: self.expression + var statements = body[0].body.slice(); + var exp = body[0].expression; + if (exp) statements.unshift(make_node(AST_SimpleStatement, exp, { + body: exp + })); + statements.unshift(make_node(AST_SimpleStatement, self.expression, { + body:self.expression })); return make_node(AST_BlockStatement, self, { - body: body + body: statements }).optimize(compressor); } } |