diff --git a/lib/compress.js b/lib/compress.js index 79a507fe..3500ed87 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -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; } diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js index 7fe337d2..bd580541 100644 --- a/test/compress/collapse_vars.js +++ b/test/compress/collapse_vars.js @@ -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,