From 8bc03dc6c47e987815e062abf86508582d7e5de7 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Sun, 29 May 2022 05:10:19 +0100 Subject: [PATCH] fix corner case in `keep_fargs` (#5477) fixes #5476 --- lib/scope.js | 13 +++++++------ test/compress/const.js | 17 +++++++++++++++++ test/compress/let.js | 20 ++++++++++++++++++++ test/ufuzz/index.js | 2 +- 4 files changed, 45 insertions(+), 7 deletions(-) diff --git a/lib/scope.js b/lib/scope.js index 90301d9a..2a54a5ce 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -64,19 +64,20 @@ SymbolDef.prototype = { this.references.forEach(fn); }, mangle: function(options) { - var cache = options.cache && options.cache.props; - if (this.global && cache && cache.has(this.name)) { + if (this.mangled_name) return; + var cache = this.global && options.cache && options.cache.props; + if (cache && cache.has(this.name)) { this.mangled_name = cache.get(this.name); - } else if (!this.mangled_name && !this.unmangleable(options)) { + } else if (this.unmangleable(options)) { + names_in_use(this.scope, options).set(this.name, true); + } else { var def = this.redefined(); if (def) { this.mangled_name = def.mangled_name || def.name; } else { this.mangled_name = next_mangled_name(this, options); } - if (this.global && cache) { - cache.set(this.name, this.mangled_name); - } + if (cache) cache.set(this.name, this.mangled_name); } }, redefined: function() { diff --git a/test/compress/const.js b/test/compress/const.js index 8178747d..0729a68c 100644 --- a/test/compress/const.js +++ b/test/compress/const.js @@ -1855,3 +1855,20 @@ issue_5338: { } expect_stdout: true } + +issue_5476: { + mangle = { + keep_fargs: true, + } + input: { + console.log(function(n) { + const a = 42; + }()); + } + expect: { + console.log(function(n) { + const o = 42; + }()); + } + expect_stdout: "undefined" +} diff --git a/test/compress/let.js b/test/compress/let.js index d0261fc4..eb096b37 100644 --- a/test/compress/let.js +++ b/test/compress/let.js @@ -2020,3 +2020,23 @@ issue_5338: { expect_stdout: ReferenceError("a is not defined") node_version: ">=4" } + +issue_5476: { + mangle = { + keep_fargs: true, + } + input: { + "use strict"; + console.log(function(n) { + let a; + }()); + } + expect: { + "use strict"; + console.log(function(n) { + let o; + }()); + } + expect_stdout: "undefined" + node_version: ">=4" +} diff --git a/test/ufuzz/index.js b/test/ufuzz/index.js index 14d9cc2f..49971309 100644 --- a/test/ufuzz/index.js +++ b/test/ufuzz/index.js @@ -2329,7 +2329,7 @@ function is_error_tdz(ex) { } function is_error_spread(ex) { - return ex.name == "TypeError" && /Found non-callable @@iterator| is not iterable| not a function/.test(ex.message); + return ex.name == "TypeError" && /Found non-callable @@iterator| is not iterable| not a function|Symbol\(Symbol\.iterator\)/.test(ex.message); } function is_error_recursion(ex) {