diff options
author | Mihai Bazon <mihai.bazon@gmail.com> | 2013-08-20 17:45:52 +0300 |
---|---|---|
committer | Mihai Bazon <mihai.bazon@gmail.com> | 2013-08-20 17:45:52 +0300 |
commit | ed80b4a534083510082419b305e0b60b395b10c6 (patch) | |
tree | 9a264d89beb4304dfcbdae48572cf4d7e142154e /test/compress | |
parent | 4f09df238e15bfb9d03d28ba718c402bad0b1078 (diff) | |
download | tracifyjs-ed80b4a534083510082419b305e0b60b395b10c6.tar.gz tracifyjs-ed80b4a534083510082419b305e0b60b395b10c6.zip |
Move support for `negate_iife` in the compressor, rather than code generator
(the code generator doesn't maintain enough context to know whether
the return value is important or discarded)
Fixes #272
Diffstat (limited to 'test/compress')
-rw-r--r-- | test/compress/negate-iife.js | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/test/compress/negate-iife.js b/test/compress/negate-iife.js new file mode 100644 index 00000000..0362ffce --- /dev/null +++ b/test/compress/negate-iife.js @@ -0,0 +1,76 @@ +negate_iife_1: { + options = { + negate_iife: true + }; + input: { + (function(){ stuff() })(); + } + expect: { + !function(){ stuff() }(); + } +} + +negate_iife_2: { + options = { + negate_iife: true + }; + input: { + (function(){ return {} })().x = 10; // should not transform this one + } + expect: { + (function(){ return {} })().x = 10; + } +} + +negate_iife_3: { + options = { + negate_iife: true, + }; + input: { + (function(){ return true })() ? console.log(true) : console.log(false); + } + expect: { + !function(){ return true }() ? console.log(false) : console.log(true); + } +} + +negate_iife_3: { + options = { + negate_iife: true, + sequences: true + }; + input: { + (function(){ return true })() ? console.log(true) : console.log(false); + (function(){ + console.log("something"); + })(); + } + expect: { + !function(){ return true }() ? console.log(false) : console.log(true), function(){ + console.log("something"); + }(); + } +} + +negate_iife_4: { + options = { + negate_iife: true, + sequences: true, + conditionals: true, + }; + input: { + if ((function(){ return true })()) { + console.log(true); + } else { + console.log(false); + } + (function(){ + console.log("something"); + })(); + } + expect: { + !function(){ return true }() ? console.log(false) : console.log(true), function(){ + console.log("something"); + }(); + } +} |