diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2018-02-03 02:44:40 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-03 02:44:40 +0800 |
commit | e6a2e9e4d08b73c327e95bcd4da923f9404788d0 (patch) | |
tree | e642ddf31db372f679d51000c812104ebf114f8a /test/compress/collapse_vars.js | |
parent | e773f0392769794173358b362a645facb51b2ad2 (diff) | |
download | tracifyjs-e6a2e9e4d08b73c327e95bcd4da923f9404788d0.tar.gz tracifyjs-e6a2e9e4d08b73c327e95bcd4da923f9404788d0.zip |
allow `collapse_vars` across conditional branches (#2867)
Diffstat (limited to 'test/compress/collapse_vars.js')
-rw-r--r-- | test/compress/collapse_vars.js | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js index 948389b1..a2571c24 100644 --- a/test/compress/collapse_vars.js +++ b/test/compress/collapse_vars.js @@ -4249,3 +4249,137 @@ issue_2858: { } expect_stdout: "undefined" } + +cond_branch_1: { + options = { + collapse_vars: true, + sequences: true, + unused: true, + } + input: { + function f1(b, c) { + var log = console.log; + var a = ++c; + if (b) b++; + log(a, b); + } + function f2(b, c) { + var log = console.log; + var a = ++c; + b && b++; + log(a, b); + } + function f3(b, c) { + var log = console.log; + var a = ++c; + b ? b++ : b--; + log(a, b); + } + f1(1, 2); + f2(3, 4); + f3(5, 6); + } + expect: { + function f1(b, c) { + var log = console.log; + if (b) b++; + log(++c, b); + } + function f2(b, c) { + var log = console.log; + b && b++, + log(++c, b); + } + function f3(b, c) { + var log = console.log; + b ? b++ : b--, + log(++c, b); + } + f1(1, 2), + f2(3, 4), + f3(5, 6); + } + expect_stdout: [ + "3 2", + "5 4", + "7 6", + ] +} + +cond_branch_2: { + options = { + collapse_vars: true, + sequences: true, + unused: true, + } + input: { + function f1(b, c) { + var log = console.log; + var a = ++c; + if (b) b += a; + log(a, b); + } + function f2(b, c) { + var log = console.log; + var a = ++c; + b && (b += a); + log(a, b); + } + function f3(b, c) { + var log = console.log; + var a = ++c; + b ? b += a : b--; + log(a, b); + } + f1(1, 2); + f2(3, 4); + f3(5, 6); + } + expect: { + function f1(b, c) { + var log = console.log; + var a = ++c; + if (b) b += a; + log(a, b); + } + function f2(b, c) { + var log = console.log; + var a = ++c; + b && (b += a), + log(a, b); + } + function f3(b, c) { + var log = console.log; + var a = ++c; + b ? b += a : b--, + log(a, b); + } + f1(1, 2), + f2(3, 4), + f3(5, 6); + } + expect_stdout: [ + "3 4", + "5 8", + "7 12", + ] +} + +cond_branch_switch: { + options = { + collapse_vars: true, + } + input: { + var c = 0; + if (c = 1 + c, 0) switch (c = 1 + c) { + } + console.log(c); + } + expect: { + var c = 0; + if (c = 1 + c, 0) switch (c = 1 + c) { + } + console.log(c); + } + expect_stdout: "1" +} |