aboutsummaryrefslogtreecommitdiff
path: root/test/compress/dead-code.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2017-12-14 02:59:59 +0800
committerGitHub <noreply@github.com>2017-12-14 02:59:59 +0800
commit9a137e8613e49066a54f2a1b734a559c05338f11 (patch)
treed621147814d38dfd20a97c25d287e12b739b3dde /test/compress/dead-code.js
parentef618332ea92db57e59f90f166035a0e7cf8a509 (diff)
downloadtracifyjs-9a137e8613e49066a54f2a1b734a559c05338f11.tar.gz
tracifyjs-9a137e8613e49066a54f2a1b734a559c05338f11.zip
drop local assign-only variable in `return` (#2587)
Diffstat (limited to 'test/compress/dead-code.js')
-rw-r--r--test/compress/dead-code.js90
1 files changed, 90 insertions, 0 deletions
diff --git a/test/compress/dead-code.js b/test/compress/dead-code.js
index 9baf9984..ca7ad5c0 100644
--- a/test/compress/dead-code.js
+++ b/test/compress/dead-code.js
@@ -417,3 +417,93 @@ global_fns: {
"RangeError",
]
}
+
+collapse_vars_assignment: {
+ options = {
+ collapse_vars: true,
+ dead_code: true,
+ passes: 2,
+ unused: true,
+ }
+ input: {
+ function f0(c) {
+ var a = 3 / c;
+ return a = a;
+ }
+ }
+ expect: {
+ function f0(c) {
+ return 3 / c;
+ }
+ }
+}
+
+collapse_vars_lvalues_drop_assign: {
+ options = {
+ collapse_vars: true,
+ dead_code: true,
+ unused: true,
+ }
+ input: {
+ function f0(x) { var i = ++x; return x += i; }
+ function f1(x) { var a = (x -= 3); return x += a; }
+ function f2(x) { var z = x, a = ++z; return z += a; }
+ }
+ expect: {
+ function f0(x) { var i = ++x; return x + i; }
+ function f1(x) { var a = (x -= 3); return x + a; }
+ function f2(x) { var z = x, a = ++z; return z + a; }
+ }
+}
+
+collapse_vars_misc1: {
+ options = {
+ collapse_vars: true,
+ dead_code: true,
+ unused: true,
+ }
+ input: {
+ function f10(x) { var a = 5, b = 3; return a += b; }
+ function f11(x) { var a = 5, b = 3; return a += --b; }
+ }
+ expect: {
+ function f10(x) { return 5 + 3; }
+ function f11(x) { var b = 3; return 5 + --b; }
+ }
+}
+
+return_assignment: {
+ options = {
+ dead_code: true,
+ unused: true,
+ }
+ input: {
+ function f1(a, b, c) {
+ return a = x(), b = y(), b = a && (c >>= 5);
+ }
+ function f2() {
+ return e = x();
+ }
+ function f3(e) {
+ return e = x();
+ }
+ function f4() {
+ var e;
+ return e = x();
+ }
+ }
+ expect: {
+ function f1(a, b, c) {
+ return a = x(), y(), a && (c >> 5);
+ }
+ function f2() {
+ return e = x();
+ }
+ function f3(e) {
+ return x();
+ }
+ function f4() {
+ return x();
+ }
+ }
+}