From aecbabc587247f65316988629d17aa29383f9156 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Wed, 18 Nov 2020 21:44:47 +0000 Subject: [PATCH] fix corner case in `merge_vars` (#4302) fixes #4301 --- lib/compress.js | 19 ++++++++++++++++--- test/compress/destructured.js | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index 0f1342f7..f0453d6a 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -4635,14 +4635,27 @@ merge(Compressor.prototype, { var lhs = node.left; if (lhs instanceof AST_Destructured) { node.right.walk(tw); - lhs.mark_symbol(function(node) { - if (node instanceof AST_SymbolRef) { + var marker = new TreeWalker(function(node) { + if (node instanceof AST_Destructured) return; + if (node instanceof AST_DestructuredKeyVal) { + if (node.key instanceof AST_Node) { + push(); + node.key.walk(tw); + pop(); + push(); + node.value.walk(marker); + pop(); + } else { + node.value.walk(marker); + } + } else if (node instanceof AST_SymbolRef) { mark(node, false, true); } else { node.walk(tw); } return true; - }, tw); + }); + lhs.walk(marker); return true; } if (lhs instanceof AST_SymbolRef) { diff --git a/test/compress/destructured.js b/test/compress/destructured.js index 8671d87b..bbe62a71 100644 --- a/test/compress/destructured.js +++ b/test/compress/destructured.js @@ -1559,3 +1559,35 @@ issue_4298: { expect_stdout: "PASS" node_version: ">=6" } + +issue_4301: { + options = { + merge_vars: true, + } + input: { + try { + console.log(function() { + var a, b = console; + return { + [a = b]: a.p, + } = "foo"; + }()); + } catch (e) { + console.log("bar"); + } + } + expect: { + try { + console.log(function() { + var a, b = console; + return { + [a = b]: a.p, + } = "foo"; + }()); + } catch (e) { + console.log("bar"); + } + } + expect_stdout: true + node_version: ">=6" +} -- 2.34.1