Skip to content

Commit

Permalink
fix corner case in reduce_vars (#4211)
Browse files Browse the repository at this point in the history
fixes #4210
  • Loading branch information
alexlamsl committed Oct 13, 2020
1 parent 3096f6f commit 0e234a2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -6651,7 +6651,7 @@ merge(Compressor.prototype, {
var s = def.scope;
do {
s = s.parent_scope;
if (s.variables.has(node.name)) return false;
if (s.var_names()[node.name]) return false;
} while (s !== scope);
return true;
}) ? make_node(AST_Var, self, {
Expand Down
11 changes: 7 additions & 4 deletions lib/scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,13 @@ SymbolDef.prototype = {
redefined: function() {
var scope = this.defun;
if (!scope) return;
var def = scope.variables.get(this.name);
if (!def && scope instanceof AST_Toplevel) def = scope.globals.get(this.name);
if (!def || def === this) return;
return def.redefined() || def;
var name = this.name;
var def = scope.variables.get(name)
|| scope instanceof AST_Toplevel && scope.globals.get(name)
|| this.orig[0] instanceof AST_SymbolConst && find_if(function(def) {
return def.name == name;
}, scope.enclosed);
if (def && def !== this) return def.redefined() || def;
},
unmangleable: function(options) {
return this.global && !options.toplevel
Expand Down
33 changes: 33 additions & 0 deletions test/compress/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -930,3 +930,36 @@ issue_4207: {
}
expect_stdout: "0"
}

issue_4210: {
options = {
reduce_vars: true,
}
input: {
(function() {
try {
throw 42;
} catch (e) {
const a = typeof e;
console.log(a);
} finally {
return a = "foo";
}
})();
console.log(typeof a);
}
expect: {
(function() {
try {
throw 42;
} catch (e) {
const a = typeof e;
console.log(a);
} finally {
return a = "foo";
}
})();
console.log(typeof a);
}
expect_stdout: true
}

0 comments on commit 0e234a2

Please sign in to comment.