aboutsummaryrefslogtreecommitdiff
path: root/test/compress/collapse_vars.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2019-11-28 03:57:10 +0800
committerGitHub <noreply@github.com>2019-11-28 03:57:10 +0800
commit168ae747ad8c8c48a0318eaaffd25e084521fb60 (patch)
tree5462f8183e3079c1de8aee7d5c09376d9fa522e8 /test/compress/collapse_vars.js
parentd4b701067805f5041c3b27225742a7b36c3db90c (diff)
downloadtracifyjs-168ae747ad8c8c48a0318eaaffd25e084521fb60.tar.gz
tracifyjs-168ae747ad8c8c48a0318eaaffd25e084521fb60.zip
enhance `collapse_vars` (#3611)
Diffstat (limited to 'test/compress/collapse_vars.js')
-rw-r--r--test/compress/collapse_vars.js187
1 files changed, 184 insertions, 3 deletions
diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js
index 0f1e59a3..175ab9c2 100644
--- a/test/compress/collapse_vars.js
+++ b/test/compress/collapse_vars.js
@@ -669,7 +669,7 @@ collapse_vars_throw: {
expect_stdout: "13"
}
-collapse_vars_switch: {
+collapse_vars_switch_1: {
options = {
booleans: true,
collapse_vars: true,
@@ -721,6 +721,31 @@ collapse_vars_switch: {
}
}
+collapse_vars_switch_2: {
+ options = {
+ collapse_vars: true,
+ }
+ input: {
+ var c = 0;
+ (function(b) {
+ switch (b && [ b = 0, (c++, 0) ]) {
+ case c = 1 + c:
+ }
+ })();
+ console.log(c);
+ }
+ expect: {
+ var c = 0;
+ (function(b) {
+ switch (b && [ b = 0, (c++, 0) ]) {
+ case c = 1 + c:
+ }
+ })();
+ console.log(c);
+ }
+ expect_stdout: "1"
+}
+
collapse_vars_assignment: {
options = {
booleans: true,
@@ -1234,7 +1259,7 @@ collapse_vars_try: {
}
}
-collapse_vars_array: {
+collapse_vars_array_1: {
options = {
booleans: true,
collapse_vars: true,
@@ -1280,7 +1305,58 @@ collapse_vars_array: {
}
}
-collapse_vars_object: {
+collapse_vars_array_2: {
+ options = {
+ collapse_vars: true,
+ unused: true,
+ }
+ input: {
+ function f(a) {
+ var b;
+ return [ (b = a, b.g()) ];
+ }
+ console.log(f({
+ g: function() {
+ return "PASS";
+ }
+ })[0]);
+ }
+ expect: {
+ function f(a) {
+ return [ a.g() ];
+ }
+ console.log(f({
+ g: function() {
+ return "PASS";
+ }
+ })[0]);
+ }
+ expect_stdout: "PASS"
+}
+
+collapse_vars_array_3: {
+ options = {
+ collapse_vars: true,
+ unused: true,
+ }
+ input: {
+ function f(a) {
+ var b;
+ return [ b = a, b, b ];
+ }
+ console.log(f().length);
+ }
+ expect: {
+ function f(a) {
+ var b;
+ return [ b = a, b, b ];
+ }
+ console.log(f().length);
+ }
+ expect_stdout: "3"
+}
+
+collapse_vars_object_1: {
options = {
booleans: true,
collapse_vars: true,
@@ -1360,6 +1436,69 @@ collapse_vars_object: {
}
}
+collapse_vars_object_2: {
+ options = {
+ collapse_vars: true,
+ unused: true,
+ }
+ input: {
+ function f(a) {
+ var b;
+ return {
+ p: (b = a, b.g())
+ };
+ }
+ console.log(f({
+ g: function() {
+ return "PASS";
+ }
+ }).p);
+ }
+ expect: {
+ function f(a) {
+ return {
+ p: a.g()
+ };
+ }
+ console.log(f({
+ g: function() {
+ return "PASS";
+ }
+ }).p);
+ }
+ expect_stdout: "PASS"
+}
+
+collapse_vars_object_3: {
+ options = {
+ collapse_vars: true,
+ unused: true,
+ }
+ input: {
+ function f(a) {
+ var b;
+ return {
+ p: b = a,
+ q: b,
+ r: b,
+ };
+ }
+ console.log(f("PASS").r);
+ }
+ expect: {
+ function f(a) {
+ var b;
+ return {
+ p: b = a,
+ q: b,
+ r: b,
+ };
+ }
+ console.log(f("PASS").r);
+ }
+ expect_stdout: "PASS"
+}
+
collapse_vars_eval_and_with: {
options = {
booleans: true,
@@ -6624,3 +6763,45 @@ local_value_replacement: {
}
expect_stdout: "PASS"
}
+
+array_in_object_1: {
+ options = {
+ collapse_vars: true,
+ }
+ input: {
+ var a = 2;
+ console.log({
+ p: [ a, a-- ],
+ q: a,
+ }.q, a);
+ }
+ expect: {
+ var a = 2;
+ console.log({
+ p: [ a, a-- ],
+ q: a,
+ }.q, a);
+ }
+ expect_stdout: "1 1"
+}
+
+array_in_object_2: {
+ options = {
+ collapse_vars: true,
+ }
+ input: {
+ var a = 2;
+ console.log({
+ p: [ a, (a--, 42) ],
+ q: a,
+ }.q, a);
+ }
+ expect: {
+ var a = 2;
+ console.log({
+ p: [ a, 42 ],
+ q: --a,
+ }.q, a);
+ }
+ expect_stdout: "1 1"
+}