diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-10-02 09:10:25 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-02 16:10:25 +0800 |
commit | 47a5e6e17a91719dd8ee124f818e6a1996b4d668 (patch) | |
tree | 5f659e96b4fc620aad3e87b646d1a3cdb19cea78 /test | |
parent | 090ee895e12ff7e985a972c448b7d29f63e12696 (diff) | |
download | tracifyjs-47a5e6e17a91719dd8ee124f818e6a1996b4d668.tar.gz tracifyjs-47a5e6e17a91719dd8ee124f818e6a1996b4d668.zip |
enhance `if_return` (#4164)
Diffstat (limited to 'test')
-rw-r--r-- | test/compress/if_return.js | 85 | ||||
-rw-r--r-- | test/compress/issue-1052.js | 6 |
2 files changed, 88 insertions, 3 deletions
diff --git a/test/compress/if_return.js b/test/compress/if_return.js index 90ae1210..28e6a57e 100644 --- a/test/compress/if_return.js +++ b/test/compress/if_return.js @@ -663,3 +663,88 @@ nested_if_continue: { "even 21", ] } + +nested_if_return: { + options = { + conditionals: true, + if_return: true, + } + input: { + function f() { + if (A) { + if (B) + return B; + if (C) + return D; + if (E) + return F; + if (G) + return H; + if (I) { + if (J) + return K; + return; + } + if (L) { + if (M) + return; + return N; + } + } + } + } + expect: { + function f() { + if (A) + return B || (C ? D : E ? F : G ? H : I ? J ? K : void 0 : L && !M ? N : void 0); + } + } +} + +issue_866_1: { + options = { + conditionals: true, + if_return: true, + sequences: false, + }; + input: { + function f(a) { + if (a) + return ""; + console.log(a); + } + } + expect: { + function f(a) { + if (a) + return ""; + console.log(a); + } + } +} + +issue_866_2: { + options = { + conditionals: true, + if_return: true, + sequences: true, + } + input: { + (function() { + if (a) + if (b) + c; + else + return d; + })(); + } + expect: { + (function() { + if (a) { + if (!b) + return d; + c; + } + })(); + } +} diff --git a/test/compress/issue-1052.js b/test/compress/issue-1052.js index 30a563fe..cbdd1cb7 100644 --- a/test/compress/issue-1052.js +++ b/test/compress/issue-1052.js @@ -16,7 +16,7 @@ multiple_functions: { ( function() { // NOTE: other compression steps will reduce this // down to just `window`. - if ( window ); + if ( !window ); function f() {} function g() {} } )(); @@ -38,7 +38,7 @@ single_function: { } expect: { ( function() { - if ( window ); + if ( !window ); function f() {} } )(); } @@ -67,7 +67,7 @@ deeply_nested: { // NOTE: other compression steps will reduce this // down to just `window`. if ( window ) - if (document); + if ( !document ); function f() {} function g() {} function h() {} |