aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/compress/evaluate.js136
-rw-r--r--test/compress/issue-1609.js27
2 files changed, 163 insertions, 0 deletions
diff --git a/test/compress/evaluate.js b/test/compress/evaluate.js
index ea707e63..94258049 100644
--- a/test/compress/evaluate.js
+++ b/test/compress/evaluate.js
@@ -1921,3 +1921,139 @@ conditional_function: {
}
expect_stdout: "42 42"
}
+
+best_of_evaluate: {
+ options = {
+ evaluate: true,
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ function d(x, y) {
+ return x / y;
+ }
+ console.log(0 / 3, 1 / 64, 4 / 7, 7 / 7);
+ console.log(d(0, 3), d(1, 64), d(4, 7), d(7, 7));
+ }
+ expect: {
+ function d(x, y) {
+ return x / y;
+ }
+ console.log(0, 1 / 64, 4 / 7, 1);
+ console.log(0, .015625, d(4, 7), 1);
+ }
+ expect_stdout: [
+ "0 0.015625 0.5714285714285714 1",
+ "0 0.015625 0.5714285714285714 1",
+ ]
+}
+
+eager_evaluate: {
+ options = {
+ evaluate: "eager",
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ function d(x, y) {
+ return x / y;
+ }
+ console.log(0 / 3, 1 / 64, 4 / 7, 7 / 7);
+ console.log(d(0, 3), d(1, 64), d(4, 7), d(7, 7));
+ }
+ expect: {
+ console.log(0, .015625, .5714285714285714, 1);
+ console.log(0, .015625, .5714285714285714, 1);
+ }
+ expect_stdout: [
+ "0 0.015625 0.5714285714285714 1",
+ "0 0.015625 0.5714285714285714 1",
+ ]
+}
+
+threshold_evaluate_default: {
+ options = {
+ evaluate: true,
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ function b(x) {
+ return x + x + x;
+ }
+ console.log(b("1"), b(2), b(b(b("ABCDEFGHIJK"))));
+ }
+ expect: {
+ function b(x) {
+ return x + x + x;
+ }
+ console.log("111", 6, b(b(b("ABCDEFGHIJK"))));
+ }
+ expect_stdout: "111 6 ABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJK"
+}
+
+threshold_evaluate_30: {
+ options = {
+ evaluate: 30,
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ function b(x) {
+ return x + x + x;
+ }
+ console.log(b("1"), b(2), b(b(b("ABCDEFGHIJK"))));
+ }
+ expect: {
+ function b(x) {
+ return x + x + x;
+ }
+ console.log("111", 6, b(b("ABCDEFGHIJKABCDEFGHIJKABCDEFGHIJK")));
+ }
+ expect_stdout: "111 6 ABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJK"
+}
+
+threshold_evaluate_100: {
+ options = {
+ evaluate: 100,
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ function b(x) {
+ return x + x + x;
+ }
+ console.log(b("1"), b(2), b(b(b("ABCDEFGHIJK"))));
+ }
+ expect: {
+ function b(x) {
+ return x + x + x;
+ }
+ console.log("111", 6, b("ABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJK"));
+ }
+ expect_stdout: "111 6 ABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJK"
+}
+
+threshold_evaluate_999: {
+ options = {
+ evaluate: 999,
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ function b(x) {
+ return x + x + x;
+ }
+ console.log(b("1"), b(2), b(b(b("ABCDEFGHIJK"))));
+ }
+ expect: {
+ console.log("111", 6, "ABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJK");
+ }
+ expect_stdout: "111 6 ABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJK"
+}
diff --git a/test/compress/issue-1609.js b/test/compress/issue-1609.js
index d8e82263..17fbb0e7 100644
--- a/test/compress/issue-1609.js
+++ b/test/compress/issue-1609.js
@@ -52,3 +52,30 @@ chained_evaluation_2: {
})();
}
}
+
+chained_evaluation_3: {
+ options = {
+ collapse_vars: true,
+ evaluate: 10,
+ reduce_funcs: true,
+ reduce_vars: true,
+ unused: true,
+ }
+ input: {
+ (function() {
+ var a = "long piece of string";
+ (function() {
+ var b = a, c;
+ c = f(b);
+ c.bar = b;
+ })();
+ })();
+ }
+ expect: {
+ (function() {
+ (function() {
+ f("long piece of string").bar = "long piece of string";
+ })();
+ })();
+ }
+}