From 2619bff3cf71bbb4be9b0178272af72b42878496 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Mon, 15 Mar 2021 04:44:41 +0000 Subject: [PATCH] fix corner case in `conditionals` (#4777) --- lib/compress.js | 1 + test/compress/spreads.js | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/compress.js b/lib/compress.js index 3830f0db78..bdd3c94876 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -11044,6 +11044,7 @@ merge(Compressor.prototype, { if (len != b.length) return -2; for (var i = 0; i < len; i++) { if (!a[i].equivalent_to(b[i])) { + if (a[i] instanceof AST_Spread !== b[i] instanceof AST_Spread) return -3; for (var j = i + 1; j < len; j++) { if (!a[j].equivalent_to(b[j])) return -2; } diff --git a/test/compress/spreads.js b/test/compress/spreads.js index a3a70035fa..ba10167a60 100644 --- a/test/compress/spreads.js +++ b/test/compress/spreads.js @@ -85,7 +85,7 @@ collapse_vars_4: { node_version: ">=6" } -conditionals_farg: { +conditionals_farg_1: { options = { conditionals: true, } @@ -107,6 +107,28 @@ conditionals_farg: { node_version: ">=6" } +conditionals_farg_2: { + options = { + conditionals: true, + pure_getters: "strict", + reduce_vars: true, + } + input: { + var log = console.log; + (function(a) { + return a.length ? log(...a) : log("FAIL"); + })([ "PASS" ]); + } + expect: { + var log = console.log; + (function(a) { + return a.length ? log(...a) : log("FAIL"); + })([ "PASS" ]); + } + expect_stdout: "PASS" + node_version: ">=6" +} + dont_inline: { options = { inline: true,