fix corner case in reduce_vars (#3510)

fixes #3509
This commit is contained in:
Alex Lam S.L
2019-10-22 20:36:05 +08:00
committed by GitHub
parent 0b3705e82f
commit 02308a7b56
2 changed files with 29 additions and 3 deletions

View File

@@ -292,9 +292,7 @@ AST_Scope.DEFMETHOD("def_variable", function(symbol, init) {
var def = this.variables.get(symbol.name); var def = this.variables.get(symbol.name);
if (def) { if (def) {
def.orig.push(symbol); def.orig.push(symbol);
if (def.init && (def.scope !== symbol.scope || def.init instanceof AST_Function)) { if (def.init instanceof AST_Function) def.init = init;
def.init = init;
}
} else { } else {
def = new SymbolDef(this, symbol, init); def = new SymbolDef(this, symbol, init);
this.variables.set(symbol.name, def); this.variables.set(symbol.name, def);

View File

@@ -6752,3 +6752,31 @@ issue_3377: {
} }
expect_stdout: "42" 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"
}