aboutsummaryrefslogtreecommitdiff
path: root/test/compress/drop-unused.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2018-01-04 01:03:33 +0800
committerGitHub <noreply@github.com>2018-01-04 01:03:33 +0800
commitcfe3a98ce50a1eb844654da57b4ef47a750feda5 (patch)
tree7c15b516108c4eda8a4e1836d059c7d54c8e9e15 /test/compress/drop-unused.js
parent14778e049b12e131fc05ddacff9cda56dfede77d (diff)
downloadtracifyjs-cfe3a98ce50a1eb844654da57b4ef47a750feda5.tar.gz
tracifyjs-cfe3a98ce50a1eb844654da57b4ef47a750feda5.zip
drop `unused` assignment based on `reduce_vars` (#2709)
Diffstat (limited to 'test/compress/drop-unused.js')
-rw-r--r--test/compress/drop-unused.js122
1 files changed, 122 insertions, 0 deletions
diff --git a/test/compress/drop-unused.js b/test/compress/drop-unused.js
index 21d4b7ce..5ad489b9 100644
--- a/test/compress/drop-unused.js
+++ b/test/compress/drop-unused.js
@@ -1522,3 +1522,125 @@ issue_2665: {
}
expect_stdout: "-1"
}
+
+double_assign_1: {
+ options = {
+ passes: 2,
+ reduce_vars: true,
+ side_effects: true,
+ unused: true,
+ }
+ input: {
+ function f1() {
+ var a = {};
+ var a = [];
+ return a;
+ }
+ function f2() {
+ var a = {};
+ a = [];
+ return a;
+ }
+ function f3() {
+ a = {};
+ var a = [];
+ return a;
+ }
+ function f4(a) {
+ a = {};
+ a = [];
+ return a;
+ }
+ function f5(a) {
+ var a = {};
+ a = [];
+ return a;
+ }
+ function f6(a) {
+ a = {};
+ var a = [];
+ return a;
+ }
+ console.log(f1(), f2(), f3(), f4(), f5(), f6());
+ }
+ expect: {
+ function f1() {
+ return [];
+ }
+ function f2() {
+ var a;
+ a = [];
+ return a;
+ }
+ function f3() {
+ return [];
+ }
+ function f4(a) {
+ a = [];
+ return a;
+ }
+ function f5(a) {
+ a = [];
+ return a;
+ }
+ function f6(a) {
+ a = [];
+ return a;
+ }
+ console.log(f1(), f2(), f3(), f4(), f5(), f6());
+ }
+ expect_stdout: true
+}
+
+double_assign_2: {
+ options = {
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ for (var i = 0; i < 2; i++)
+ a = void 0, a = {}, console.log(a);
+ var a;
+ }
+ expect: {
+ for (var i = 0; i < 2; i++)
+ void 0, a = {}, console.log(a);
+ var a;
+ }
+}
+
+double_assign_3: {
+ options = {
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ for (var i = 0; i < 2; i++)
+ a = void 0, a = { a: a }, console.log(a);
+ var a;
+ }
+ expect: {
+ for (var i = 0; i < 2; i++)
+ a = void 0, a = { a: a }, console.log(a);
+ var a;
+ }
+}
+
+cascade_drop_assign: {
+ options = {
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ var a, b = a = "PASS";
+ console.log(b);
+ }
+ expect: {
+ var b = "PASS";
+ console.log(b);
+ }
+ expect_stdout: "PASS"
+}