From b371dc2d1ed523e9a8b38ef4eb5826fa0fdfcf05 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Sat, 23 Jul 2022 00:18:26 +0100 Subject: [PATCH] fix corner case in `collapse_vars` (#5574) fixes #5573 --- lib/compress.js | 3 ++- test/compress/destructured.js | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/compress.js b/lib/compress.js index a1e6497a..7819414b 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -2593,7 +2593,8 @@ Compressor.prototype.compress = function(node) { if (value instanceof AST_Array) return !all(node.elements, function(element, index) { return !arg_may_throw(reject, element, value[index]); }); - return value.is_string(compressor) && !all(node.elements, function(element) { + if (!value.is_string(compressor)) return true; + return !all(node.elements, function(element) { return !arg_may_throw(reject, element); }); } diff --git a/test/compress/destructured.js b/test/compress/destructured.js index 4cef240b..81640318 100644 --- a/test/compress/destructured.js +++ b/test/compress/destructured.js @@ -3817,3 +3817,30 @@ issue_5533_drop_fargs: { expect_stdout: "PASS" node_version: ">=6" } + +issue_5573: { + options = { + collapse_vars: true, + } + input: { + var log = console.log; + var a = "FAIL"; + (function([ { [log(a)]: b } ]) { + A = 42; + })((a = "PASS", [ {} ])); + log(a, A); + } + expect: { + var log = console.log; + var a = "FAIL"; + (function([ { [log(a)]: b } ]) { + A = 42; + })((a = "PASS", [ {} ])); + log(a, A); + } + expect_stdout: [ + "PASS", + "PASS 42", + ] + node_version: ">=6" +}