From f34fbb2c36b2fd1cfe38aa12d103cdeb3916c73d Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L." Date: Wed, 14 Aug 2024 01:35:47 +0300 Subject: [PATCH] fix corner case in `reduce_vars` (#5919) fixes #5917 --- lib/compress.js | 4 ---- test/compress/pure_getters.js | 36 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index 1e358599f5f..5438cc54da7 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -601,10 +601,6 @@ Compressor.prototype.compress = function(node) { 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 && fixed.safe_ids !== undefined) return; d.fixed = false; }); } diff --git a/test/compress/pure_getters.js b/test/compress/pure_getters.js index 7f2ec4e8810..1e6509e1c52 100644 --- a/test/compress/pure_getters.js +++ b/test/compress/pure_getters.js @@ -1715,3 +1715,39 @@ issue_5856: { } expect_stdout: "PASS" } + +issue_5917: { + options = { + pure_getters: "strict", + reduce_vars: true, + side_effects: true, + toplevel: true, + } + input: { + var a; + console || (a = function() {})(f); + function f() { + a.p; + } + try { + f(); + console.log("FAIL"); + } catch (e) { + console.log("PASS"); + } + } + expect: { + var a; + console || (a = function() {})(f); + function f() { + a.p; + } + try { + f(); + console.log("FAIL"); + } catch (e) { + console.log("PASS"); + } + } + expect_stdout: "PASS" +}