Add test cases for slightly more esoteric cases
authorRichard van Velzen <rvanvelzen@experty.com>
Tue, 26 Apr 2016 09:49:55 +0000 (11:49 +0200)
committerRichard van Velzen <rvanvelzen@experty.com>
Tue, 26 Apr 2016 09:49:55 +0000 (11:49 +0200)
test/compress/issue-1052.js

index bad28a8..0a77f00 100644 (file)
@@ -41,3 +41,56 @@ single_function: {
         } )();
     }
 }
+
+deeply_nested: {
+    options = { if_return: true, hoist_funs: false };
+    input: {
+        ( function() {
+            if ( !window ) {
+                return;
+            }
+
+            function f() {}
+            function g() {}
+
+            if ( !document ) {
+                return;
+            }
+
+            function h() {}
+        } )();
+    }
+    expect: {
+        ( function() {
+            function f() {}
+            function g() {}
+
+            function h() {}
+
+            // NOTE: other compression steps will reduce this
+            // down to just `window`.
+            if ( window )
+                if (document);
+        } )();
+    }
+}
+
+not_hoisted_when_already_nested: {
+    options = { if_return: true, hoist_funs: false };
+    input: {
+        ( function() {
+            if ( !window ) {
+                return;
+            }
+
+            if ( foo ) function f() {}
+
+        } )();
+    }
+    expect: {
+        ( function() {
+            if ( window )
+                if ( foo ) function f() {}
+        } )();
+    }
+}