aboutsummaryrefslogtreecommitdiff
path: root/test/compress/reduce_vars.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2017-11-07 02:37:23 +0800
committerGitHub <noreply@github.com>2017-11-07 02:37:23 +0800
commitbbedbf4ea03580c5b7aa39f32b92fdda9216c5b4 (patch)
tree8d2313be98b975b0b96ca36be869c172c3303599 /test/compress/reduce_vars.js
parent2cfb5aa7dadd744bf7fbe16756696fc595f134a2 (diff)
downloadtracifyjs-bbedbf4ea03580c5b7aa39f32b92fdda9216c5b4.tar.gz
tracifyjs-bbedbf4ea03580c5b7aa39f32b92fdda9216c5b4.zip
handle circular `function` reference gracefully (#2446)
fixes #2442
Diffstat (limited to 'test/compress/reduce_vars.js')
-rw-r--r--test/compress/reduce_vars.js191
1 files changed, 191 insertions, 0 deletions
diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js
index 25f95ff8..f1a27ff9 100644
--- a/test/compress/reduce_vars.js
+++ b/test/compress/reduce_vars.js
@@ -3654,3 +3654,194 @@ issue_2440_with_2: {
}
}
}
+
+issue_2442: {
+ options = {
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ function foo() {
+ foo();
+ }
+ }
+ expect: {}
+}
+
+recursive_inlining_1: {
+ options = {
+ reduce_vars: true,
+ unused: true,
+ }
+ input: {
+ !function() {
+ function foo() { bar(); }
+ function bar() { foo(); }
+ console.log("PASS");
+ }();
+ }
+ expect: {
+ !function() {
+ console.log("PASS");
+ }();
+ }
+ expect_stdout: "PASS"
+}
+
+recursive_inlining_2: {
+ options = {
+ reduce_vars: true,
+ unused: true,
+ }
+ input: {
+ !function() {
+ function foo() { qux(); }
+ function bar() { foo(); }
+ function qux() { bar(); }
+ console.log("PASS");
+ }();
+ }
+ expect: {
+ !function() {
+ console.log("PASS");
+ }();
+ }
+ expect_stdout: "PASS"
+}
+
+recursive_inlining_3: {
+ options = {
+ reduce_vars: true,
+ unused: true,
+ }
+ input: {
+ !function() {
+ function foo(x) { console.log("foo", x); if (x) bar(x-1); }
+ function bar(x) { console.log("bar", x); if (x) qux(x-1); }
+ function qux(x) { console.log("qux", x); if (x) foo(x-1); }
+ qux(4);
+ }();
+ }
+ expect: {
+ !function() {
+ function qux(x) {
+ console.log("qux", x);
+ if (x) (function(x) {
+ console.log("foo", x);
+ if (x) (function(x) {
+ console.log("bar", x);
+ if (x) qux(x - 1);
+ })(x - 1);
+ })(x - 1);
+ }
+ qux(4);
+ }();
+ }
+ expect_stdout: [
+ "qux 4",
+ "foo 3",
+ "bar 2",
+ "qux 1",
+ "foo 0",
+ ]
+}
+
+recursive_inlining_4: {
+ options = {
+ reduce_vars: true,
+ unused: true,
+ }
+ input: {
+ !function() {
+ function foo(x) { console.log("foo", x); if (x) bar(x-1); }
+ function bar(x) { console.log("bar", x); if (x) qux(x-1); }
+ function qux(x) { console.log("qux", x); if (x) foo(x-1); }
+ qux(4);
+ bar(5);
+ }();
+ }
+ expect: {
+ !function() {
+ function bar(x) {
+ console.log("bar", x);
+ if (x) qux(x - 1);
+ }
+ function qux(x) {
+ console.log("qux", x);
+ if (x) (function(x) {
+ console.log("foo", x);
+ if (x) bar(x - 1);
+ })(x - 1);
+ }
+ qux(4);
+ bar(5);
+ }();
+ }
+ expect_stdout: [
+ "qux 4",
+ "foo 3",
+ "bar 2",
+ "qux 1",
+ "foo 0",
+ "bar 5",
+ "qux 4",
+ "foo 3",
+ "bar 2",
+ "qux 1",
+ "foo 0",
+ ]
+}
+
+recursive_inlining_5: {
+ options = {
+ reduce_vars: true,
+ unused: true,
+ }
+ input: {
+ !function() {
+ function foo(x) { console.log("foo", x); if (x) bar(x-1); }
+ function bar(x) { console.log("bar", x); if (x) qux(x-1); }
+ function qux(x) { console.log("qux", x); if (x) foo(x-1); }
+ qux(4);
+ bar(5);
+ foo(3);
+ }();
+ }
+ expect: {
+ !function() {
+ function foo(x) {
+ console.log("foo", x);
+ if (x) bar(x - 1);
+ }
+ function bar(x) {
+ console.log("bar", x);
+ if (x) qux(x - 1);
+ }
+ function qux(x) {
+ console.log("qux", x);
+ if (x) foo(x - 1);
+ }
+ qux(4);
+ bar(5);
+ foo(3);
+ }();
+ }
+ expect_stdout: [
+ "qux 4",
+ "foo 3",
+ "bar 2",
+ "qux 1",
+ "foo 0",
+ "bar 5",
+ "qux 4",
+ "foo 3",
+ "bar 2",
+ "qux 1",
+ "foo 0",
+ "foo 3",
+ "bar 2",
+ "qux 1",
+ "foo 0",
+ ]
+}