fix corner case in unused (#1718)
When fixing catch-related issue in #1715, it tries to optimise for duplicate definitions but did not take anonymous functions into account. Remove such optimisation for now and we can cover this as a more general rule later.
This commit is contained in:
@@ -1896,8 +1896,7 @@ merge(Compressor.prototype, {
|
|||||||
if (def.value) def.value = def.value.transform(tt);
|
if (def.value) def.value = def.value.transform(tt);
|
||||||
var sym = def.name.definition();
|
var sym = def.name.definition();
|
||||||
if (sym.id in in_use_ids) return true;
|
if (sym.id in in_use_ids) return true;
|
||||||
if (sym.orig[0] instanceof AST_SymbolCatch
|
if (sym.orig[0] instanceof AST_SymbolCatch) {
|
||||||
&& sym.scope.parent_scope.find_variable(def.name).orig[0] === def.name) {
|
|
||||||
def.value = def.value && def.value.drop_side_effect_free(compressor);
|
def.value = def.value && def.value.drop_side_effect_free(compressor);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -931,3 +931,30 @@ issue_1715_3: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "1"
|
expect_stdout: "1"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_1715_4: {
|
||||||
|
options = {
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 1;
|
||||||
|
!function a() {
|
||||||
|
a++;
|
||||||
|
try {} catch (a) {
|
||||||
|
var a;
|
||||||
|
}
|
||||||
|
}();
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = 1;
|
||||||
|
!function() {
|
||||||
|
a++;
|
||||||
|
try {} catch (a) {
|
||||||
|
var a;
|
||||||
|
}
|
||||||
|
}();
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_stdout: "1"
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user