From 48e76eb98c369562602229a26de6a81f7a273726 Mon Sep 17 00:00:00 2001 From: alexlamsl Date: Wed, 27 Dec 2017 15:20:03 +0800 Subject: [PATCH] fix `reduce_vars` on `AST_Destructuring` fixes #2669 --- lib/compress.js | 6 +++++- test/compress/reduce_vars.js | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/compress.js b/lib/compress.js index 91e3c388..44b27584 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -482,6 +482,10 @@ merge(Compressor.prototype, { def(AST_Arrow, mark_func_expr); def(AST_Assign, function(tw) { var node = this; + if (node.left instanceof AST_Destructuring) { + node.left.walk(suppressor); + return; + } if (node.operator != "=" || !(node.left instanceof AST_SymbolRef)) return; var d = node.left.definition(); if (safe_to_assign(tw, d, node.right) @@ -705,7 +709,7 @@ merge(Compressor.prototype, { var node = this; if (node.name instanceof AST_Destructuring) { node.name.walk(suppressor); - return true; + return; } var d = node.name.definition(); if (d.fixed === undefined || safe_to_assign(tw, d, node.value)) { diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js index f04f7c75..55ed3e01 100644 --- a/test/compress/reduce_vars.js +++ b/test/compress/reduce_vars.js @@ -5446,3 +5446,22 @@ issue_2598: { } expect_stdout: "true" } + +issue_2669: { + options = { + evaluate: true, + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + let foo; + console.log(([ foo ] = [ "PASS" ]) && foo); + } + expect: { + let foo; + console.log(([ foo ] = [ "PASS" ]) && foo); + } + expect_stdout: "PASS" + node_version: ">=6" +}