diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-09-15 21:43:01 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-16 04:43:01 +0800 |
commit | ad27c1420226032459157444cf7ac17bf95bd5e6 (patch) | |
tree | c09914c296bd2cbbc3e0bbe5e2fd663b01e2738f /test/compress | |
parent | a62b086184e70072929a218d97dd11ce8efdfaff (diff) | |
download | tracifyjs-ad27c1420226032459157444cf7ac17bf95bd5e6.tar.gz tracifyjs-ad27c1420226032459157444cf7ac17bf95bd5e6.zip |
fix corner cases in `merge_vars` (#4108)
fixes #4107
fixes #4109
fixes #4110
fixes #4111
Diffstat (limited to 'test/compress')
-rw-r--r-- | test/compress/merge_vars.js | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/test/compress/merge_vars.js b/test/compress/merge_vars.js index 4c5f6dac..f83643e3 100644 --- a/test/compress/merge_vars.js +++ b/test/compress/merge_vars.js @@ -324,3 +324,129 @@ issue_4103: { "NaN", ] } + +issue_4107: { + options = { + keep_fargs: "strict", + merge_vars: true, + reduce_vars: true, + unused: true, + } + input: { + (function() { + function f(b, b, c) { + var d = 1 && a, a = console || c; + console.log(typeof a); + } + f(); + })(); + console.log(typeof a); + } + expect: { + (function() { + (function(c) { + var a = console || c; + console.log(typeof a); + })(); + })(); + console.log(typeof a); + } + expect_stdout: [ + "object", + "undefined", + ] +} + +issue_4109: { + options = { + ie8: true, + merge_vars: true, + toplevel: true, + } + input: { + var a = "foo"; + try { + throw "bar"; + } catch (e) { + console.log(e); + } finally { + var o = a; + for (var k in o); + (function() { + a++; + }); + } + console.log(a); + } + expect: { + var a = "foo"; + try { + throw "bar"; + } catch (e) { + console.log(e); + } finally { + var o = a; + for (var k in o); + (function() { + a++; + }); + } + console.log(a); + } + expect_stdout: [ + "bar", + "foo", + ] +} + +issue_4110: { + options = { + merge_vars: true, + toplevel: true, + } + input: { + while (a) + var c; + var b, a = c += b = a; + console.log(b); + } + expect: { + while (a) + var c; + var b, a = c += b = a; + console.log(b); + } + expect_stdout: "undefined" +} + +issue_4111: { + options = { + join_vars: true, + loops: true, + merge_vars: true, + toplevel: true, + } + input: { + var a = 0; + if (a) + a = 0; + else + for (var b = 0; --b && ++a < 2;) { + var o = console, k; + for (k in o); + } + console.log(a); + } + expect: { + var a = 0; + if (a) + a = 0; + else + for (var b = 0; --b && ++a < 2;) { + var o = console, k; + for (k in o); + } + console.log(a); + } + expect_stdout: "2" +} |