aboutsummaryrefslogtreecommitdiff
path: root/test/compress
diff options
context:
space:
mode:
authorTal Ater <tal@talater.com>2014-09-02 23:30:25 +0300
committerTal Ater <tal@talater.com>2014-09-02 23:30:25 +0300
commit885835a655b4c1b3a0a9cb0f78edaa6ac446a0e7 (patch)
tree3d29a96ef884f7368c040f9453b2346f3de01435 /test/compress
parent4c64554808e0805b86893704dc87df9ec449961a (diff)
downloadtracifyjs-885835a655b4c1b3a0a9cb0f78edaa6ac446a0e7.tar.gz
tracifyjs-885835a655b4c1b3a0a9cb0f78edaa6ac446a0e7.zip
Compress conditional assignments where all possible outcomes are equivalant and condition has no side effects
Diffstat (limited to 'test/compress')
-rw-r--r--test/compress/conditionals.js44
1 files changed, 44 insertions, 0 deletions
diff --git a/test/compress/conditionals.js b/test/compress/conditionals.js
index 213b246b..b0234031 100644
--- a/test/compress/conditionals.js
+++ b/test/compress/conditionals.js
@@ -232,3 +232,47 @@ 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;
+ }
+
+ x = y ? 'foo' : 'fo'+'o';
+
+ x = y ? 'foo' : y ? 'foo' : 'fo'+'o';
+
+ // don't compress these
+ x = y ? a : b;
+
+ x = y ? 'foo' : 'fo';
+
+ // make sure not to mess with conditions that have side effects
+ // TODO: Make sure to mess with conditions that have side effects... proprely
+ if (some_condition()) {
+ x = 1+1;
+ } else {
+ x = 2;
+ }
+
+ x = some_condition() ? 'foo' : 'fo'+'o';
+ }
+ expect: {
+ x = 2;
+ x = 'foo';
+ x = 'foo';
+ x = y ? a : b;
+ x = y ? 'foo' : 'fo';
+ x = some_condition() ? 2 : 2;
+ x = some_condition() ? 'foo' : 'foo';
+ }
+}
+