aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/compress.js31
-rw-r--r--test/compress/reduce_vars.js46
2 files changed, 65 insertions, 12 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 714d3cd7..75b1c8ab 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -526,26 +526,33 @@ merge(Compressor.prototype, {
tw.fn_scanning = was_scanning;
}
+ function revisit_fn_def(tw, fn) {
+ fn.enclosed.forEach(function(d) {
+ if (fn.variables.get(d.name) === d) return;
+ if (safe_to_read(tw, d)) return;
+ d.single_use = false;
+ var fixed = d.fixed;
+ if (typeof fixed == "function") fixed = fixed();
+ if (fixed instanceof AST_Lambda && HOP(fixed, "safe_ids")) return;
+ d.fixed = false;
+ });
+ }
+
function mark_fn_def(tw, def, fn) {
if (!HOP(fn, "safe_ids")) return;
var marker = fn.safe_ids;
if (marker === false) return;
- if (fn.parent_scope.resolve().may_call_this === return_true) return;
- if (marker) {
+ if (fn.parent_scope.resolve().may_call_this === return_true) {
+ if (member(fn, tw.fn_visited)) revisit_fn_def(tw, fn);
+ } else if (marker) {
var visited = member(fn, tw.fn_visited);
if (marker === tw.safe_ids) {
if (!visited) walk_fn_def(tw, fn);
- } else if (!visited) {
+ } else if (visited) {
+ revisit_fn_def(tw, fn);
+ } else {
fn.safe_ids = false;
- } else fn.enclosed.forEach(function(d) {
- if (fn.variables.get(d.name) === d) return;
- if (safe_to_read(tw, d)) return;
- d.single_use = false;
- var fixed = d.fixed;
- if (typeof fixed == "function") fixed = fixed();
- if (fixed instanceof AST_Lambda && HOP(fixed, "safe_ids")) return;
- d.fixed = false;
- });
+ }
} else if (tw.fn_scanning && tw.fn_scanning !== def.scope.resolve()) {
fn.safe_ids = false;
} else {
diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js
index 4af4945f..66c70d5a 100644
--- a/test/compress/reduce_vars.js
+++ b/test/compress/reduce_vars.js
@@ -7725,3 +7725,49 @@ issue_5050: {
"3",
]
}
+
+issue_5055_1: {
+ options = {
+ evaluate: true,
+ reduce_vars: true,
+ toplevel: true,
+ }
+ input: {
+ var a = "PASS";
+ function f() {
+ console.log(a || "FAIL");
+ }
+ f(0 && (a = 0)(f(this)));
+ }
+ expect: {
+ var a = "PASS";
+ function f() {
+ console.log(a || "FAIL");
+ }
+ f(0);
+ }
+ expect_stdout: "PASS"
+}
+
+issue_5055_2: {
+ options = {
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ var a = "PASS";
+ function f() {
+ console.log(a || "FAIL");
+ }
+ f(0 && (a = 0)(f(this)));
+ }
+ expect: {
+ var a = "PASS";
+ function f() {
+ console.log(a || "FAIL");
+ }
+ f(0 && (a = 0)(f()));
+ }
+ expect_stdout: "PASS"
+}