diff --git a/lib/compress.js b/lib/compress.js index f1c6e07d..8c9e3f76 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -12998,6 +12998,7 @@ Compressor.prototype.compress = function(node) { }); scope = scope.parent_scope; } + if (!member(scope, compressor.stack)) return; if (scope instanceof AST_Toplevel && fn.variables.size() > (arrow ? 0 : 1)) { if (!compressor.toplevel.vars) return; if (fn.functions.size() > 0 && !compressor.toplevel.funcs) return; diff --git a/test/compress/functions.js b/test/compress/functions.js index a196f79f..31be259c 100644 --- a/test/compress/functions.js +++ b/test/compress/functions.js @@ -7977,3 +7977,40 @@ issue_5264_2: { "baz", ] } + +issue_5283: { + options = { + if_return: true, + inline: true, + pure_getters: "strict", + side_effects: true, + unused: true, + } + input: { + var a = "FAIL 1"; + (function() { + (a = "PASS")[function() { + if (console) + return null; + var b = function f(a) { + console.log("FAIL 2"); + var c = a.p; + }(); + }()]; + })(); + console.log(a); + } + expect: { + var a = "FAIL 1"; + (function() { + a = "PASS"; + if (!console) + (function(a) { + console.log("FAIL 2"); + a.p; + })(); + })(); + console.log(a); + } + expect_stdout: "PASS" +}