From 7621527a5f6a2bef8be44714729a082d4691d2d5 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Thu, 24 Jun 2021 20:43:52 +0100 Subject: [PATCH] fix corner case in `functions` (#5037) fixes #5036 --- lib/compress.js | 8 +++----- test/compress/functions.js | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index 22f4736a748..0f9f079593f 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -6574,12 +6574,10 @@ merge(Compressor.prototype, { return all(def.references, function(ref) { var scope = ref.scope; if (scope.find_variable(name) !== sym) return false; - if (forbidden) { + if (forbidden) do { scope = scope.resolve(); - do { - if (forbidden(scope)) return false; - } while ((scope = scope.parent_scope.resolve()) && scope !== fn); - } + if (forbidden(scope)) return false; + } while (scope !== fn && (scope = scope.parent_scope)); return true; }) && def; } diff --git a/test/compress/functions.js b/test/compress/functions.js index b3a6011f348..e4766cd5c7e 100644 --- a/test/compress/functions.js +++ b/test/compress/functions.js @@ -6258,3 +6258,28 @@ issue_5025: { } expect_stdout: "object" } + +issue_5036: { + options = { + functions: true, + reduce_vars: true, + unused: true, + } + input: { + console.log(typeof function() { + var await = function f() { + return f; + }; + return await() === await; + }() ? "PASS" : "FAIL"); + } + expect: { + console.log(typeof function() { + function await() { + return await; + } + return await() === await; + }() ? "PASS" : "FAIL"); + } + expect_stdout: "PASS" +}