handle AST_SymbolFunarg

This commit is contained in:
alexlamsl 2017-11-02 18:59:01 +08:00
parent 68d3a1718d
commit 8334f86f30
2 changed files with 51 additions and 4 deletions

View File

@ -4217,9 +4217,10 @@ merge(Compressor.prototype, {
if (fixed && d.should_replace === undefined) {
var init;
if (fixed instanceof AST_This) {
if (all(d.references, function(ref) {
return d.scope === ref.scope;
})) {
if (!(d.orig[0] instanceof AST_SymbolFunarg)
&& all(d.references, function(ref) {
return d.scope === ref.scope;
})) {
init = fixed;
}
} else {

View File

@ -3296,7 +3296,7 @@ escaped_prop: {
expect_stdout: "2"
}
issue_2420: {
issue_2420_1: {
options = {
reduce_vars: true,
unused: true,
@ -3337,3 +3337,49 @@ issue_2420: {
"foo",
]
}
issue_2420_2: {
options = {
reduce_vars: true,
unused: true,
}
input: {
function f() {
var t = this;
if (t.bar)
t.foo();
else
!function(t) {
console.log(this === t);
}(this);
}
var o = {
bar: 1,
foo: function() { console.log("foo", this.bar); },
};
f.call(o);
o.bar = 0;
f.call(o);
}
expect: {
function f() {
if (this.bar)
this.foo();
else
!function(t) {
console.log(this === t);
}(this);
}
var o = {
bar: 1,
foo: function() { console.log("foo", this.bar); },
};
f.call(o);
o.bar = 0;
f.call(o);
}
expect_stdout: [
"foo 1",
"false",
]
}