handle LHS side-effects on cascade & collapse_vars (#2314)

fixes #2313
This commit is contained in:
Alex Lam S.L
2017-09-16 11:45:19 +08:00
committed by GitHub
parent 182a47bfb1
commit 4f0953f7e9
4 changed files with 325 additions and 2 deletions

View File

@@ -561,6 +561,7 @@ merge(Compressor.prototype, {
});
function is_lhs_read_only(lhs) {
if (lhs instanceof AST_This) return true;
if (lhs instanceof AST_SymbolRef) return lhs.definition().orig[0] instanceof AST_SymbolLambda;
if (lhs instanceof AST_PropAccess) {
lhs = lhs.expression;
@@ -745,7 +746,7 @@ merge(Compressor.prototype, {
while (candidates.length > 0) {
var candidate = candidates.pop();
var lhs = get_lhs(candidate);
if (!lhs || is_lhs_read_only(lhs)) continue;
if (!lhs || is_lhs_read_only(lhs) || lhs.has_side_effects(compressor)) continue;
// Locate symbols which may execute code outside of scanning range
var lvalues = get_lvalues(candidate);
if (lhs instanceof AST_SymbolRef) lvalues[lhs.name] = false;
@@ -3496,7 +3497,7 @@ merge(Compressor.prototype, {
&& (left.operator == "++" || left.operator == "--")) {
left = left.expression;
} else left = null;
if (!left || is_lhs_read_only(left)) {
if (!left || is_lhs_read_only(left) || left.has_side_effects(compressor)) {
expressions[++i] = cdr;
continue;
}