diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/compress/conditionals.js | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/test/compress/conditionals.js b/test/compress/conditionals.js index 213b246b..c20297aa 100644 --- a/test/compress/conditionals.js +++ b/test/compress/conditionals.js @@ -232,3 +232,64 @@ cond_5: { some_condition() && some_other_condition() && do_something(); } } + +cond_7: { + options = { + conditionals: true, + evaluate : true + }; + input: { + // compress these + if (y) { + x = 1+1; + } else { + x = 2; + } + + if (y) { + x = 1+1; + } else if (z) { + x = 2; + } else { + x = 3-1; + } + + x = y ? 'foo' : 'fo'+'o'; + + x = y ? 'foo' : y ? 'foo' : 'fo'+'o'; + + // Compress conditions that have side effects + if (condition()) { + x = 10+10; + } else { + x = 20; + } + + if (z) { + x = 'fuji'; + } else if (condition()) { + x = 'fu'+'ji'; + } else { + x = 'fuji'; + } + + x = condition() ? 'foobar' : 'foo'+'bar'; + + // don't compress these + x = y ? a : b; + + x = y ? 'foo' : 'fo'; + } + expect: { + x = 2; + x = 2; + x = 'foo'; + x = 'foo'; + x = (condition(), 20); + x = z ? 'fuji' : (condition(), 'fuji'); + x = (condition(), 'foobar'); + x = y ? a : b; + x = y ? 'foo' : 'fo'; + } +} + |