aboutsummaryrefslogtreecommitdiff
path: root/test/compress
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2017-12-15 13:28:30 +0800
committerGitHub <noreply@github.com>2017-12-15 13:28:30 +0800
commit8f681b1d1721e931852be48720d26ba052eac96c (patch)
treefc0f3a94f03fe79107fa3db5f46bef4249ce89c1 /test/compress
parent90313875f75f68fecfc23c6c6f96f921da730301 (diff)
downloadtracifyjs-8f681b1d1721e931852be48720d26ba052eac96c.tar.gz
tracifyjs-8f681b1d1721e931852be48720d26ba052eac96c.zip
handle `inline` of function arguments (#2590)
fixes #2476
Diffstat (limited to 'test/compress')
-rw-r--r--test/compress/collapse_vars.js48
-rw-r--r--test/compress/functions.js39
-rw-r--r--test/compress/hoist_props.js8
-rw-r--r--test/compress/reduce_vars.js13
4 files changed, 65 insertions, 43 deletions
diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js
index 39d6b641..1a487981 100644
--- a/test/compress/collapse_vars.js
+++ b/test/compress/collapse_vars.js
@@ -3317,15 +3317,14 @@ issue_2436_4: {
}(o));
}
expect: {
- console.log(function(c) {
- return {
- x: c.a,
- y: c.b,
- };
- }({
+ console.log({
+ x: (c = {
a: 1,
b: 2,
- }));
+ }).a,
+ y: c.b,
+ });
+ var c;
}
expect_stdout: true
}
@@ -3448,12 +3447,11 @@ issue_2436_8: {
}(o));
}
expect: {
- console.log(function(c) {
- return {
- x: c.a,
- y: c.b,
- };
- }(o));
+ console.log({
+ x: (c = o).a,
+ y: c.b,
+ });
+ var c;
}
expect_stdout: true
}
@@ -3478,12 +3476,11 @@ issue_2436_9: {
}
expect: {
var o = console;
- console.log(function(c) {
- return {
- x: c.a,
- y: c.b,
- };
- }(o));
+ console.log({
+ x: (c = o).a,
+ y: c.b,
+ });
+ var c;
}
expect_stdout: true
}
@@ -3523,13 +3520,12 @@ issue_2436_10: {
o = { b: 3 };
return n;
}
- console.log(function(c) {
- return [
- c.a,
- f(c.b),
- c.b,
- ];
- }(o).join(" "));
+ console.log((c = o, [
+ c.a,
+ f(c.b),
+ c.b,
+ ]).join(" "));
+ var c;
}
expect_stdout: "1 2 2"
}
diff --git a/test/compress/functions.js b/test/compress/functions.js
index c4281d5c..a36509af 100644
--- a/test/compress/functions.js
+++ b/test/compress/functions.js
@@ -578,11 +578,10 @@ issue_2531_1: {
}
expect: {
function outer() {
- return function(value) {
- return function() {
- return value;
- };
- }("Hello");
+ return value = "Hello", function() {
+ return value;
+ };
+ var value;
}
console.log("Greeting:", outer()());
}
@@ -593,9 +592,10 @@ issue_2531_2: {
options = {
evaluate: true,
inline: true,
- passes: 2,
+ passes: 3,
reduce_funcs: true,
reduce_vars: true,
+ side_effects: true,
unused: true,
}
input: {
@@ -627,9 +627,10 @@ issue_2531_3: {
options = {
evaluate: true,
inline: true,
- passes: 2,
+ passes: 3,
reduce_funcs: true,
reduce_vars: true,
+ side_effects: true,
toplevel: true,
unused: true,
}
@@ -747,3 +748,27 @@ inline_loop_4: {
};
}
}
+
+issue_2476: {
+ options = {
+ inline: true,
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ function foo(x, y, z) {
+ return x < y ? x * y + z : x * z - y;
+ }
+ for (var sum = 0, i = 0; i < 10; i++)
+ sum += foo(i, i + 1, 3 * i);
+ console.log(sum);
+ }
+ expect: {
+ for (var sum = 0, i = 0; i < 10; i++)
+ sum += (x = i, y = i + 1, z = 3 * i, x < y ? x * y + z : x * z - y);
+ var x, y, z;
+ console.log(sum);
+ }
+ expect_stdout: "465"
+}
diff --git a/test/compress/hoist_props.js b/test/compress/hoist_props.js
index a46033d5..012a3fca 100644
--- a/test/compress/hoist_props.js
+++ b/test/compress/hoist_props.js
@@ -55,9 +55,8 @@ issue_2377_2: {
console.log(obj.foo, obj.cube(3));
}
expect: {
- console.log(1, function(x) {
- return x * x * x;
- }(3));
+ console.log(1, (x = 3, x * x * x));
+ var x;
}
expect_stdout: "1 27"
}
@@ -67,9 +66,10 @@ issue_2377_3: {
evaluate: true,
inline: true,
hoist_props: true,
- passes: 3,
+ passes: 4,
reduce_funcs: true,
reduce_vars: true,
+ side_effects: true,
toplevel: true,
unused: true,
}
diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js
index ff93079d..9ed9c974 100644
--- a/test/compress/reduce_vars.js
+++ b/test/compress/reduce_vars.js
@@ -1396,7 +1396,7 @@ defun_inline_3: {
options = {
evaluate: true,
inline: true,
- passes: 2,
+ passes: 3,
reduce_funcs: true,
reduce_vars: true,
side_effects: true,
@@ -2250,12 +2250,11 @@ redefine_farg_2: {
console.log(f([]), g([]), h([]));
}
expect: {
- console.log(function(a) {
- return typeof a;
- }([]), "number",function(a, b) {
+ console.log((a = [], typeof a), "number",function(a, b) {
a = b;
return typeof a;
}([]));
+ var a;
}
expect_stdout: "object number undefined"
}
@@ -2266,7 +2265,7 @@ redefine_farg_3: {
evaluate: true,
inline: true,
keep_fargs: false,
- passes: 2,
+ passes: 3,
reduce_funcs: true,
reduce_vars: true,
sequences: true,
@@ -3107,6 +3106,7 @@ obj_var_2: {
obj_arg_1: {
options = {
+ collapse_vars: true,
evaluate: true,
inline: true,
passes: 2,
@@ -3138,9 +3138,10 @@ obj_arg_1: {
obj_arg_2: {
options = {
+ collapse_vars: true,
evaluate: true,
inline: true,
- passes: 2,
+ passes: 3,
properties: true,
reduce_funcs: true,
reduce_vars: true,