handle AST_Arrow IIFEs in collapse_vars

This commit is contained in:
alexlamsl
2017-07-08 14:27:06 +08:00
parent 2539fb8096
commit ef63de6968
2 changed files with 73 additions and 5 deletions

View File

@@ -850,8 +850,8 @@ merge(Compressor.prototype, {
}
function has_overlapping_symbol(fn, arg) {
var found = false;
var tw = new TreeWalker(function(node) {
var found = false, scan_this = !(fn instanceof AST_Arrow);
arg.walk(new TreeWalker(function(node, descend) {
if (found) return true;
if (node instanceof AST_SymbolRef && fn.variables.has(node.name)) {
var s = node.definition().scope;
@@ -860,11 +860,17 @@ merge(Compressor.prototype, {
}
return found = true;
}
if (node instanceof AST_This && !tw.find_parent(AST_Scope)) {
if (scan_this && node instanceof AST_This) {
return found = true;
}
});
arg.walk(tw);
if (node instanceof AST_Scope && !(node instanceof AST_Arrow)) {
var prev = scan_this;
scan_this = false;
descend();
scan_this = prev;
return true;
}
}));
return found;
}

View File

@@ -2465,6 +2465,68 @@ issue_2203_2: {
expect_stdout: "PASS"
}
issue_2203_3: {
options = {
collapse_vars: true,
unused: true,
}
input: {
a = "FAIL";
console.log({
a: "PASS",
b: function() {
return function(c) {
return c.a;
}((String, (Object, (() => this)())));
}
}.b());
}
expect: {
a = "FAIL";
console.log({
a: "PASS",
b: function() {
return function(c) {
return c.a;
}((String, (Object, (() => this)())));
}
}.b());
}
expect_stdout: "PASS"
node_version: ">=4"
}
issue_2203_4: {
options = {
collapse_vars: true,
unused: true,
}
input: {
a = "FAIL";
console.log({
a: "PASS",
b: function() {
return (c => {
return c.a;
})((String, (Object, (() => this)())));
}
}.b());
}
expect: {
a = "FAIL";
console.log({
a: "PASS",
b: function() {
return (c => {
return (String, (Object, (() => this)())).a;
})();
}
}.b());
}
expect_stdout: "PASS"
node_version: ">=4"
}
duplicate_argname: {
options = {
collapse_vars: true,