diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2018-02-23 23:51:49 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-23 23:51:49 +0800 |
commit | f40f5eb228aa576f2555b5aaa20f3a676aaad147 (patch) | |
tree | 6a6f176ee0afc1af3a0fc68d49087322a5e289a0 /test/compress | |
parent | 604caa09e7181791621db6c96b92cb8ecc7ace24 (diff) | |
download | tracifyjs-f40f5eb228aa576f2555b5aaa20f3a676aaad147.tar.gz tracifyjs-f40f5eb228aa576f2555b5aaa20f3a676aaad147.zip |
improve `mangle` (#2948)
Diffstat (limited to 'test/compress')
-rw-r--r-- | test/compress/issue-1704.js | 96 | ||||
-rw-r--r-- | test/compress/issue-1733.js | 6 | ||||
-rw-r--r-- | test/compress/rename.js | 10 | ||||
-rw-r--r-- | test/compress/screw-ie8.js | 16 |
4 files changed, 110 insertions, 18 deletions
diff --git a/test/compress/issue-1704.js b/test/compress/issue-1704.js index 25e49522..043038e5 100644 --- a/test/compress/issue-1704.js +++ b/test/compress/issue-1704.js @@ -104,7 +104,7 @@ mangle_catch_toplevel: { } console.log(a); } - expect_exact: 'var o="FAIL";try{throw 1}catch(c){o="PASS"}console.log(o);' + expect_exact: 'var c="FAIL";try{throw 1}catch(o){c="PASS"}console.log(c);' expect_stdout: "PASS" } @@ -148,7 +148,7 @@ mangle_catch_var_toplevel: { } console.log(a); } - expect_exact: 'var o="FAIL";try{throw 1}catch(r){var o="PASS"}console.log(o);' + expect_exact: 'var r="FAIL";try{throw 1}catch(o){var r="PASS"}console.log(r);' expect_stdout: "PASS" } @@ -345,3 +345,95 @@ mangle_catch_redef_2_ie8_toplevel: { expect_exact: 'try{throw"FAIL1"}catch(o){var o="FAIL2"}console.log(o);' expect_stdout: "undefined" } + +mangle_catch_redef_3: { + mangle = { + ie8: false, + toplevel: false, + } + input: { + var o = "PASS"; + try { + throw 0; + } catch (o) { + (function() { + function f() { + o = "FAIL"; + } + f(), f(); + })(); + } + console.log(o); + } + expect_exact: 'var o="PASS";try{throw 0}catch(o){(function(){function c(){o="FAIL"}c(),c()})()}console.log(o);' + expect_stdout: "PASS" +} + +mangle_catch_redef_3_toplevel: { + mangle = { + ie8: false, + toplevel: true, + } + input: { + var o = "PASS"; + try { + throw 0; + } catch (o) { + (function() { + function f() { + o = "FAIL"; + } + f(), f(); + })(); + } + console.log(o); + } + expect_exact: 'var c="PASS";try{throw 0}catch(c){(function(){function o(){c="FAIL"}o(),o()})()}console.log(c);' + expect_stdout: "PASS" +} + +mangle_catch_redef_ie8_3: { + mangle = { + ie8: true, + toplevel: false, + } + input: { + var o = "PASS"; + try { + throw 0; + } catch (o) { + (function() { + function f() { + o = "FAIL"; + } + f(), f(); + })(); + } + console.log(o); + } + expect_exact: 'var o="PASS";try{throw 0}catch(o){(function(){function c(){o="FAIL"}c(),c()})()}console.log(o);' + expect_stdout: "PASS" +} + +mangle_catch_redef_3_ie8_toplevel: { + mangle = { + ie8: true, + toplevel: true, + } + input: { + var o = "PASS"; + try { + throw 0; + } catch (o) { + (function() { + function f() { + o = "FAIL"; + } + f(), f(); + })(); + } + console.log(o); + } + expect_exact: 'var c="PASS";try{throw 0}catch(c){(function(){function o(){c="FAIL"}o(),o()})()}console.log(c);' + expect_stdout: "PASS" +} diff --git a/test/compress/issue-1733.js b/test/compress/issue-1733.js index f1e576c7..15c4a899 100644 --- a/test/compress/issue-1733.js +++ b/test/compress/issue-1733.js @@ -15,7 +15,7 @@ function_iife_catch: { } f(); } - expect_exact: "function f(o){!function(){try{throw 0}catch(c){var o=1;console.log(c,o)}}()}f();" + expect_exact: "function f(o){!function(){try{throw 0}catch(o){var c=1;console.log(o,c)}}()}f();" expect_stdout: "0 1" } @@ -36,7 +36,7 @@ function_iife_catch_ie8: { } f(); } - expect_exact: "function f(o){!function(){try{throw 0}catch(o){var c=1;console.log(o,c)}}()}f();" + expect_exact: "function f(c){!function(){try{throw 0}catch(c){var o=1;console.log(c,o)}}()}f();" expect_stdout: "0 1" } @@ -61,7 +61,7 @@ function_catch_catch: { } f(); } - expect_exact: "var o=0;function f(){try{throw 1}catch(c){try{throw 2}catch(o){var o=3;console.log(o)}}console.log(o)}f();" + expect_exact: "var o=0;function f(){try{throw 1}catch(o){try{throw 2}catch(c){var c=3;console.log(c)}}console.log(c)}f();" expect_stdout: [ "3", "undefined", diff --git a/test/compress/rename.js b/test/compress/rename.js index defc6cf5..83187dff 100644 --- a/test/compress/rename.js +++ b/test/compress/rename.js @@ -109,7 +109,7 @@ mangle_catch_toplevel: { } console.log(a); } - expect_exact: 'var o="FAIL";try{throw 1}catch(c){o="PASS"}console.log(o);' + expect_exact: 'var c="FAIL";try{throw 1}catch(o){c="PASS"}console.log(c);' expect_stdout: "PASS" } @@ -155,7 +155,7 @@ mangle_catch_var_toplevel: { } console.log(a); } - expect_exact: 'var o="FAIL";try{throw 1}catch(r){var o="PASS"}console.log(o);' + expect_exact: 'var r="FAIL";try{throw 1}catch(o){var r="PASS"}console.log(r);' expect_stdout: "PASS" } @@ -451,7 +451,7 @@ function_iife_catch: { } f(); } - expect_exact: "function f(o){!function(){try{throw 0}catch(c){var o=1;console.log(c,o)}}()}f();" + expect_exact: "function f(o){!function(){try{throw 0}catch(o){var c=1;console.log(o,c)}}()}f();" expect_stdout: "0 1" } @@ -473,7 +473,7 @@ function_iife_catch_ie8: { } f(); } - expect_exact: "function f(o){!function(){try{throw 0}catch(o){var c=1;console.log(o,c)}}()}f();" + expect_exact: "function f(c){!function(){try{throw 0}catch(c){var o=1;console.log(c,o)}}()}f();" expect_stdout: "0 1" } @@ -499,7 +499,7 @@ function_catch_catch: { } f(); } - expect_exact: "var o=0;function f(){try{throw 1}catch(c){try{throw 2}catch(o){var o=3;console.log(o)}}console.log(o)}f();" + expect_exact: "var o=0;function f(){try{throw 1}catch(o){try{throw 2}catch(c){var c=3;console.log(c)}}console.log(c)}f();" expect_stdout: [ "3", "undefined", diff --git a/test/compress/screw-ie8.js b/test/compress/screw-ie8.js index 82152b7d..b4098b8e 100644 --- a/test/compress/screw-ie8.js +++ b/test/compress/screw-ie8.js @@ -102,12 +102,12 @@ dont_screw_try_catch: { }; } expect: { - bad = function(n){ - return function(t){ + bad = function(t){ + return function(n){ try{ - n() - } catch(n) { - t(n) + t() + } catch(t) { + n(t) } } }; @@ -349,11 +349,11 @@ issue_2254_1: { try { console.log(f("PASS")); } catch (e) {} - function f(e) { + function f(t) { try { throw "FAIL"; - } catch (t) { - return e; + } catch (e) { + return t; } } } |