aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/compress/collapse_vars.js26
-rw-r--r--test/compress/drop-unused.js64
-rw-r--r--test/compress/evaluate.js12
-rw-r--r--test/compress/functions.js1
-rw-r--r--test/compress/keep_fargs.js2
-rw-r--r--test/compress/reduce_vars.js47
6 files changed, 98 insertions, 54 deletions
diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js
index 6244e03f..546e0d3b 100644
--- a/test/compress/collapse_vars.js
+++ b/test/compress/collapse_vars.js
@@ -3001,8 +3001,6 @@ issue_2298: {
expect: {
!function() {
(function() {
- var a = undefined;
- var undefined = a++;
try {
!function(b) {
(void 0)[1] = "foo";
@@ -3836,20 +3834,19 @@ issue_2436_3: {
}(o));
}
expect: {
- var o = {
- a: 1,
- b: 2,
- };
console.log(function(c) {
- o = {
+ ({
a: 3,
b: 4,
- };
+ });
return {
x: c.a,
y: c.b,
};
- }(o));
+ }({
+ a: 1,
+ b: 2,
+ }));
}
expect_stdout: true
}
@@ -4071,16 +4068,15 @@ issue_2436_10: {
}(o).join(" "));
}
expect: {
- var o = {
- a: 1,
- b: 2,
- };
function f(n) {
- o = { b: 3 };
+ ({ b: 3 });
return n;
}
console.log([
- (c = o).a,
+ (c = {
+ a: 1,
+ b: 2,
+ }).a,
f(c.b),
c.b,
].join(" "));
diff --git a/test/compress/drop-unused.js b/test/compress/drop-unused.js
index e3166970..b21ca399 100644
--- a/test/compress/drop-unused.js
+++ b/test/compress/drop-unused.js
@@ -1729,7 +1729,7 @@ chained_3: {
}
expect: {
console.log(function(a, b) {
- var c = b;
+ var c = 2;
b++;
return c;
}(0, 2));
@@ -2557,7 +2557,7 @@ issue_3899: {
console.log(typeof a);
}
expect: {
- ++a;
+ 0;
var a = function() {
return 2;
};
@@ -2565,3 +2565,63 @@ issue_3899: {
}
expect_stdout: "function"
}
+
+cross_scope_assign_chain: {
+ options = {
+ reduce_vars: true,
+ side_effects: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ var a, b = 0;
+ (function() {
+ a = b;
+ a++;
+ while (b++);
+ })();
+ console.log(a ? "PASS" : "FAIL");
+ }
+ expect: {
+ var a, b = 0;
+ (function() {
+ a = b;
+ a++;
+ while (b++);
+ })();
+ console.log(a ? "PASS" : "FAIL");
+ }
+ expect_stdout: "PASS"
+}
+
+assign_if_assign_read: {
+ options = {
+ reduce_vars: true,
+ unused: true,
+ }
+ input: {
+ (function(a) {
+ var b;
+ do {
+ b = "FAIL";
+ if (Array.isArray(a)) {
+ b = a[0];
+ console.log(b);
+ }
+ } while (!console);
+ })([ "PASS" ]);
+ }
+ expect: {
+ (function(a) {
+ var b;
+ do {
+ "FAIL";
+ if (Array.isArray(a)) {
+ b = a[0];
+ console.log(b);
+ }
+ } while (!console);
+ })([ "PASS" ]);
+ }
+ expect_stdout: "PASS"
+}
diff --git a/test/compress/evaluate.js b/test/compress/evaluate.js
index 0cf1d892..6deabafa 100644
--- a/test/compress/evaluate.js
+++ b/test/compress/evaluate.js
@@ -2412,9 +2412,9 @@ issue_3887: {
expect: {
(function(b) {
try {
- b-- && console.log("PASS");
+ 1, console.log("PASS");
} catch (a_2) {}
- })(1);
+ })();
}
expect_stdout: "PASS"
}
@@ -2478,10 +2478,10 @@ issue_3920: {
console.log(a);
}
expect: {
- var a = function(b) {
- return (b[b = 0] = 0) >= (b ? 0 : 1);
- }("foo");
- console.log(a);
+ (function(b) {
+ "foo"[0] = 0;
+ })();
+ console.log(false);
}
expect_stdout: "false"
}
diff --git a/test/compress/functions.js b/test/compress/functions.js
index 9607c593..1383dbe9 100644
--- a/test/compress/functions.js
+++ b/test/compress/functions.js
@@ -2336,6 +2336,7 @@ issue_3274: {
inline: true,
join_vars: true,
loops: true,
+ passes: 2,
reduce_vars: true,
unused: true,
}
diff --git a/test/compress/keep_fargs.js b/test/compress/keep_fargs.js
index c2a4ceef..e1737081 100644
--- a/test/compress/keep_fargs.js
+++ b/test/compress/keep_fargs.js
@@ -306,8 +306,6 @@ issue_2298: {
expect: {
!function() {
(function() {
- var a = undefined;
- var undefined = a++;
try {
!function() {
(void 0)[1] = "foo";
diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js
index 9168e81b..cb7599a9 100644
--- a/test/compress/reduce_vars.js
+++ b/test/compress/reduce_vars.js
@@ -905,7 +905,7 @@ use_before_var: {
}
expect: {
function f(){
- console.log(t);
+ console.log(void 0);
var t = 1;
}
}
@@ -981,12 +981,12 @@ inner_var_for_1: {
expect: {
function f() {
var a = 1;
- x(1, b, d);
- for (var b = 2, c = 3; x(1, b, 3, d); x(1, b, 3, d)) {
+ x(1, void 0, d);
+ for (var b = 2, c = 3; x(1, 2, 3, d); x(1, 2, 3, d)) {
var d = 4, e = 5;
- x(1, b, 3, d, e);
+ x(1, 2, 3, d, e);
}
- x(1, b, 3, d, e);
+ x(1, 2, 3, d, e);
}
}
}
@@ -1521,9 +1521,7 @@ func_inline: {
expect: {
function f() {
console.log(1 + h());
- var h = function() {
- return 2;
- };
+ var h;
}
}
}
@@ -2372,8 +2370,7 @@ delay_def: {
return;
}
function g() {
- return a;
- var a = 1;
+ return;
}
console.log(f(), g());
}
@@ -2395,7 +2392,7 @@ delay_def_lhs: {
expect: {
console.log(function() {
long_name++;
- return long_name;
+ return NaN;
var long_name;
}());
}
@@ -2651,11 +2648,9 @@ var_assign_5: {
}
expect: {
!function() {
- var a;
!function(b) {
- a = 2,
- console.log(a, b);
- }(a);
+ console.log(2, void 0);
+ }();
}();
}
expect_stdout: "2 undefined"
@@ -4725,7 +4720,7 @@ escape_conditional: {
function bar() {}
(function() {
var thing = baz();
- if (thing !== (thing = baz()))
+ if (thing !== baz())
console.log("FAIL");
else
console.log("PASS");
@@ -4763,7 +4758,7 @@ escape_sequence: {
function bar() {}
(function() {
var thing = baz();
- if (thing !== (thing = baz()))
+ if (thing !== baz())
console.log("FAIL");
else
console.log("PASS");
@@ -4808,7 +4803,7 @@ escape_throw: {
function foo() {}
(function() {
var thing = baz();
- if (thing !== (thing = baz()))
+ if (thing !== baz())
console.log("FAIL");
else
console.log("PASS");
@@ -4845,7 +4840,7 @@ escape_local_conditional: {
}
(function() {
var thing = baz();
- if (thing !== (thing = baz()))
+ if (thing !== baz())
console.log("PASS");
else
console.log("FAIL");
@@ -4882,7 +4877,7 @@ escape_local_sequence: {
}
(function() {
var thing = baz();
- if (thing !== (thing = baz()))
+ if (thing !== baz())
console.log("PASS");
else
console.log("FAIL");
@@ -4926,7 +4921,7 @@ escape_local_throw: {
}
(function() {
var thing = baz();
- if (thing !== (thing = baz()))
+ if (thing !== baz())
console.log("PASS");
else
console.log("FAIL");
@@ -4980,11 +4975,7 @@ inverted_var: {
console.log(1, 2, 3, 4, 5, function c() {
c = 6;
return c;
- }(), 7, function() {
- c = 8;
- return c;
- var c = "foo";
- }());
+ }(), 7, 8);
}
expect_stdout: true
}
@@ -5180,9 +5171,7 @@ defun_var_3: {
var a = 42, b;
}
expect: {
- function a() {}
- console.log(typeof a, "function");
- var a = 42;
+ console.log("function", "function");
}
expect_stdout: "function function"
}