diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-11-16 18:06:00 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-17 02:06:00 +0800 |
commit | 42e34c870ad5979135ab7407ab62abce9507fc28 (patch) | |
tree | 2465b3c694049962454944d6d7d35aea7bb82805 /lib/compress.js | |
parent | e390e7e12467ec1dd204245212aea9f811763439 (diff) | |
download | tracifyjs-42e34c870ad5979135ab7407ab62abce9507fc28.tar.gz tracifyjs-42e34c870ad5979135ab7407ab62abce9507fc28.zip |
fix corner case in `unused` (#4277)
fixes #4276
Diffstat (limited to 'lib/compress.js')
-rw-r--r-- | lib/compress.js | 15 |
1 files changed, 10 insertions, 5 deletions
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 = []; } |