account for side-effects from AST_This in collapse_vars (#2365)
This commit is contained in:
@@ -950,9 +950,11 @@ merge(Compressor.prototype, {
|
||||
scope = save_scope;
|
||||
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);
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2600,3 +2600,55 @@ prop_side_effects_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",
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user