diff options
author | alexlamsl <alexlamsl@gmail.com> | 2016-02-17 02:52:28 +0800 |
---|---|---|
committer | Richard van Velzen <rvanvelzen@experty.com> | 2016-02-17 19:34:01 +0100 |
commit | 654743772514f5204d38bc7e7dba566b9dafedbd (patch) | |
tree | 2c0c4fb767f112b87939301ddd28464478f6f36b /test | |
parent | 9662228f6a026908aaf6f3e3531b6abd98fa28fc (diff) | |
download | tracifyjs-654743772514f5204d38bc7e7dba566b9dafedbd.tar.gz tracifyjs-654743772514f5204d38bc7e7dba566b9dafedbd.zip |
preserve ThisBinding for side_effects
Diffstat (limited to 'test')
-rw-r--r-- | test/compress/issue-782.js | 4 | ||||
-rw-r--r-- | test/compress/issue-973.js | 47 | ||||
-rw-r--r-- | test/compress/issue-976.js | 88 |
3 files changed, 129 insertions, 10 deletions
diff --git a/test/compress/issue-782.js b/test/compress/issue-782.js index 80b1493c..2f72d1ab 100644 --- a/test/compress/issue-782.js +++ b/test/compress/issue-782.js @@ -1,10 +1,12 @@ remove_redundant_sequence_items: { options = { side_effects: true }; input: { + (0, 1, eval)(); (0, 1, logThis)(); (0, 1, _decorators.logThis)(); } expect: { + (0, eval)(); logThis(); (0, _decorators.logThis)(); } @@ -13,10 +15,12 @@ remove_redundant_sequence_items: { dont_remove_this_binding_sequence: { options = { side_effects: true }; input: { + (0, eval)(); (0, logThis)(); (0, _decorators.logThis)(); } expect: { + (0, eval)(); logThis(); (0, _decorators.logThis)(); } diff --git a/test/compress/issue-973.js b/test/compress/issue-973.js index f2d44010..0e040922 100644 --- a/test/compress/issue-973.js +++ b/test/compress/issue-973.js @@ -18,6 +18,11 @@ this_binding_conditionals: { (0 || a[b])(); (0 || 1 && a[b])(); (1 ? a[b] : 0)(); + + (1 && eval)(); + (0 || eval)(); + (0 || 1 && eval)(); + (1 ? eval : 0)(); } expect: { a(); @@ -34,6 +39,11 @@ this_binding_conditionals: { (0, a[b])(); (0, a[b])(); (0, a[b])(); + + (0, eval)(); + (0, eval)(); + (0, eval)(); + (0, eval)(); } } @@ -44,26 +54,43 @@ this_binding_collapse_vars: { input: { var c = a; c(); var d = a.b; d(); + var e = eval; e(); } expect: { a(); (0, a.b)(); + (0, eval)(); } } -eval_direct_calls: { +this_binding_side_effects: { options = { - side_effects: true, - collapse_vars: true - } + side_effects : true + }; input: { - (0, eval)(''); - - var fn = eval; - fn(''); + (function (foo) { + (0, foo)(); + (0, foo.bar)(); + (0, eval)('console.log(foo);'); + }()); + (function (foo) { + var eval = console; + (0, foo)(); + (0, foo.bar)(); + (0, eval)('console.log(foo);'); + }()); } expect: { - (0, eval)(''); - (0, eval)(''); + (function (foo) { + foo(); + (0, foo.bar)(); + (0, eval)('console.log(foo);'); + }()); + (function (foo) { + var eval = console; + foo(); + (0, foo.bar)(); + (0, eval)('console.log(foo);'); + }()); } }
\ No newline at end of file diff --git a/test/compress/issue-976.js b/test/compress/issue-976.js new file mode 100644 index 00000000..dea30705 --- /dev/null +++ b/test/compress/issue-976.js @@ -0,0 +1,88 @@ +eval_collapse_vars: { + options = { + collapse_vars:true, sequences:false, properties:true, dead_code:true, conditionals:true, + comparisons:true, evaluate:true, booleans:true, loops:true, unused:true, hoist_funs:true, + keep_fargs:true, if_return:true, join_vars:true, cascade:true, side_effects:true + }; + input: { + function f1() { + var e = 7; + var s = "abcdef"; + var i = 2; + var eval = console.log.bind(console); + var x = s.charAt(i++); + var y = s.charAt(i++); + var z = s.charAt(i++); + eval(x, y, z, e); + } + function p1() { var a = foo(), b = bar(), eval = baz(); return a + b + eval; } + function p2() { var a = foo(), b = bar(), eval = baz; return a + b + eval(); } + (function f2(eval) { + var a = 2; + console.log(a - 5); + eval("console.log(a);"); + })(eval); + } + expect: { + function f1() { + var e = 7, + s = "abcdef", + i = 2, + eval = console.log.bind(console), + x = s.charAt(i++), + y = s.charAt(i++), + z = s.charAt(i++); + eval(x, y, z, e); + } + function p1() { return foo() + bar() + baz(); } + function p2() { var a = foo(), b = bar(), eval = baz; return a + b + eval(); } + (function f2(eval) { + var a = 2; + console.log(a - 5); + eval("console.log(a);"); + })(eval); + } +} + +eval_unused: { + options = { unused: true, keep_fargs: false }; + input: { + function f1(a, eval, c, d, e) { + return a('c') + eval; + } + function f2(a, b, c, d, e) { + return a + eval('c'); + } + function f3(a, eval, c, d, e) { + return a + eval('c'); + } + } + expect: { + function f1(a, eval) { + return a('c') + eval; + } + function f2(a, b, c, d, e) { + return a + eval('c'); + } + function f3(a, eval, c, d, e) { + return a + eval('c'); + } + } +} + +eval_mangle: { + mangle = { + }; + input: { + function f1(a, eval, c, d, e) { + return a('c') + eval; + } + function f2(a, b, c, d, e) { + return a + eval('c'); + } + function f3(a, eval, c, d, e) { + return a + eval('c'); + } + } + expect_exact: 'function f1(n,c,e,a,o){return n("c")+c}function f2(a,b,c,d,e){return a+eval("c")}function f3(a,eval,c,d,e){return a+eval("c")}' +} |