aboutsummaryrefslogtreecommitdiff
path: root/test/compress/collapse_vars.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-04-18 22:04:21 +0100
committerGitHub <noreply@github.com>2020-04-19 05:04:21 +0800
commiteb6f32bfc3c9af65f417e2e4440115cec21ac075 (patch)
treedad9cc96442a75542fe88b07137676d8d6854bab /test/compress/collapse_vars.js
parentf110601fb4bfa8f7b362bcc4a7a8a2f850e5132e (diff)
downloadtracifyjs-eb6f32bfc3c9af65f417e2e4440115cec21ac075.tar.gz
tracifyjs-eb6f32bfc3c9af65f417e2e4440115cec21ac075.zip
enhance `collapse_vars` (#3801)
Diffstat (limited to 'test/compress/collapse_vars.js')
-rw-r--r--test/compress/collapse_vars.js45
1 files changed, 39 insertions, 6 deletions
diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js
index ac87d788..c93a1465 100644
--- a/test/compress/collapse_vars.js
+++ b/test/compress/collapse_vars.js
@@ -803,8 +803,7 @@ collapse_vars_assignment: {
expect: {
function log(x) { return console.log(x), x; }
function f0(c) {
- var a = 3 / c;
- return a = a;
+ return 3 / c;
}
function f1(c) {
return 1 - 3 / c;
@@ -2205,8 +2204,8 @@ var_defs: {
}
expect: {
var f1 = function(x, y) {
- var r = x + y, a = r * r - r, b = 7;
- console.log(a + b);
+ var r = x + y, z = r * r - r, b = 7;
+ console.log(z + b);
};
f1("1", 0);
}
@@ -2665,8 +2664,8 @@ double_def_1: {
a();
}
expect: {
- var a;
- (a = (a = x) && y)();
+ var a = x;
+ (a = a && y)();
}
}
@@ -7921,3 +7920,37 @@ var_value_def: {
}
expect_stdout: "PASS"
}
+
+mangleable_var: {
+ options = {
+ collapse_vars: true,
+ unused: true,
+ }
+ input: {
+ function f(a) {
+ var b = a(), c = a(), d = b;
+ return c.p(c, d);
+ }
+ console.log(f(function() {
+ return {
+ p: function() {
+ return "PASS"
+ },
+ };
+ }));
+ }
+ expect: {
+ function f(a) {
+ var b = a(), c = a();
+ return c.p(c, b);
+ }
+ console.log(f(function() {
+ return {
+ p: function() {
+ return "PASS";
+ }
+ };
+ }));
+ }
+ expect_stdout: "PASS"
+}