diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-08-06 09:39:50 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-06 09:39:50 +0100 |
commit | 9b05494ebcbcc40a6682cf570aa183f045244650 (patch) | |
tree | 933a355be5fa4715413c09ce7795e7b1c43b0616 /test/compress | |
parent | 30ef20a208adceeb465593d89dd9fead7ab953c2 (diff) | |
download | tracifyjs-9b05494ebcbcc40a6682cf570aa183f045244650.tar.gz tracifyjs-9b05494ebcbcc40a6682cf570aa183f045244650.zip |
fix corner cases in aliasing of global variables (#4039)
fixes #4038
Diffstat (limited to 'test/compress')
-rw-r--r-- | test/compress/collapse_vars.js | 58 | ||||
-rw-r--r-- | test/compress/reduce_vars.js | 22 |
2 files changed, 79 insertions, 1 deletions
diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js index 109bbde0..d68c10e2 100644 --- a/test/compress/collapse_vars.js +++ b/test/compress/collapse_vars.js @@ -8317,3 +8317,61 @@ issue_4012: { } expect_stdout: "PASS" } + +global_assign: { + options = { + collapse_vars: true, + } + input: { + this.A = "FAIL"; + A = "PASS"; + B = "FAIL"; + console.log(A); + } + expect: { + this.A = "FAIL"; + A = "PASS"; + B = "FAIL"; + console.log(A); + } + expect_stdout: "PASS" +} + +global_read: { + options = { + collapse_vars: true, + } + input: { + var a = 0; + a = this.A; + A = 1; + a ? console.log("FAIL") : console.log("PASS"); + } + expect: { + var a = 0; + a = this.A; + A = 1; + a ? console.log("FAIL") : console.log("PASS"); + } + expect_stdout: "PASS" +} + +issue_4038: { + options = { + collapse_vars: true, + } + input: { + var a = 0; + a = this; + a = a.A; + A = 1; + a ? console.log("FAIL") : console.log("PASS"); + } + expect: { + var a = 0; + a = (a = this).A; + A = 1; + a ? console.log("FAIL") : console.log("PASS"); + } + expect_stdout: "PASS" +} diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js index 85969f90..77782cfd 100644 --- a/test/compress/reduce_vars.js +++ b/test/compress/reduce_vars.js @@ -7402,7 +7402,27 @@ issue_4030: { } expect: { A = "PASS"; - console.log("PASS"); + console.log(A); + } + expect_stdout: "PASS" +} + +global_assign: { + options = { + evaluate: true, + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + A = "FAIL"; + this.A = "PASS"; + console.log(A); + } + expect: { + A = "FAIL"; + this.A = "PASS"; + console.log(A); } expect_stdout: "PASS" } |