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

View File

@@ -2465,6 +2465,68 @@ issue_2203_2: {
expect_stdout: "PASS" 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: { duplicate_argname: {
options = { options = {
collapse_vars: true, collapse_vars: true,