From 2944e3df7d743e32737ddf51d3c91cd1ccb448b2 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Tue, 9 May 2017 17:44:28 +0800 Subject: [PATCH] fix `collapse_vars` on destructuring declarations (#1889) fixes #1886 --- lib/compress.js | 2 +- test/compress/destructuring.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/compress.js b/lib/compress.js index 21ff25cc..8abf5d11 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -799,7 +799,7 @@ merge(Compressor.prototype, { } function get_lhs(expr) { - if (expr instanceof AST_VarDef) { + if (expr instanceof AST_VarDef && expr.name instanceof AST_SymbolDeclaration) { var def = expr.name.definition(); if (def.orig.length > 1 || def.references.length == 1 && (!def.global || compressor.toplevel(def))) { diff --git a/test/compress/destructuring.js b/test/compress/destructuring.js index 8603a38b..70f5d053 100644 --- a/test/compress/destructuring.js +++ b/test/compress/destructuring.js @@ -315,3 +315,18 @@ unused: { console.log(a); } } + +issue_1886: { + options = { + collapse_vars: true, + } + input: { + let [a] = [1]; + console.log(a); + } + expect: { + let [a] = [1]; + console.log(a); + } + expect_exact: "1" +}