aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/test_other.py13
-rw-r--r--tools/js-optimizer.js6
2 files changed, 17 insertions, 2 deletions
diff --git a/tests/test_other.py b/tests/test_other.py
index 19d1790d..ded45112 100644
--- a/tests/test_other.py
+++ b/tests/test_other.py
@@ -2652,3 +2652,16 @@ int main()
}
''', [3, 1, 1])
+ test(r'''
+ #include <stdio.h>
+ #include <stdlib.h>
+
+ int main(int argc, char *argv[]) {
+ if (getenv("A") || getenv("B")) {
+ printf("hello world\n");
+ }
+ printf("and that's that\n");
+ return 0;
+ }
+ ''', [3, 1, 1])
+
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js
index 88bcf503..129c493f 100644
--- a/tools/js-optimizer.js
+++ b/tools/js-optimizer.js
@@ -861,16 +861,18 @@ function simplifyIfs(ast) {
node[1] = flipCondition(node[1]);
node[2] = node[3];
node[3] = body;
+ body = node[2];
} else break;
} else break;
}
// we can handle elses, but must be fully identical
if (node[3] || other[3]) {
- if (!node[3] || !other[3]) break;
+ if (!node[3]) break;
if (!astCompare(node[3], other[3])) {
// the elses are different, but perhaps if we flipped a condition we can do better
if (astCompare(node[3], other[2])) {
- // flip other
+ // flip other. note that other may not have had an else! add one if so; we will eliminate such things later
+ if (!other[3]) other[3] = ['block', []];
other[1] = flipCondition(other[1]);
var temp = other[2];
other[2] = other[3];