diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-11-17 20:03:20 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-18 04:03:20 +0800 |
commit | caa92aea5d6ff4f0ac053df3163a6bc2266002ec (patch) | |
tree | 3f1cc64312599e71c23bc26218c283e51d9bb93c /lib/compress.js | |
parent | 383163afa67c5726e18da145d6eb012ee1b064e3 (diff) | |
download | tracifyjs-caa92aea5d6ff4f0ac053df3163a6bc2266002ec.tar.gz tracifyjs-caa92aea5d6ff4f0ac053df3163a6bc2266002ec.zip |
fix corner case in `merge_vars` (#4289)
fixes #4288
Diffstat (limited to 'lib/compress.js')
-rw-r--r-- | lib/compress.js | 20 |
1 files changed, 16 insertions, 4 deletions
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; } |