diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-09-10 15:31:34 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-10 22:31:34 +0800 |
commit | d7456a2dc220112a5fc294b102612c568395d72c (patch) | |
tree | d038a47ec99397258ca23c73612b75e7e79d2c43 /test | |
parent | d97672613d28632a038fa14eb35d8c19c748320d (diff) | |
download | tracifyjs-d7456a2dc220112a5fc294b102612c568395d72c.tar.gz tracifyjs-d7456a2dc220112a5fc294b102612c568395d72c.zip |
enhance `if_return` (#4097)
Diffstat (limited to 'test')
-rw-r--r-- | test/compress/if_return.js | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/test/compress/if_return.js b/test/compress/if_return.js index 836fab17..90ae1210 100644 --- a/test/compress/if_return.js +++ b/test/compress/if_return.js @@ -594,3 +594,72 @@ iife_if_return_simple: { } expect_stdout: "PASS" } + +nested_if_break: { + options = { + if_return: true, + } + input: { + for (var i = 0; i < 3; i++) + L1: if ("number" == typeof i) { + if (0 === i) break L1; + console.log(i); + } + } + expect: { + for (var i = 0; i < 3; i++) + L1: if ("number" == typeof i) + if (0 !== i) console.log(i); + } + expect_stdout: [ + "1", + "2", + ] +} + +nested_if_continue: { + options = { + conditionals: true, + if_return: true, + join_vars: true, + loops: true, + } + input: { + function f(n) { + var i = 0; + do { + if ("number" == typeof n) { + if (0 === n) { + console.log("even", i); + continue; + } + if (1 === n) { + console.log("odd", i); + continue; + } + i++; + } + } while (0 <= (n -= 2)); + } + f(37); + f(42); + } + expect: { + function f(n) { + for (var i = 0; + "number" == typeof n + && (0 !== n + ? 1 !== n + ? i++ + : console.log("odd", i) + : console.log("even", i)), + 0 <= (n -= 2);); + } + f(37); + f(42); + } + expect_stdout: [ + "odd 18", + "even 21", + ] +} |