diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2017-06-24 21:30:06 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-24 21:30:06 +0800 |
commit | 9db4c42380ff409b6be933083b92311522679988 (patch) | |
tree | b9ee5f2915bd6661b74fd6bb790e0f4b86308f75 /test/compress/pure_getters.js | |
parent | 94e5e00c0321b92aca1abf170c12a02d6c3275b5 (diff) | |
download | tracifyjs-9db4c42380ff409b6be933083b92311522679988.tar.gz tracifyjs-9db4c42380ff409b6be933083b92311522679988.zip |
fix `cascade` & `collapse` on property access of constants (#2158)
Diffstat (limited to 'test/compress/pure_getters.js')
-rw-r--r-- | test/compress/pure_getters.js | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/test/compress/pure_getters.js b/test/compress/pure_getters.js index 81a96b73..2e7e17dc 100644 --- a/test/compress/pure_getters.js +++ b/test/compress/pure_getters.js @@ -241,3 +241,97 @@ issue_2110_2: { } expect_stdout: "function" } + +set_immutable_1: { + options = { + collapse_vars: true, + evaluate: true, + pure_getters: "strict", + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + var a = 1; + a.foo += ""; + if (a.foo) console.log("FAIL"); + else console.log("PASS"); + } + expect: { + 1..foo += ""; + if (1..foo) console.log("FAIL"); + else console.log("PASS"); + } + expect_stdout: "PASS" +} + +set_immutable_2: { + options = { + cascade: true, + conditionals: true, + pure_getters: "strict", + reduce_vars: true, + sequences: true, + side_effects: true, + toplevel: true, + } + input: { + var a = 1; + a.foo += ""; + if (a.foo) console.log("FAIL"); + else console.log("PASS"); + } + expect: { + var a = 1; + a.foo += "", a.foo ? console.log("FAIL") : console.log("PASS"); + } + expect_stdout: "PASS" +} + +set_mutable_1: { + options = { + collapse_vars: true, + evaluate: true, + pure_getters: "strict", + reduce_vars: true, + unused: true, + } + input: { + !function a() { + a.foo += ""; + if (a.foo) console.log("PASS"); + else console.log("FAIL"); + }(); + } + expect: { + !function a() { + if (a.foo += "") console.log("PASS"); + else console.log("FAIL"); + }(); + } + expect_stdout: "PASS" +} + +set_mutable_2: { + options = { + cascade: true, + conditionals: true, + pure_getters: "strict", + reduce_vars: true, + sequences: true, + side_effects: true, + } + input: { + !function a() { + a.foo += ""; + if (a.foo) console.log("PASS"); + else console.log("FAIL"); + }(); + } + expect: { + !function a() { + (a.foo += "") ? console.log("PASS") : console.log("FAIL"); + }(); + } + expect_stdout: "PASS" +} |