From 224c91b6c1bea47e152c31994247e119089b92ae Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Sat, 2 Apr 2022 18:12:53 +0100 Subject: [PATCH] fix corner case in `inline` (#5402) fixes #5401 --- lib/compress.js | 6 ++++++ test/compress/functions.js | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/lib/compress.js b/lib/compress.js index e34b1d3a..1998311f 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -13508,6 +13508,12 @@ Compressor.prototype.compress = function(node) { def(AST_LabeledStatement, function(compressor, scope, no_return, in_loop) { var body = this.body.try_inline(compressor, scope, no_return, in_loop); if (!body) return; + if (this.body instanceof AST_IterationStatement && body instanceof AST_BlockStatement) { + var loop = body.body.pop(); + this.body = loop; + body.body.push(this); + return body; + } this.body = body; return this; }); diff --git a/test/compress/functions.js b/test/compress/functions.js index 02f90f9b..79be3969 100644 --- a/test/compress/functions.js +++ b/test/compress/functions.js @@ -8350,3 +8350,23 @@ issue_5376_2: { } expect_stdout: Error("PASS") } + +issue_5401: { + options = { + inline: true, + } + input: { + L: for (var a in function() { + while (console.log("PASS")); + }(), a) do { + continue L; + } while (console.log("FAIL")); + } + expect: { + while (console.log("PASS")); + L: for (var a in a) do { + continue L; + } while (console.log("FAIL")); + } + expect_stdout: "PASS" +}