diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2021-03-05 05:18:01 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-05 13:18:01 +0800 |
commit | dd30ed6a9bf108f05b103eef81d84f91ae4c6322 (patch) | |
tree | 206a02f962fcbbec0a3747789e6a17b56b31e815 /test/compress/collapse_vars.js | |
parent | cb50a2d192ef8be1aac7577d6ec9c06f27b71232 (diff) | |
download | tracifyjs-dd30ed6a9bf108f05b103eef81d84f91ae4c6322.tar.gz tracifyjs-dd30ed6a9bf108f05b103eef81d84f91ae4c6322.zip |
enhance `collapse_vars` (#4735)
Diffstat (limited to 'test/compress/collapse_vars.js')
-rw-r--r-- | test/compress/collapse_vars.js | 69 |
1 files changed, 61 insertions, 8 deletions
diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js index 6e82e8b0..dcc87397 100644 --- a/test/compress/collapse_vars.js +++ b/test/compress/collapse_vars.js @@ -958,8 +958,7 @@ collapse_vars_misc: { } expect: { function f0(o, a, h) { - var b = 3 - a; - return o.run(b)[7] = h; + return o.run(3 - a)[7] = h; } function f1(x) { return 5 - x } function f2(x) { return foo() / (5 - x) } @@ -2276,8 +2275,8 @@ var_defs: { } expect: { var f1 = function(x, y) { - var r = x + y, z = r * r - r, b = 7; - console.log(z + b); + var r = x + y; + console.log(r * r - r + 7); }; f1("1", 0); } @@ -2907,8 +2906,7 @@ issue_2187_1: { var a = 1; !function(foo) { foo(); - var a = 2; - console.log(a); + console.log(2); }(function() { console.log(a); }); @@ -6961,8 +6959,7 @@ sequence_in_iife_2: { } expect: { var a = "foo", b = 42; - b = a; - console.log(a, b); + console.log(a, b = a); } expect_stdout: "foo foo" } @@ -8804,3 +8801,59 @@ issue_4732_2: { } expect_stdout: "PASS" } + +dot_in_try: { + options = { + collapse_vars: true, + } + input: { + var o, a = 6, b = 7, c; + try { + c = a * b; + o.p(c); + } catch (e) { + console.log(c); + } + } + expect: { + var o, a = 6, b = 7, c; + try { + c = a * b; + o.p(c); + } catch (e) { + console.log(c); + } + } + expect_stdout: "42" +} + +dot_non_local: { + options = { + collapse_vars: true, + } + input: { + var o, a = 6, b = 7, c; + function f() { + c = a * b; + o.p(c); + } + try { + f(); + } catch (e) { + console.log(c); + } + } + expect: { + var o, a = 6, b = 7, c; + function f() { + c = a * b; + o.p(c); + } + try { + f(); + } catch (e) { + console.log(c); + } + } + expect_stdout: "42" +} |