diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2018-01-05 20:24:30 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-05 20:24:30 +0800 |
commit | b82feb9302adddb1763e9915b0daf9ff35ab2af2 (patch) | |
tree | 3e8bba3d8e4f15ea261f9f13d84695e6210d4e42 | |
parent | 7f2a591c7ecdb13a20bbad5e7c614672dd890431 (diff) | |
download | tracifyjs-b82feb9302adddb1763e9915b0daf9ff35ab2af2.tar.gz tracifyjs-b82feb9302adddb1763e9915b0daf9ff35ab2af2.zip |
improve `if_return` (#2727)
-rw-r--r-- | lib/compress.js | 5 | ||||
-rw-r--r-- | test/compress/if_return.js | 24 |
2 files changed, 27 insertions, 2 deletions
diff --git a/lib/compress.js b/lib/compress.js index e824d6ff..7f33b53b 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1436,8 +1436,9 @@ merge(Compressor.prototype, { } //--- // if (foo()) return x; [ return ; ] ==> return foo() ? x : undefined; - if (multiple_if_returns && in_lambda && value && !stat.alternative - && (!next || next instanceof AST_Return)) { + if (value && !stat.alternative + && (!next && in_lambda && multiple_if_returns + || next instanceof AST_Return)) { CHANGED = true; stat = stat.clone(); stat.alternative = next || make_node(AST_Return, stat, { diff --git a/test/compress/if_return.js b/test/compress/if_return.js index a0dfdc9a..981b437f 100644 --- a/test/compress/if_return.js +++ b/test/compress/if_return.js @@ -372,3 +372,27 @@ if_var_return: { } } } + +if_if_return_return: { + options = { + conditionals: true, + if_return: true, + } + input: { + function f(a, b) { + if (a) { + if (b) + return b; + return; + } + g(); + } + } + expect: { + function f(a, b) { + if (a) + return b || void 0; + g(); + } + } +} |