From 2122a181246112eab2f7b04430a28471be29dee5 Mon Sep 17 00:00:00 2001 From: alexlamsl Date: Sun, 22 Oct 2017 21:23:03 +0800 Subject: [PATCH] fix `dead_code` on `AST_Destructuring` fixes #2383 --- lib/compress.js | 13 ++++++++++++- test/compress/dead-code.js | 16 ++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/compress.js b/lib/compress.js index ad7c205a..f83a1ffd 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -3315,7 +3315,18 @@ merge(Compressor.prototype, { }); AST_Definitions.DEFMETHOD("remove_initializers", function(){ - this.definitions.forEach(function(def){ def.value = null }); + var decls = []; + this.definitions.forEach(function(def) { + def.name.walk(new TreeWalker(function(node) { + if (node instanceof AST_SymbolDeclaration) { + decls.push(make_node(AST_VarDef, def, { + name: node, + value: null + })); + } + })); + }); + this.definitions = decls; }); AST_Definitions.DEFMETHOD("to_assignments", function(compressor){ diff --git a/test/compress/dead-code.js b/test/compress/dead-code.js index 174b48e7..14dd0a95 100644 --- a/test/compress/dead-code.js +++ b/test/compress/dead-code.js @@ -560,3 +560,19 @@ global_fns: { "RangeError", ] } + +issue_2383: { + options = { + conditionals: true, + dead_code: true, + evaluate: true, + } + input: { + if (0) { + var {x, y} = foo(); + } + } + expect: { + var x, y; + } +}