From caa92aea5d6ff4f0ac053df3163a6bc2266002ec Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Tue, 17 Nov 2020 20:03:20 +0000 Subject: fix corner case in `merge_vars` (#4289) fixes #4288 --- lib/compress.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'lib/compress.js') diff --git a/lib/compress.js b/lib/compress.js index fe2e6242..c86bb5f0 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -4739,13 +4739,25 @@ merge(Compressor.prototype, { if (node === self) root = segment; if (node instanceof AST_Lambda) { if (node.name) references[node.name.definition().id] = false; - node.each_argname(node.uses_arguments && !tw.has_directive("use strict") ? function(node) { - references[node.definition().id] = false; + var marker = node.uses_arguments && !tw.has_directive("use strict") ? function(node) { + if (node instanceof AST_SymbolFunarg) references[node.definition().id] = false; } : function(node) { - mark(node, false, true); + if (node instanceof AST_SymbolFunarg) mark(node, false, true); + }; + var scanner = new TreeWalker(function(ref) { + if (!(ref instanceof AST_SymbolRef)) return; + var def = ref.definition(); + var ldef = node.variables.get(ref.name); + if (ldef && (ldef === def || def.undeclared || node.parent_scope.find_variable(ref) === def)) { + references[ldef.id] = false; + } + return true; + }); + node.argnames.forEach(function(argname) { + argname.mark_symbol(marker, scanner); }); } - descend(); + walk_body(node, tw); pop(); return true; } -- cgit v1.2.3