fix corner case in merge_vars (#4170)

fixes #4168
This commit is contained in:
Alex Lam S.L
2020-10-03 00:03:39 +01:00
committed by GitHub
parent baf4903aa7
commit 8cb509d50e
2 changed files with 87 additions and 1 deletions

View File

@@ -4406,7 +4406,12 @@ merge(Compressor.prototype, {
push();
segment.block = node;
if (node === self) root = segment;
if (node instanceof AST_Lambda && node.name) references[node.name.definition().id] = false;
if (node instanceof AST_Lambda) {
if (node.name) references[node.name.definition().id] = false;
if (node.uses_arguments && !tw.has_directive("use strict")) node.argnames.forEach(function(node) {
references[node.definition().id] = false;
});
}
descend();
pop();
return true;
@@ -4474,6 +4479,7 @@ merge(Compressor.prototype, {
return true;
}
});
tw.directives = Object.create(compressor.directives);
self.walk(tw);
var merged = Object.create(null);
while (first.length && last.length) {

View File

@@ -2928,3 +2928,83 @@ issue_4157_2: {
}
expect_stdout: "undefined"
}
issue_4168: {
options = {
merge_vars: true,
}
input: {
var o = {
f: function(a, b, c) {
var d = a.d;
var e = b.e;
var f = c.f;
this.g(arguments);
if (d)
console.log(e, f);
},
g: function(args) {
console.log(args[0], args[1], args[2]);
},
};
o.f("PASS", true, 42);
}
expect: {
var o = {
f: function(a, b, c) {
var d = a.d;
var e = b.e;
var f = c.f;
this.g(arguments);
if (d)
console.log(e, f);
},
g: function(args) {
console.log(args[0], args[1], args[2]);
},
};
o.f("PASS", true, 42);
}
expect_stdout: "PASS true 42"
}
issue_4168_use_strict: {
options = {
merge_vars: true,
}
input: {
"use strict";
var o = {
f: function(a, b, c) {
var d = a.d;
var e = b.e;
var f = c.f;
this.g(arguments);
if (d)
console.log(e, f);
},
g: function(args) {
console.log(args[0], args[1], args[2]);
},
};
o.f("PASS", true, 42);
}
expect: {
"use strict";
var o = {
f: function(d, e, f) {
var d = d.d;
var e = e.e;
var f = f.f;
this.g(arguments);
if (d)
console.log(e, f);
},
g: function(args) {
console.log(args[0], args[1], args[2]);
},
};
o.f("PASS", true, 42);
}
expect_stdout: "PASS true 42"
}