fix corner case in unused (#4767)

fixes #4766
This commit is contained in:
Alex Lam S.L
2021-03-13 07:09:07 +00:00
committed by GitHub
parent 3b5d5014e0
commit 6f3ab09319
2 changed files with 18 additions and 1 deletions

View File

@@ -6216,7 +6216,10 @@ merge(Compressor.prototype, {
});
body.push(defun);
} else {
if (drop_sym && var_defs[sym.id] > 1 && sym.orig.indexOf(def.name) > sym.eliminated) {
if (drop_sym
&& var_defs[sym.id] > 1
&& !(parent instanceof AST_ExportDeclaration)
&& sym.orig.indexOf(def.name) > sym.eliminated) {
var_defs[sym.id]--;
duplicated++;
}

View File

@@ -464,3 +464,17 @@ issue_4761: {
}
expect_exact: 'export default"function"==42;'
}
issue_4766: {
options = {
unused: true,
}
input: {
var a = "foo";
export var a = "bar";
}
expect: {
var a = "foo";
export var a = "bar";
}
}