From b1279a46d9801bbc3eee8c4ea90422dd7582b928 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Thu, 17 Oct 2019 09:57:50 +0800 Subject: [PATCH] fix corner case in `sequences` (#3491) fixes #3490 --- lib/compress.js | 4 +-- test/compress/sequences.js | 63 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 2 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index c903d9af..e39435c7 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -2030,14 +2030,14 @@ merge(Compressor.prototype, { n--; CHANGED = true; var left = prev.body; - return make_sequence(left, [ left, right ]).transform(compressor); + return make_sequence(left, [ left, right ]); } var n = 0, prev; for (var i = 0; i < statements.length; i++) { var stat = statements[i]; if (prev) { if (stat instanceof AST_Exit) { - stat.value = cons_seq(stat.value || make_node(AST_Undefined, stat).transform(compressor)); + stat.value = cons_seq(stat.value || make_node(AST_Undefined, stat)).transform(compressor); } else if (stat instanceof AST_For) { if (!(stat.init instanceof AST_Definitions)) { var abort = false; diff --git a/test/compress/sequences.js b/test/compress/sequences.js index 08a06790..fbca559a 100644 --- a/test/compress/sequences.js +++ b/test/compress/sequences.js @@ -1006,3 +1006,66 @@ angularjs_chain: { } } } + +issue_3490_1: { + options = { + conditionals: true, + dead_code: true, + inline: true, + sequences: true, + side_effects: true, + toplevel: true, + } + input: { + var b = 42, c = "FAIL"; + if ({ + 3: function() { + var a; + return (a && a.p) < this; + }(), + }) c = "PASS"; + if (b) while ("" == typeof d); + console.log(c, b); + } + expect: { + var b = 42, c = "FAIL"; + if (function() { + var a; + a && a.p; + }(), c = "PASS", b) while ("" == typeof d); + console.log(c, b); + } + expect_stdout: "PASS 42" +} + +issue_3490_2: { + options = { + conditionals: true, + dead_code: true, + evaluate: true, + inline: true, + reduce_vars: true, + sequences: true, + side_effects: true, + toplevel: true, + } + input: { + var b = 42, c = "FAIL"; + if ({ + 3: function() { + var a; + return (a && a.p) < this; + }(), + }) c = "PASS"; + if (b) for (; "" == typeof d;); + console.log(c, b); + } + expect: { + var b = 42, c = "FAIL"; + for (function() { + var a; + }(), c = "PASS", b; "" == typeof d;); + console.log(c, b); + } + expect_stdout: "PASS 42" +} -- 2.34.1