aboutsummaryrefslogtreecommitdiff
path: root/test/compress
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-01-30 00:08:53 +0800
committerGitHub <noreply@github.com>2020-01-30 00:08:53 +0800
commita3754068dde7a51ab41b59a6d8a17a3a8c022564 (patch)
treebbf713958d95e4e5d558f7173959f0dfce7fb48f /test/compress
parent2ba5f391e008b5d842571094d1140f9ae888ea4d (diff)
downloadtracifyjs-a3754068dde7a51ab41b59a6d8a17a3a8c022564.tar.gz
tracifyjs-a3754068dde7a51ab41b59a6d8a17a3a8c022564.zip
fix corner case in `collapse_vars` (#3699)
fixes #3698
Diffstat (limited to 'test/compress')
-rw-r--r--test/compress/collapse_vars.js76
1 files changed, 76 insertions, 0 deletions
diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js
index 4cd59a4c..f109e93e 100644
--- a/test/compress/collapse_vars.js
+++ b/test/compress/collapse_vars.js
@@ -7658,3 +7658,79 @@ call_3_symbol: {
}
expect_stdout: "function"
}
+
+issue_3698_1: {
+ options = {
+ collapse_vars: true,
+ }
+ input: {
+ var log = console.log;
+ var a, b = 0, c = 0;
+ (function() {
+ a = b;
+ })(b++, (b++, c++));
+ log(a, b, c);
+ }
+ expect: {
+ var log = console.log;
+ var a, b = 0, c = 0;
+ (function() {
+ a = b;
+ })(b++, (b++, c++));
+ log(a, b, c);
+ }
+ expect_stdout: "2 2 1"
+}
+
+issue_3698_2: {
+ options = {
+ collapse_vars: true,
+ reduce_vars: true,
+ }
+ input: {
+ var log = console.log;
+ var a, b = 0, c = 0, d = 1;
+ (function f() {
+ a = b;
+ d-- && f();
+ })(b++, (b++, c++));
+ log(a, b, c, d);
+ }
+ expect: {
+ var log = console.log;
+ var a, b = 0, c = 0, d = 1;
+ (function f() {
+ a = b;
+ d-- && f();
+ })(b++, (b++, c++));
+ log(a, b, c, d);
+ }
+ expect_stdout: "2 2 1 -1"
+}
+
+issue_3698_3: {
+ options = {
+ collapse_vars: true,
+ reduce_vars: true,
+ }
+ input: {
+ var a = 0, b = 0;
+ (function f(c) {
+ {
+ b++;
+ var bar_1 = (b = 1 + b, c = 0);
+ a-- && f();
+ }
+ })();
+ console.log(b);
+ }
+ expect: {
+ var a = 0, b = 0;
+ (function f(c) {
+ var bar_1 = (b = 1 + ++b, c = 0);
+ a-- && f();
+ })();
+ console.log(b);
+ }
+ expect_stdout: "2"
+}