aboutsummaryrefslogtreecommitdiff
path: root/test/compress
diff options
context:
space:
mode:
Diffstat (limited to 'test/compress')
-rw-r--r--test/compress/collapse_vars.js127
1 files changed, 121 insertions, 6 deletions
diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js
index fd421a20..1c3af6fa 100644
--- a/test/compress/collapse_vars.js
+++ b/test/compress/collapse_vars.js
@@ -2205,8 +2205,8 @@ var_defs: {
}
expect: {
var f1 = function(x, y) {
- var r = x + y, a = r * r - r, b = 7;
- console.log(a + b);
+ var r = x + y, z = r * r - r, b = 7;
+ console.log(z + b);
};
f1("1", 0);
}
@@ -2700,8 +2700,8 @@ toplevel_single_reference: {
}
expect: {
for (var b in x) {
- var a;
- b(a = b);
+ var a = b;
+ b(b);
}
}
}
@@ -4244,8 +4244,7 @@ issue_2497: {
if (true)
for (var i = 0; i < 1; ++i)
for (var k = 0; k < 1; ++k) {
- value = 1;
- value = value ? value + 1 : 0;
+ value = (value = 1) ? value + 1 : 0;
}
else
for (i = 0; i < 1; ++i)
@@ -7807,3 +7806,119 @@ issue_3744: {
}
expect_stdout: "PASS"
}
+
+assign_value_def: {
+ options = {
+ collapse_vars: true,
+ unused: true,
+ }
+ input: {
+ function f(a) {
+ while (1) {
+ var b = a[0], c = a[1];
+ d = b;
+ e = c;
+ if (c[0] - e[0] > c[1] - d[1]) break;
+ return "PASS";
+ }
+ var d, e;
+ return "FAIL";
+ }
+ console.log(f([
+ [ 1, 2 ],
+ [ 3, 4 ],
+ ]));
+ }
+ expect: {
+ function f(a) {
+ while (1) {
+ var b = a[0], c = a[1];
+ if (c[0] - c[0] > c[1] - b[1]) break;
+ return "PASS";
+ }
+ return "FAIL";
+ }
+ console.log(f([
+ [ 1, 2 ],
+ [ 3, 4 ],
+ ]));
+ }
+ expect_stdout: "PASS"
+}
+
+join_vars_value_def: {
+ options = {
+ collapse_vars: true,
+ join_vars: true,
+ unused: true,
+ }
+ input: {
+ function f(a) {
+ while (1) {
+ var b = a[0], c = a[1];
+ d = b;
+ e = c;
+ if (c[0] - e[0] > c[1] - d[1]) break;
+ return "PASS";
+ }
+ var d, e;
+ return "FAIL";
+ }
+ console.log(f([
+ [ 1, 2 ],
+ [ 3, 4 ],
+ ]));
+ }
+ expect: {
+ function f(a) {
+ while (1) {
+ var b = a[0], c = a[1];
+ if (c[0] - c[0] > c[1] - b[1]) break;
+ return "PASS";
+ }
+ return "FAIL";
+ }
+ console.log(f([
+ [ 1, 2 ],
+ [ 3, 4 ],
+ ]));
+ }
+ expect_stdout: "PASS"
+}
+
+var_value_def: {
+ options = {
+ collapse_vars: true,
+ unused: true,
+ }
+ input: {
+ function f(a) {
+ while (1) {
+ var b = a[0], c = a[1], d = b, e = c;
+ if (c[0] - e[0] > c[1] - d[1]) break;
+ return "PASS";
+ }
+ var d, e;
+ return "FAIL";
+ }
+ console.log(f([
+ [ 1, 2 ],
+ [ 3, 4 ],
+ ]));
+ }
+ expect: {
+ function f(a) {
+ while (1) {
+ var b = a[0], c = a[1];
+ if (c[0] - c[0] > c[1] - b[1]) break;
+ return "PASS";
+ }
+ return "FAIL";
+ }
+ console.log(f([
+ [ 1, 2 ],
+ [ 3, 4 ],
+ ]));
+ }
+ expect_stdout: "PASS"
+}