Skip to content

Commit

Permalink
fix corner case in unused (#1718)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alexlamsl authored Mar 28, 2017
1 parent 6ab3224 commit eb48a03
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -1896,8 +1896,7 @@ merge(Compressor.prototype, {
if (def.value) def.value = def.value.transform(tt);
var sym = def.name.definition();
if (sym.id in in_use_ids) return true;
if (sym.orig[0] instanceof AST_SymbolCatch
&& sym.scope.parent_scope.find_variable(def.name).orig[0] === def.name) {
if (sym.orig[0] instanceof AST_SymbolCatch) {
def.value = def.value && def.value.drop_side_effect_free(compressor);
return true;
}
Expand Down
27 changes: 27 additions & 0 deletions test/compress/drop-unused.js
Original file line number Diff line number Diff line change
Expand Up @@ -931,3 +931,30 @@ issue_1715_3: {
}
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"
}

0 comments on commit eb48a03

Please sign in to comment.