fix missing corner case in #2855 (#2868)

This commit is contained in:
Alex Lam S.L
2018-02-02 18:08:56 +08:00
committed by GitHub
parent 334b07a3db
commit b16380d669
2 changed files with 29 additions and 3 deletions

View File

@@ -1044,13 +1044,15 @@ merge(Compressor.prototype, {
// but are otherwise not safe to scan into or beyond them.
var sym;
if (node instanceof AST_Call
|| node instanceof AST_Exit
&& (side_effects || lhs instanceof AST_PropAccess || may_modify(lhs))
|| node instanceof AST_PropAccess
&& (side_effects || node.expression.may_throw_on_access(compressor))
|| node instanceof AST_SymbolRef
&& !(parent instanceof AST_Assign && parent.operator == "=" && parent.left === node)
&& (lvalues[node.name] || may_modify(node))
&& (lvalues[node.name] || side_effects && may_modify(node))
|| node instanceof AST_VarDef && node.value
&& (node.name.name in lvalues || may_modify(node.name))
&& (node.name.name in lvalues || side_effects && may_modify(node.name))
|| (sym = is_lhs(node.left, node))
&& (sym instanceof AST_PropAccess || sym.name in lvalues)
|| may_throw
@@ -1356,7 +1358,6 @@ merge(Compressor.prototype, {
}
function may_modify(sym) {
if (!side_effects) return false;
var def = sym.definition();
if (def.orig.length == 1 && def.orig[0] instanceof AST_SymbolDefun) return false;
if (def.scope !== scope) return true;

View File

@@ -4191,6 +4191,31 @@ return_3: {
expect_stdout: "0"
}
return_4: {
options = {
collapse_vars: true,
}
input: {
var a = "FAIL";
(function(b) {
a = "PASS";
return;
b(a);
})();
console.log(a);
}
expect: {
var a = "FAIL";
(function(b) {
a = "PASS";
return;
b(a);
})();
console.log(a);
}
expect_stdout: "PASS"
}
issue_2858: {
options = {
collapse_vars: true,