aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2018-08-29 22:14:25 +0800
committerGitHub <noreply@github.com>2018-08-29 22:14:25 +0800
commitaa0029204ebb7f52db4c70e9579caa1712d1261f (patch)
tree8961c28c92832fd0e2a14272994a8e54a6003e54 /test
parentf352bcec3ab48b1dafd5fdf698f99398c4cf52ff (diff)
downloadtracifyjs-aa0029204ebb7f52db4c70e9579caa1712d1261f.tar.gz
tracifyjs-aa0029204ebb7f52db4c70e9579caa1712d1261f.zip
fix corner case in `reduce_vars` (#3241)
fixes #3240
Diffstat (limited to 'test')
-rw-r--r--test/compress/reduce_vars.js157
1 files changed, 157 insertions, 0 deletions
diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js
index dad8ca3b..b040a3f7 100644
--- a/test/compress/reduce_vars.js
+++ b/test/compress/reduce_vars.js
@@ -5354,6 +5354,7 @@ issue_2774: {
issue_2799_1: {
options = {
+ passes: 2,
reduce_funcs: true,
reduce_vars: true,
unused: true,
@@ -6429,3 +6430,159 @@ issue_3140_5: {
}
expect_stdout: "1"
}
+
+issue_3240_1: {
+ options = {
+ reduce_funcs: true,
+ reduce_vars: true,
+ unused: true,
+ }
+ input: {
+ (function() {
+ f(1);
+ function f(a) {
+ console.log(a);
+ var g = function() {
+ f(a - 1);
+ };
+ if (a) g();
+ }
+ })();
+ }
+ expect: {
+ (function() {
+ (function f(a) {
+ console.log(a);
+ var g = function() {
+ f(a - 1);
+ };
+ if (a) g();
+ })(1);
+ })();
+ }
+ expect_stdout: [
+ "1",
+ "0",
+ ]
+}
+
+issue_3240_2: {
+ options = {
+ passes: 2,
+ reduce_funcs: true,
+ reduce_vars: true,
+ unused: true,
+ }
+ input: {
+ (function() {
+ f(1);
+ function f(a) {
+ console.log(a);
+ var g = function() {
+ f(a - 1);
+ };
+ if (a) g();
+ }
+ })();
+ }
+ expect: {
+ (function() {
+ (function f(a) {
+ console.log(a);
+ if (a) (function() {
+ f(a - 1);
+ })();
+ })(1);
+ })();
+ }
+ expect_stdout: [
+ "1",
+ "0",
+ ]
+}
+
+issue_3240_3: {
+ options = {
+ reduce_funcs: true,
+ reduce_vars: true,
+ unused: true,
+ }
+ input: {
+ (function() {
+ f();
+ function f(b) {
+ if (!f.a) f.a = 0;
+ console.log(f.a.toString());
+ var g = function() {
+ (b ? function() {} : function() {
+ f.a++;
+ f(1);
+ })();
+ };
+ g();
+ }
+ })();
+ }
+ expect: {
+ (function() {
+ (function f(b) {
+ if (!f.a) f.a = 0;
+ console.log(f.a.toString());
+ var g = function() {
+ (b ? function() {} : function() {
+ f.a++;
+ f(1);
+ })();
+ };
+ g();
+ })();
+ })();
+ }
+ expect_stdout: [
+ "0",
+ "1",
+ ]
+}
+
+issue_3240_4: {
+ options = {
+ passes: 2,
+ reduce_funcs: true,
+ reduce_vars: true,
+ unused: true,
+ }
+ input: {
+ (function() {
+ f();
+ function f(b) {
+ if (!f.a) f.a = 0;
+ console.log(f.a.toString());
+ var g = function() {
+ (b ? function() {} : function() {
+ f.a++;
+ f(1);
+ })();
+ };
+ g();
+ }
+ })();
+ }
+ expect: {
+ (function() {
+ (function f(b) {
+ if (!f.a) f.a = 0;
+ console.log(f.a.toString());
+ (function() {
+ (b ? function() {} : function() {
+ f.a++;
+ f(1);
+ })();
+ })();
+ })();
+ })();
+ }
+ expect_stdout: [
+ "0",
+ "1",
+ ]
+}