aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2019-11-17 11:19:42 +0800
committerGitHub <noreply@github.com>2019-11-17 11:19:42 +0800
commit8504a4ea0eddeb759f6f762f4ee46e5dde5f8e07 (patch)
tree62ae9871704fc0600b1c89323275ce809da93917 /test
parent10c1a78772c1d6ca1bc7f78f0fa1f2ab50b07ae2 (diff)
downloadtracifyjs-8504a4ea0eddeb759f6f762f4ee46e5dde5f8e07.tar.gz
tracifyjs-8504a4ea0eddeb759f6f762f4ee46e5dde5f8e07.zip
fix corner case in `reduce_funcs` (#3592)
Diffstat (limited to 'test')
-rw-r--r--test/compress/functions.js150
1 files changed, 118 insertions, 32 deletions
diff --git a/test/compress/functions.js b/test/compress/functions.js
index 6c86c1c5..297dac78 100644
--- a/test/compress/functions.js
+++ b/test/compress/functions.js
@@ -2416,7 +2416,7 @@ issue_3297_2: {
doProcessOne({
param1: param1,
param2: param2,
- }, function () {
+ }, function() {
processBulk(bulk);
});
};
@@ -2497,7 +2497,7 @@ issue_3297_3: {
doProcessOne({
param1: param1,
param2: param2,
- }, function () {
+ }, function() {
processBulk(bulk);
});
};
@@ -2514,18 +2514,21 @@ issue_3297_3: {
}).processBulk([1, 2, 3]);
}
expect: {
- function function1(u) {
+ function function1(c) {
return {
- processBulk: function n(r) {
- var o, t = u();
- r && 0 < r.length && (o = {
- param1: r.shift(),
+ processBulk: function n(o) {
+ var r, t, u = c();
+ o && 0 < o.length && (r = {
+ param1: o.shift(),
param2: {
- subparam1: t
+ subparam1: u
}
},
- console.log(JSON.stringify(o)),
- n(r));
+ t = function() {
+ n(o);
+ },
+ console.log(JSON.stringify(r)),
+ t());
}
};
}
@@ -3097,23 +3100,20 @@ issue_3400_1: {
});
}
expect: {
- void console.log(function() {
- function g() {
- function h(u) {
- var o = {
- p: u
- };
- return console.log(o[g]), o;
- }
- function e() {
- return [ 42 ].map(function(v) {
- return h(v);
- });
- }
- return e();
+ void console.log(function g() {
+ function h(u) {
+ var o = {
+ p: u
+ };
+ return console.log(o[g]), o;
}
- return g;
- }()()[0].p);
+ function e() {
+ return [ 42 ].map(function(v) {
+ return h(v);
+ });
+ }
+ return e();
+ }()[0].p);
}
expect_stdout: [
"undefined",
@@ -3154,12 +3154,10 @@ issue_3400_2: {
expect: {
void console.log(function g() {
return [ 42 ].map(function(v) {
- return function(u) {
- var o = {
- p: u
- };
- return console.log(o[g]), o;
- }(v);
+ return o = {
+ p: v
+ }, console.log(o[g]), o;
+ var o;
});
}()[0].p);
}
@@ -3401,3 +3399,91 @@ issue_3562: {
}
expect_stdout: "PASS"
}
+
+hoisted_inline: {
+ options = {
+ inline: true,
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ function f() {
+ console.log("PASS");
+ }
+ function g() {
+ for (var console in [ 0 ])
+ h();
+ }
+ function h() {
+ f();
+ }
+ g();
+ }
+ expect: {
+ function f() {
+ console.log("PASS");
+ }
+ (function() {
+ for (var console in [ 0 ])
+ void f();
+ })();
+ }
+ expect_stdout: "PASS"
+}
+
+hoisted_single_use: {
+ options = {
+ reduce_funcs: true,
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ function f(a) {
+ for (var r in a) g(r);
+ }
+ function g(a) {
+ console.log(a);
+ }
+ function h(a) {
+ var g = a.bar;
+ g();
+ g();
+ i(a);
+ }
+ function i(b) {
+ f(b);
+ }
+ h({
+ bar: function() {
+ console.log("foo");
+ }
+ });
+ }
+ expect: {
+ function f(a) {
+ for (var r in a) g(r);
+ }
+ function g(a) {
+ console.log(a);
+ }
+ (function(a) {
+ var g = a.bar;
+ g();
+ g();
+ (function(b) {
+ f(b);
+ })(a);
+ })({
+ bar: function() {
+ console.log("foo");
+ }
+ });
+ }
+ expect_stdout: [
+ "foo",
+ "foo",
+ "bar",
+ ]
+}