aboutsummaryrefslogtreecommitdiff
path: root/test/compress/collapse_vars.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2018-08-29 11:34:34 +0800
committerGitHub <noreply@github.com>2018-08-29 11:34:34 +0800
commitf352bcec3ab48b1dafd5fdf698f99398c4cf52ff (patch)
tree9110a7611545f2a0a60a1cee9b94958cbb4353bc /test/compress/collapse_vars.js
parent08514030f4140cb604f2b316987280a29c02883e (diff)
downloadtracifyjs-f352bcec3ab48b1dafd5fdf698f99398c4cf52ff.tar.gz
tracifyjs-f352bcec3ab48b1dafd5fdf698f99398c4cf52ff.zip
fix corner case in `collapse_vars` (#3239)
fixes #3238
Diffstat (limited to 'test/compress/collapse_vars.js')
-rw-r--r--test/compress/collapse_vars.js180
1 files changed, 180 insertions, 0 deletions
diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js
index 31eb2383..d1c26c68 100644
--- a/test/compress/collapse_vars.js
+++ b/test/compress/collapse_vars.js
@@ -5827,3 +5827,183 @@ issue_3215_4: {
}
expect_stdout: "number"
}
+
+issue_3238_1: {
+ options = {
+ collapse_vars: true,
+ unsafe: true,
+ }
+ input: {
+ function f(a) {
+ var b, c;
+ if (a) {
+ b = Object.create(null);
+ c = Object.create(null);
+ }
+ return b === c;
+ }
+ console.log(f(0), f(1));
+ }
+ expect: {
+ function f(a) {
+ var b, c;
+ if (a) {
+ b = Object.create(null);
+ c = Object.create(null);
+ }
+ return b === c;
+ }
+ console.log(f(0), f(1));
+ }
+ expect_stdout: "true false"
+}
+
+issue_3238_2: {
+ options = {
+ collapse_vars: true,
+ unsafe: true,
+ }
+ input: {
+ function f(a) {
+ var b, c;
+ if (a) {
+ b = Error();
+ c = Error();
+ }
+ return b === c;
+ }
+ console.log(f(0), f(1));
+ }
+ expect: {
+ function f(a) {
+ var b, c;
+ if (a) {
+ b = Error();
+ c = Error();
+ }
+ return b === c;
+ }
+ console.log(f(0), f(1));
+ }
+ expect_stdout: "true false"
+}
+
+issue_3238_3: {
+ options = {
+ collapse_vars: true,
+ unsafe: true,
+ }
+ input: {
+ function f(a) {
+ var b, c;
+ if (a) {
+ b = new Date();
+ c = new Date();
+ }
+ return b === c;
+ }
+ console.log(f(0), f(1));
+ }
+ expect: {
+ function f(a) {
+ var b, c;
+ if (a) {
+ b = new Date();
+ c = new Date();
+ }
+ return b === c;
+ }
+ console.log(f(0), f(1));
+ }
+ expect_stdout: "true false"
+}
+
+issue_3238_4: {
+ options = {
+ collapse_vars: true,
+ unsafe: true,
+ }
+ input: {
+ function f(a) {
+ var b, c;
+ if (a) {
+ b = a && {};
+ c = a && {};
+ }
+ return b === c;
+ }
+ console.log(f(0), f(1));
+ }
+ expect: {
+ function f(a) {
+ var b, c;
+ if (a) {
+ b = a && {};
+ c = a && {};
+ }
+ return b === c;
+ }
+ console.log(f(0), f(1));
+ }
+ expect_stdout: "true false"
+}
+
+issue_3238_5: {
+ options = {
+ collapse_vars: true,
+ unsafe: true,
+ }
+ input: {
+ function f(a) {
+ var b, c;
+ if (a) {
+ b = a ? [] : 42;
+ c = a ? [] : 42;
+ }
+ return b === c;
+ }
+ console.log(f(0), f(1));
+ }
+ expect: {
+ function f(a) {
+ var b, c;
+ if (a) {
+ b = a ? [] : 42;
+ c = a ? [] : 42;
+ }
+ return b === c;
+ }
+ console.log(f(0), f(1));
+ }
+ expect_stdout: "true false"
+}
+
+issue_3238_6: {
+ options = {
+ collapse_vars: true,
+ unsafe: true,
+ }
+ input: {
+ function f(a) {
+ var b, c;
+ if (a) {
+ b = a && 0 || [];
+ c = a && 0 || [];
+ }
+ return b === c;
+ }
+ console.log(f(0), f(1));
+ }
+ expect: {
+ function f(a) {
+ var b, c;
+ if (a) {
+ b = a && 0 || [];
+ c = a && 0 || [];
+ }
+ return b === c;
+ }
+ console.log(f(0), f(1));
+ }
+ expect_stdout: "true false"
+}