aboutsummaryrefslogtreecommitdiff
path: root/test/compress
diff options
context:
space:
mode:
authorkzc <zaxxon2011@gmail.com>2016-02-21 12:05:02 -0500
committerkzc <zaxxon2011@gmail.com>2016-02-21 12:05:02 -0500
commit5486b68850f8da3fbcdef228a88ff494c33bac4a (patch)
treec7d7ac7e93603820166c4e19c6fc97f1d94e890d /test/compress
parentbdd8e34f635db60765f1fd5c8b5355e71ee16095 (diff)
downloadtracifyjs-5486b68850f8da3fbcdef228a88ff494c33bac4a.tar.gz
tracifyjs-5486b68850f8da3fbcdef228a88ff494c33bac4a.zip
Take operator || precendence into account for AST_If optimization.
Fixes #979.
Diffstat (limited to 'test/compress')
-rw-r--r--test/compress/issue-979.js89
1 files changed, 89 insertions, 0 deletions
diff --git a/test/compress/issue-979.js b/test/compress/issue-979.js
new file mode 100644
index 00000000..bae15db8
--- /dev/null
+++ b/test/compress/issue-979.js
@@ -0,0 +1,89 @@
+issue979_reported: {
+ options = {
+ sequences:true, properties:true, dead_code:true, conditionals:true,
+ comparisons:true, evaluate:true, booleans:true, loops:true, unused:true, hoist_funs:true,
+ keep_fargs:true, if_return:true, join_vars:true, cascade:true, side_effects:true
+ }
+ input: {
+ function f1() {
+ if (a == 1 || b == 2) {
+ foo();
+ }
+ }
+ function f2() {
+ if (!(a == 1 || b == 2)) {
+ }
+ else {
+ foo();
+ }
+ }
+ }
+ expect: {
+ function f1() {
+ 1!=a&&2!=b||foo();
+ }
+ function f2() {
+ 1!=a&&2!=b||foo();
+ }
+ }
+}
+
+issue979_test_negated_is_best: {
+ options = {
+ sequences:true, properties:true, dead_code:true, conditionals:true,
+ comparisons:true, evaluate:true, booleans:true, loops:true, unused:true, hoist_funs:true,
+ keep_fargs:true, if_return:true, join_vars:true, cascade:true, side_effects:true
+ }
+ input: {
+ function f3() {
+ if (a == 1 | b == 2) {
+ foo();
+ }
+ }
+ function f4() {
+ if (!(a == 1 | b == 2)) {
+ }
+ else {
+ foo();
+ }
+ }
+ function f5() {
+ if (a == 1 && b == 2) {
+ foo();
+ }
+ }
+ function f6() {
+ if (!(a == 1 && b == 2)) {
+ }
+ else {
+ foo();
+ }
+ }
+ function f7() {
+ if (a == 1 || b == 2) {
+ foo();
+ }
+ else {
+ return bar();
+ }
+ }
+ }
+ expect: {
+ function f3() {
+ 1==a|2==b&&foo();
+ }
+ function f4() {
+ 1==a|2==b&&foo();
+ }
+ function f5() {
+ 1==a&&2==b&&foo();
+ }
+ function f6() {
+ 1!=a||2!=b||foo();
+ }
+ function f7() {
+ return 1!=a&&2!=b?bar():void foo();
+ }
+ }
+}
+