diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2018-05-02 15:11:45 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-02 15:11:45 +0800 |
commit | 1a314e9f60735634f85e56d7b003ee83707561f4 (patch) | |
tree | df8fe25818b920196e949556f96c6b326a2eab1d /test/compress/reduce_vars.js | |
parent | 6fcbd5e217dee38802a0df260303e21a3199c103 (diff) | |
download | tracifyjs-1a314e9f60735634f85e56d7b003ee83707561f4.tar.gz tracifyjs-1a314e9f60735634f85e56d7b003ee83707561f4.zip |
improve `reduce_vars` (#3112)
fixes #3110
Diffstat (limited to 'test/compress/reduce_vars.js')
-rw-r--r-- | test/compress/reduce_vars.js | 163 |
1 files changed, 143 insertions, 20 deletions
diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js index 63a17e72..afc86452 100644 --- a/test/compress/reduce_vars.js +++ b/test/compress/reduce_vars.js @@ -1476,18 +1476,18 @@ defun_redefine: { }; return g() + h(); } + console.log(f()); } expect: { function f() { - function g() { - return 1; - } - g = function() { + (function() { return 3; - }; - return g() + 2; + }); + return 3 + 2; } + console.log(f()); } + expect_stdout: "5" } func_inline: { @@ -1527,23 +1527,37 @@ func_modified: { } input: { function f(a) { - function a() { return 1; } - function b() { return 2; } - function c() { return 3; } + function a() { + return 1; + } + function b() { + return 2; + } + function c() { + return 3; + } b.inject = []; - c = function() { return 4; }; + c = function() { + return 4; + }; return a() + b() + c(); } + console.log(f()); } expect: { function f(a) { - function b() { return 2; } - function c() { return 3; } + function b() { + return 2; + } b.inject = []; - c = function() { return 4; }; - return 1 + 2 + c(); + (function() { + return 4; + }); + return 1 + 2 + 4; } + console.log(f()); } + expect_stdout: "7" } defun_label: { @@ -5054,9 +5068,7 @@ defun_var_1: { console.log(typeof a, typeof b); } expect: { - var a = 42; - function a() {} - console.log(typeof a, "function"); + console.log("number", "function"); } expect_stdout: "number function" } @@ -5076,9 +5088,7 @@ defun_var_2: { console.log(typeof a, typeof b); } expect: { - function a() {} - var a = 42; - console.log(typeof a, "function"); + console.log("number", "function"); } expect_stdout: "number function" } @@ -5710,3 +5720,116 @@ issue_3068_2: { } expect_stdout: true } + +issue_3110_1: { + options = { + conditionals: true, + evaluate: true, + inline: true, + passes: 3, + properties: true, + reduce_vars: true, + sequences: true, + side_effects: true, + unused: true, + } + input: { + (function() { + function foo() { + return isDev ? "foo" : "bar"; + } + var isDev = true; + var obj = { + foo: foo + }; + console.log(foo()); + console.log(obj.foo()); + })(); + } + expect: { + console.log("foo"), + console.log("foo"); + } + expect_stdout: [ + "foo", + "foo", + ] +} + +issue_3110_2: { + options = { + conditionals: true, + evaluate: true, + inline: true, + passes: 4, + properties: true, + reduce_vars: true, + sequences: true, + side_effects: true, + unused: true, + } + input: { + (function() { + function foo() { + return isDev ? "foo" : "bar"; + } + var isDev = true; + console.log(foo()); + var obj = { + foo: foo + }; + console.log(obj.foo()); + })(); + } + expect: { + console.log("foo"), + console.log("foo"); + } + expect_stdout: [ + "foo", + "foo", + ] +} + +issue_3110_3: { + options = { + conditionals: true, + evaluate: true, + inline: true, + properties: true, + reduce_vars: true, + sequences: true, + side_effects: true, + unused: true, + } + input: { + (function() { + function foo() { + return isDev ? "foo" : "bar"; + } + console.log(foo()); + var isDev = true; + var obj = { + foo: foo + }; + console.log(obj.foo()); + })(); + } + expect: { + (function() { + function foo() { + return isDev ? "foo" : "bar"; + } + console.log(foo()); + var isDev = true; + var obj = { + foo: foo + }; + console.log(obj.foo()); + })(); + } + expect_stdout: [ + "bar", + "foo", + ] +} |