diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-06-11 19:16:13 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-12 02:16:13 +0800 |
commit | e9465717abb77fed206455881a983f313d2b894c (patch) | |
tree | c111ea3a6fb37dbf3b6f24cc41e1b2855edc47a6 /test/compress | |
parent | e89031f1afda74264c4cd4153032c16ba8d86879 (diff) | |
download | tracifyjs-e9465717abb77fed206455881a983f313d2b894c.tar.gz tracifyjs-e9465717abb77fed206455881a983f313d2b894c.zip |
enhance `dead_code` (#3990)
Diffstat (limited to 'test/compress')
-rw-r--r-- | test/compress/dead-code.js | 130 |
1 files changed, 116 insertions, 14 deletions
diff --git a/test/compress/dead-code.js b/test/compress/dead-code.js index 5506b95a..a2ebf37a 100644 --- a/test/compress/dead-code.js +++ b/test/compress/dead-code.js @@ -1169,29 +1169,131 @@ redundant_assignments: { expect_stdout: "PASS PASS" } -self_assignments: { +self_assignments_1: { options = { dead_code: true, } input: { - var a = "PASS", b = 0, l = [ "FAIL", "PASS" ], o = { p: "PASS" }; + var a = "PASS"; a = a; - l[0] = l[0]; - l[b] = l[b]; - l[b++] = l[b++]; - o.p = o.p; - console.log(a, b, l[0], o.p); + console.log(a); } expect: { - var a = "PASS", b = 0, l = [ "FAIL", "PASS" ], o = { p: "PASS" }; + var a = "PASS"; a; - l[0]; - l[b]; - l[b++] = l[b++]; - o.p; - console.log(a, b, l[0], o.p); + console.log(a); + } + expect_stdout: "PASS" +} + +self_assignments_2: { + options = { + dead_code: true, + pure_getters: "strict", + reduce_vars: true, + side_effects: true, + toplevel: true, + } + input: { + var a = "q", o = { + p: "PASS", + }; + o.p = o.p; + o[a] = o[a]; + console.log(o.p, o[a]); + } + expect: { + var a = "q", o = { + p: "PASS", + }; + console.log(o.p, o[a]); + } + expect_stdout: "PASS undefined" +} + +self_assignments_3: { + options = { + dead_code: true, + pure_getters: "strict", + reduce_vars: true, + side_effects: true, + toplevel: true, + } + input: { + var a = "q", o = { + p: "FAIL", + get q() { + return "PASS"; + }, + set q(v) { + this.p = v; + }, + }; + o.p = o.p; + o[a] = o[a]; + console.log(o.p, o[a]); + } + expect: { + var a = "q", o = { + p: "FAIL", + get q() { + return "PASS"; + }, + set q(v) { + this.p = v; + }, + }; + o.p = o.p; + o[a] = o[a]; + console.log(o.p, o[a]); + } + expect_stdout: "PASS PASS" +} + +self_assignments_4: { + options = { + dead_code: true, + pure_getters: "strict", + reduce_vars: true, + side_effects: true, + toplevel: true, + } + input: { + var i = 0, l = [ "PASS" ]; + l[0] = l[0]; + l[i] = l[i]; + console.log(l[0], i); + } + expect: { + var i = 0, l = [ "PASS" ]; + console.log(l[0], i); + } + expect_stdout: "PASS 0" +} + +self_assignments_5: { + options = { + dead_code: true, + evaluate: true, + passes: 3, + pure_getters: "strict", + reduce_vars: true, + side_effects: true, + toplevel: true, + } + input: { + var i = 0, l = [ "FAIL", "PASS" ]; + l[0] = l[0]; + l[i] = l[i]; + l[i++] = l[i++]; + console.log(l[0], i); + } + expect: { + var i = 0, l = [ "FAIL", "PASS" ]; + l[0] = l[1]; + console.log(l[0], 2); } - expect_stdout: "PASS 2 PASS PASS" + expect_stdout: "PASS 2" } issue_3967: { |