aboutsummaryrefslogtreecommitdiff
path: root/test/compress
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2018-01-31 23:49:59 +0800
committerGitHub <noreply@github.com>2018-01-31 23:49:59 +0800
commit2a4c68be4f3ed60fa638b66a57e7056f7507da83 (patch)
tree4b81a3ab5a30cbf4a8842ee39109af82f960e2e9 /test/compress
parent541e6011af7647074a41c5a82a0a16a3d32bb8c6 (diff)
downloadtracifyjs-2a4c68be4f3ed60fa638b66a57e7056f7507da83.tar.gz
tracifyjs-2a4c68be4f3ed60fa638b66a57e7056f7507da83.zip
relax `collapse_vars` on `AST_Exit` (#2855)
First introduced in #1862 to stop assignments to migrate beyond `return` or `throw`. Since then `collapse_vars` has been improved to handle various side-effect-related corner cases.
Diffstat (limited to 'test/compress')
-rw-r--r--test/compress/collapse_vars.js83
1 files changed, 83 insertions, 0 deletions
diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js
index 4172b33b..b3617816 100644
--- a/test/compress/collapse_vars.js
+++ b/test/compress/collapse_vars.js
@@ -4107,3 +4107,86 @@ unsafe_builtin: {
}
expect_stdout: "1 4"
}
+
+return_1: {
+ options = {
+ collapse_vars: true,
+ unused: true,
+ }
+ input: {
+ var log = console.log;
+ function f(b, c) {
+ var a = c;
+ if (b) return b;
+ log(a);
+ }
+ f(false, 1);
+ f(true, 2);
+ }
+ expect: {
+ var log = console.log;
+ function f(b, c) {
+ if (b) return b;
+ log(c);
+ }
+ f(false, 1);
+ f(true, 2);
+ }
+ expect_stdout: "1"
+}
+
+return_2: {
+ options = {
+ collapse_vars: true,
+ unused: true,
+ }
+ input: {
+ var log = console.log;
+ function f(b, c) {
+ var a = c();
+ if (b) return b;
+ log(a);
+ }
+ f(false, function() { return 1 });
+ f(true, function() { return 2 });
+ }
+ expect: {
+ var log = console.log;
+ function f(b, c) {
+ var a = c();
+ if (b) return b;
+ log(a);
+ }
+ f(false, function() { return 1 });
+ f(true, function() { return 2 });
+ }
+ expect_stdout: "1"
+}
+
+return_3: {
+ options = {
+ collapse_vars: true,
+ unused: true,
+ }
+ input: {
+ var log = console.log;
+ function f(b, c) {
+ var a = b <<= c;
+ if (b) return b;
+ log(a);
+ }
+ f(false, 1);
+ f(true, 2);
+ }
+ expect: {
+ var log = console.log;
+ function f(b, c) {
+ var a = b <<= c;
+ if (b) return b;
+ log(a);
+ }
+ f(false, 1);
+ f(true, 2);
+ }
+ expect_stdout: "0"
+}