diff options
author | Mihai Bazon <mihai@bazon.net> | 2013-12-29 10:31:30 +0200 |
---|---|---|
committer | Mihai Bazon <mihai@bazon.net> | 2013-12-29 10:31:30 +0200 |
commit | b521b4b926f7a385ed14ec07bc4b5dad9ebcd93b (patch) | |
tree | 5a1a75c0b9efb50a87cb6c6e4919911bd81db064 /test/compress | |
parent | aa9de76370ee83883f19a6d410ad8207d0fe1769 (diff) | |
download | tracifyjs-b521b4b926f7a385ed14ec07bc4b5dad9ebcd93b.tar.gz tracifyjs-b521b4b926f7a385ed14ec07bc4b5dad9ebcd93b.zip |
Conditional/call optimization
foo ? bar(x) : bar(y) ==> bar(foo ? x : y)
Diffstat (limited to 'test/compress')
-rw-r--r-- | test/compress/conditionals.js | 64 | ||||
-rw-r--r-- | test/compress/negate-iife.js | 6 |
2 files changed, 67 insertions, 3 deletions
diff --git a/test/compress/conditionals.js b/test/compress/conditionals.js index dc2bb671..9ef30ac1 100644 --- a/test/compress/conditionals.js +++ b/test/compress/conditionals.js @@ -141,3 +141,67 @@ ifs_6: { x = foo || bar || baz || boo ? 20 : 10; } } + +cond_1: { + options = { + conditionals: true + }; + input: { + if (some_condition()) { + do_something(x); + } else { + do_something(y); + } + } + expect: { + do_something(some_condition() ? x : y); + } +} + +cond_2: { + options = { + conditionals: true + }; + input: { + if (some_condition()) { + x = new FooBar(1); + } else { + x = new FooBar(2); + } + } + expect: { + x = new FooBar(some_condition() ? 1 : 2); + } +} + +cond_3: { + options = { + conditionals: true + }; + input: { + if (some_condition()) { + new FooBar(1); + } else { + FooBar(2); + } + } + expect: { + some_condition() ? new FooBar(1) : FooBar(2); + } +} + +cond_4: { + options = { + conditionals: true + }; + input: { + if (some_condition()) { + do_something(); + } else { + do_something(); + } + } + expect: { + some_condition(), do_something(); + } +} diff --git a/test/compress/negate-iife.js b/test/compress/negate-iife.js index 0362ffce..89c3f064 100644 --- a/test/compress/negate-iife.js +++ b/test/compress/negate-iife.js @@ -60,16 +60,16 @@ negate_iife_4: { }; input: { if ((function(){ return true })()) { - console.log(true); + foo(true); } else { - console.log(false); + bar(false); } (function(){ console.log("something"); })(); } expect: { - !function(){ return true }() ? console.log(false) : console.log(true), function(){ + !function(){ return true }() ? bar(false) : foo(true), function(){ console.log("something"); }(); } |