From 3652dce5d75a4b8443b4287209bb4a88554fc3ee Mon Sep 17 00:00:00 2001 From: bohanzh Date: Wed, 5 Oct 2022 18:50:45 +0800 Subject: [PATCH] fix: incorrect `to_simple_statement` (#1253) --- lib/compress/tighten-body.js | 2 +- test/compress/issue-1248.js | 67 ++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 test/compress/issue-1248.js diff --git a/lib/compress/tighten-body.js b/lib/compress/tighten-body.js index 18a3b734f..8142ff9c2 100644 --- a/lib/compress/tighten-body.js +++ b/lib/compress/tighten-body.js @@ -1236,7 +1236,7 @@ export function tighten_body(statements, compressor) { var line = block.body[i]; if (line instanceof AST_Var && declarations_only(line)) { decls.push(line); - } else if (stat) { + } else if (stat || line instanceof AST_Const || line instanceof AST_Let) { return false; } else { stat = line; diff --git a/test/compress/issue-1248.js b/test/compress/issue-1248.js new file mode 100644 index 000000000..7c0504aab --- /dev/null +++ b/test/compress/issue-1248.js @@ -0,0 +1,67 @@ +brackets_with_const: { + options = { + defaults: false, + }; + input: { + if (a) { + var b; + var c; + const d = d(); + const e = e(); + } + } + expect: { + if(a){var b;var c;const d=d();const e=e()} + } +} + +brackets_with_const_defaults: { + options = { + defaults: true, + }; + input: { + if (a) { + var b; + var c; + const d = d(); + const e = e(); + } + } + expect: { + if(a){var b,c;const d=d(),e=e()} + } +} + +brackets_with_const_let_mix_0: { + options = { + defaults: true, + }; + input: { + if (a) { + var b; + var c; + const d = d(); + let e = e(); + } + } + expect: { + if(a){var b,c;const d=d();let e=e()} + } +} + +brackets_with_const_let_mix_1: { + options = { + defaults: true, + }; + input: { + if (a) { + let b = b(); + var c; + var d; + const e = e(); + } + } + expect: { + if(a){let b=b();var c,d;const e=e()} + } +}