account for side-effects from AST_This in collapse_vars (#2365)

This commit is contained in:
Alex Lam S.L
2017-10-17 01:18:55 +08:00
committed by GitHub
parent dfe4f6c6de
commit fe647b083e
2 changed files with 56 additions and 2 deletions

View File

@@ -950,9 +950,11 @@ merge(Compressor.prototype, {
scope = save_scope; scope = save_scope;
return true; return true;
} }
if (node instanceof AST_SymbolRef || node instanceof AST_PropAccess) { if (node instanceof AST_PropAccess
|| node instanceof AST_SymbolRef
|| node instanceof AST_This) {
var sym = get_symbol(node); var sym = get_symbol(node);
if (sym instanceof AST_SymbolRef) { if (sym instanceof AST_SymbolRef || node instanceof AST_This) {
lvalues[sym.name] = lvalues[sym.name] || is_lhs(node, tw.parent()); lvalues[sym.name] = lvalues[sym.name] || is_lhs(node, tw.parent());
} }
} }

View File

@@ -2600,3 +2600,55 @@ prop_side_effects_2: {
"2", "2",
] ]
} }
issue_2364: {
options = {
collapse_vars: true,
pure_getters: true,
}
input: {
console.log(function(a) {
var b = a.f;
a.f++;
return b;
}({ f: 1 }));
console.log(function() {
var a = { f: 1 }, b = a.f;
a.f++;
return b;
}());
console.log({
f: 1,
g: function() {
var b = this.f;
this.f++;
return b;
}
}.g());
}
expect: {
console.log(function(a) {
var b = a.f;
a.f++;
return b;
}({ f: 1 }));
console.log(function() {
var a = { f: 1 }, b = a.f;
a.f++;
return b;
}());
console.log({
f: 1,
g: function() {
var b = this.f;
this.f++;
return b;
}
}.g());
}
expect_stdout: [
"1",
"1",
"1",
]
}