Skip to content

Commit

Permalink
fix corner case in reduce_vars (#3510)
Browse files Browse the repository at this point in the history
fixes #3509
  • Loading branch information
alexlamsl committed Oct 22, 2019
1 parent 0b3705e commit 02308a7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
4 changes: 1 addition & 3 deletions lib/scope.js
Expand Up @@ -292,9 +292,7 @@ AST_Scope.DEFMETHOD("def_variable", function(symbol, init) {
var def = this.variables.get(symbol.name);
if (def) {
def.orig.push(symbol);
if (def.init && (def.scope !== symbol.scope || def.init instanceof AST_Function)) {
def.init = init;
}
if (def.init instanceof AST_Function) def.init = init;
} else {
def = new SymbolDef(this, symbol, init);
this.variables.set(symbol.name, def);
Expand Down
28 changes: 28 additions & 0 deletions test/compress/reduce_vars.js
Expand Up @@ -6752,3 +6752,31 @@ issue_3377: {
}
expect_stdout: "42"
}

issue_3509: {
options = {
reduce_vars: true,
toplevel: true,
unused: true,
}
input: {
function a() {
console.log("PASS");
}
try {
} catch (a) {
var a;
}
a();
}
expect: {
try {
} catch (a) {
var a;
}
(function() {
console.log("PASS");
})();
}
expect_stdout: "PASS"
}

0 comments on commit 02308a7

Please sign in to comment.