aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authoralexlamsl <alexlamsl@gmail.com>2017-02-18 19:11:57 +0800
committeralexlamsl <alexlamsl@gmail.com>2017-02-21 13:29:58 +0800
commitf0ff6189be3a75cd4ccb1c38051ec27f9b30d67f (patch)
tree6586b04442f5660656ea19805b763a75d9461a80 /test
parent6b3c49e45837e8e1b32b60fe3b217b965ac16efd (diff)
downloadtracifyjs-f0ff6189be3a75cd4ccb1c38051ec27f9b30d67f.tar.gz
tracifyjs-f0ff6189be3a75cd4ccb1c38051ec27f9b30d67f.zip
clean up `negate_iife`
- remove extra tree scanning phase for `negate_iife` - `negate_iife` now only deals with the narrowest form, i.e. IIFE sitting directly under `AST_SimpleStatement` - `booleans`, `conditionals` etc. will now take care the rest via more accurate accounting - `a(); void b();` => `a(); b();` fixes #1288 closes #1451
Diffstat (limited to 'test')
-rw-r--r--test/compress/negate-iife.js148
-rw-r--r--test/compress/sequences.js38
2 files changed, 186 insertions, 0 deletions
diff --git a/test/compress/negate-iife.js b/test/compress/negate-iife.js
index 0c111604..312e0f28 100644
--- a/test/compress/negate-iife.js
+++ b/test/compress/negate-iife.js
@@ -10,6 +10,16 @@ negate_iife_1: {
}
}
+negate_iife_1_off: {
+ options = {
+ negate_iife: false,
+ };
+ input: {
+ (function(){ stuff() })();
+ }
+ expect_exact: '(function(){stuff()})();'
+}
+
negate_iife_2: {
options = {
negate_iife: true
@@ -25,6 +35,20 @@ negate_iife_2: {
negate_iife_3: {
options = {
negate_iife: true,
+ conditionals: true
+ };
+ input: {
+ (function(){ return true })() ? console.log(true) : console.log(false);
+ }
+ expect: {
+ !function(){ return true }() ? console.log(false) : console.log(true);
+ }
+}
+
+negate_iife_3_off: {
+ options = {
+ negate_iife: false,
+ conditionals: true,
};
input: {
(function(){ return true })() ? console.log(true) : console.log(false);
@@ -37,6 +61,7 @@ negate_iife_3: {
negate_iife_3: {
options = {
negate_iife: true,
+ conditionals: true,
sequences: true
};
input: {
@@ -52,6 +77,41 @@ negate_iife_3: {
}
}
+sequence_off: {
+ options = {
+ negate_iife: false,
+ conditionals: true,
+ sequences: true,
+ passes: 2,
+ };
+ input: {
+ function f() {
+ (function(){ return true })() ? console.log(true) : console.log(false);
+ (function(){
+ console.log("something");
+ })();
+ }
+ function g() {
+ (function(){
+ console.log("something");
+ })();
+ (function(){ return true })() ? console.log(true) : console.log(false);
+ }
+ }
+ expect: {
+ function f() {
+ !function(){ return true }() ? console.log(false) : console.log(true), function(){
+ console.log("something");
+ }();
+ }
+ function g() {
+ (function(){
+ console.log("something");
+ })(), function(){ return true }() ? console.log(true) : console.log(false);
+ }
+ }
+}
+
negate_iife_4: {
options = {
negate_iife: true,
@@ -75,6 +135,29 @@ negate_iife_4: {
}
}
+negate_iife_4_off: {
+ options = {
+ negate_iife: false,
+ sequences: true,
+ conditionals: true,
+ };
+ input: {
+ if ((function(){ return true })()) {
+ foo(true);
+ } else {
+ bar(false);
+ }
+ (function(){
+ console.log("something");
+ })();
+ }
+ expect: {
+ !function(){ return true }() ? bar(false) : foo(true), function(){
+ console.log("something");
+ }();
+ }
+}
+
negate_iife_nested: {
options = {
negate_iife: true,
@@ -107,6 +190,38 @@ negate_iife_nested: {
}
}
+negate_iife_nested_off: {
+ options = {
+ negate_iife: false,
+ sequences: true,
+ conditionals: true,
+ };
+ input: {
+ function Foo(f) {
+ this.f = f;
+ }
+ new Foo(function() {
+ (function(x) {
+ (function(y) {
+ console.log(y);
+ })(x);
+ })(7);
+ }).f();
+ }
+ expect: {
+ function Foo(f) {
+ this.f = f;
+ }
+ new Foo(function() {
+ (function(x) {
+ (function(y) {
+ console.log(y);
+ })(x);
+ })(7);
+ }).f();
+ }
+}
+
negate_iife_issue_1073: {
options = {
negate_iife: true,
@@ -172,3 +287,36 @@ issue_1254_negate_iife_nested: {
}
expect_exact: '!function(){return function(){console.log("test")}}()()()()();'
}
+
+issue_1288: {
+ options = {
+ negate_iife: true,
+ conditionals: true,
+ };
+ input: {
+ if (w) ;
+ else {
+ (function f() {})();
+ }
+ if (!x) {
+ (function() {
+ x = {};
+ })();
+ }
+ if (y)
+ (function() {})();
+ else
+ (function(z) {
+ return z;
+ })(0);
+ }
+ expect: {
+ w || function f() {}();
+ x || function() {
+ x = {};
+ }();
+ y ? function() {}() : function(z) {
+ return z;
+ }(0);
+ }
+}
diff --git a/test/compress/sequences.js b/test/compress/sequences.js
index 8a3ffe89..d93f5237 100644
--- a/test/compress/sequences.js
+++ b/test/compress/sequences.js
@@ -213,3 +213,41 @@ limit_2: {
i, j, k;
}
}
+
+negate_iife_for: {
+ options = {
+ sequences: true,
+ negate_iife: true,
+ };
+ input: {
+ (function() {})();
+ for (i = 0; i < 5; i++) console.log(i);
+
+ (function() {})();
+ for (; i < 5; i++) console.log(i);
+ }
+ expect: {
+ for (!function() {}(), i = 0; i < 5; i++) console.log(i);
+ for (function() {}(); i < 5; i++) console.log(i);
+ }
+}
+
+iife: {
+ options = {
+ sequences: true,
+ };
+ input: {
+ x = 42;
+ (function a() {})();
+ !function b() {}();
+ ~function c() {}();
+ +function d() {}();
+ -function e() {}();
+ void function f() {}();
+ typeof function g() {}();
+ }
+ expect: {
+ x = 42, function a() {}(), function b() {}(), function c() {}(),
+ function d() {}(), function e() {}(), function f() {}(), function g() {}()
+ }
+}