aboutsummaryrefslogtreecommitdiff
path: root/test/compress/reduce_vars.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2017-11-08 03:28:46 +0800
committerGitHub <noreply@github.com>2017-11-08 03:28:46 +0800
commit4c0b0177b6fa556c31f0099c6d52a4ad4f670ba3 (patch)
tree708f43dcb264d0cab353bbeb2144bcbfb667f20d /test/compress/reduce_vars.js
parent38bfb73f0643d73d429d7a79667f6b8fa3fd6fc5 (diff)
downloadtracifyjs-4c0b0177b6fa556c31f0099c6d52a4ad4f670ba3.tar.gz
tracifyjs-4c0b0177b6fa556c31f0099c6d52a4ad4f670ba3.zip
preserve function identity in `reduce_vars` (#2451)
fixes #2450
Diffstat (limited to 'test/compress/reduce_vars.js')
-rw-r--r--test/compress/reduce_vars.js154
1 files changed, 149 insertions, 5 deletions
diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js
index f1a27ff9..8afea850 100644
--- a/test/compress/reduce_vars.js
+++ b/test/compress/reduce_vars.js
@@ -1123,11 +1123,12 @@ toplevel_on_loops_1: {
while (x);
}
expect: {
+ function bar() {
+ console.log("bar:", --x);
+ }
var x = 3;
do
- (function() {
- console.log("bar:", --x);
- })();
+ bar();
while (x);
}
expect_stdout: true
@@ -1180,9 +1181,10 @@ toplevel_on_loops_2: {
while (x);
}
expect: {
- for (;;) (function() {
+ function bar() {
console.log("bar:");
- })();
+ }
+ for (;;) bar();
}
}
@@ -3845,3 +3847,145 @@ recursive_inlining_5: {
"foo 0",
]
}
+
+issue_2450_1: {
+ options = {
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ function f() {}
+ function g() {
+ return f;
+ }
+ console.log(g() === g());
+ }
+ expect: {
+ function f() {}
+ function g() {
+ return f;
+ }
+ console.log(g() === g());
+ }
+ expect_stdout: "true"
+}
+
+issue_2450_2: {
+ options = {
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ function g() {
+ function f() {}
+ return f;
+ }
+ console.log(g() === g());
+ }
+ expect: {
+ function g() {
+ return function() {};
+ }
+ console.log(g() === g());
+ }
+ expect_stdout: "false"
+}
+
+issue_2450_3: {
+ options = {
+ reduce_vars: true,
+ unused: true,
+ }
+ input: {
+ var x = (function() {
+ function test() {
+ return "foo";
+ }
+ return function b() {
+ return [1, test];
+ }
+ })();
+ console.log(x()[1] === x()[1]);
+ }
+ expect: {
+ var x = (function() {
+ function test() {
+ return "foo";
+ }
+ return function() {
+ return [1, test];
+ }
+ })();
+ console.log(x()[1] === x()[1]);
+ }
+ expect_stdout: "true"
+}
+
+issue_2450_4: {
+ options = {
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ var a;
+ function f(b) {
+ console.log(a === b);
+ a = b;
+ }
+ function g() {}
+ for (var i = 3; --i >= 0;)
+ f(g);
+ }
+ expect: {
+ var a;
+ function f(b) {
+ console.log(a === b);
+ a = b;
+ }
+ function g() {}
+ for (var i = 3; --i >= 0;)
+ f(g);
+ }
+ expect_stdout: [
+ "false",
+ "true",
+ "true",
+ ]
+}
+
+issue_2450_5: {
+ options = {
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ var a;
+ function f(b) {
+ console.log(a === b);
+ a = b;
+ }
+ function g() {}
+ [1, 2, 3].forEach(function() {
+ f(g);
+ });
+ }
+ expect: {
+ var a;
+ function g() {}
+ [1, 2, 3].forEach(function() {
+ (function(b) {
+ console.log(a === b);
+ a = b;
+ })(g);
+ });
+ }
+ expect_stdout: [
+ "false",
+ "true",
+ "true",
+ ]
+}