fix corner case in unused (#5339)

fixes #5338
This commit is contained in:
Alex Lam S.L
2022-02-03 23:13:23 +00:00
committed by GitHub
parent 9a91a7a4dc
commit b106cd9476
3 changed files with 39 additions and 6 deletions

View File

@@ -6943,13 +6943,16 @@ Compressor.prototype.compress = function(node) {
if (!drop_sym || !drop_vars || sym.id in in_use_ids) {
var index;
if (value && ((index = indexOf_assign(sym, def)) < 0 || self_assign(value.tail_node()))) {
value = value.drop_side_effect_free(compressor);
if (value) {
AST_Node.warn("Side effects in definition of variable {name} [{file}:{line},{col}]", template(def.name));
side_effects.push(value);
}
def = def.clone();
def.value = value = null;
value = value.drop_side_effect_free(compressor);
if (value) AST_Node.warn("Side effects in definition of variable {name} [{file}:{line},{col}]", template(def.name));
if (node instanceof AST_Const) {
def.value = value || make_node(AST_Number, def, { value: 0 });
} else {
def.value = null;
if (value) side_effects.push(value);
}
value = null;
if (index >= 0) assign_in_use[sym.id][index] = def;
}
var old_def, fn;