From e9465717abb77fed206455881a983f313d2b894c Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Thu, 11 Jun 2020 19:16:13 +0100 Subject: enhance `dead_code` (#3990) --- test/compress/dead-code.js | 130 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 116 insertions(+), 14 deletions(-) (limited to 'test/compress') 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: { -- cgit v1.2.3