From 42e34c870ad5979135ab7407ab62abce9507fc28 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Mon, 16 Nov 2020 18:06:00 +0000 Subject: fix corner case in `unused` (#4277) fixes #4276 --- lib/compress.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'lib/compress.js') diff --git a/lib/compress.js b/lib/compress.js index 97252f7f..9eb4a9e8 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -5032,7 +5032,7 @@ merge(Compressor.prototype, { } } var old_def, var_defs = var_defs_by_id.get(sym.id); - if (!def.value) { + if (!def.value && !(node instanceof AST_Let)) { if (var_defs.length > 1) { AST_Node.info("Dropping declaration of variable {name} [{file}:{line},{col}]", template(def.name)); remove(var_defs, def); @@ -5071,13 +5071,18 @@ merge(Compressor.prototype, { duplicated++; } if (side_effects.length > 0) { - if (tail.length > 0) { - side_effects.push(def.value); - def.value = make_sequence(def.value, side_effects); - } else { + if (tail.length == 0) { body.push(make_node(AST_SimpleStatement, node, { body: make_sequence(node, side_effects) })); + } else if (def.value) { + side_effects.push(def.value); + def.value = make_sequence(def.value, side_effects); + } else { + def.value = make_node(AST_UnaryPrefix, def, { + operator: "void", + expression: make_sequence(def, side_effects) + }); } side_effects = []; } -- cgit v1.2.3