From c7d2837184a7c435abe9c4411309f352170deb46 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Mon, 10 Jan 2022 07:43:26 +0000 Subject: [PATCH] fix corner case in `inline` (#5284) fixes #5283 --- lib/compress.js | 1 + test/compress/functions.js | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) 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" +}