diff --git a/lib/compress.js b/lib/compress.js index 196f2445..d8baa603 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -6830,8 +6830,8 @@ Compressor.prototype.compress = function(node) { unused_fn_names.push(node); } if (!(node instanceof AST_Accessor)) { - var args, spread; - if (parent instanceof AST_Call && parent.expression === node) { + var args, spread, trim = compressor.drop_fargs(node, parent); + if (trim && parent instanceof AST_Call && parent.expression === node) { args = parent.args; for (spread = 0; spread < args.length; spread++) { if (args[spread] instanceof AST_Spread) break; @@ -6861,8 +6861,8 @@ Compressor.prototype.compress = function(node) { } } node.rest = rest; + if (rest) trim = false; } - var trim = compressor.drop_fargs(node, parent) && !node.rest; var default_length = trim ? -1 : node.length(); for (var i = argnames.length; --i >= 0;) { var sym = argnames[i]; diff --git a/test/compress/default-values.js b/test/compress/default-values.js index b73d6416..9f3620a3 100644 --- a/test/compress/default-values.js +++ b/test/compress/default-values.js @@ -2007,6 +2007,7 @@ issue_5192: { issue_5246_1: { options = { + keep_fargs: false, pure_getters: true, unused: true, } @@ -2016,20 +2017,20 @@ issue_5246_1: { }("foo")); } expect: { - console.log(function({} = 0) { + console.log(function() { return "PASS"; - }("foo")); + }()); } expect_stdout: "PASS" expect_warnings: [ - "INFO: Dropping unused default argument value {}=42 [test/compress/default-values.js:1,29]", - "INFO: Dropping unused default argument value {}=0 [test/compress/default-values.js:1,29]", + "INFO: Dropping unused default argument {}=42 [test/compress/default-values.js:1,29]", ] node_version: ">=6" } issue_5246_2: { options = { + keep_fargs: false, unused: true, } input: { @@ -2038,9 +2039,9 @@ issue_5246_2: { })("PASS", []); } expect: { - (function(a = "FAIL", []) { + (function(a = "FAIL") { console.log(a); - })("PASS", []); + })("PASS"); } expect_stdout: "PASS" node_version: ">=6" @@ -2049,6 +2050,7 @@ issue_5246_2: { issue_5246_3: { options = { default_values: true, + keep_fargs: false, unused: true, } input: { @@ -2121,3 +2123,28 @@ issue_5314_2: { expect_stdout: "PASS" node_version: ">=6" } + +issue_5336: { + options = { + default_values: true, + unused: true, + } + input: { + var a; + do { + (function f(b = console.log("PASS")) { + a = f; + })(42); + } while (a()); + } + expect: { + var a; + do { + (function f(b = console.log("PASS")) { + a = f; + })(42); + } while (a()); + } + expect_stdout: "PASS" + node_version: ">=6" +} diff --git a/test/compress/destructured.js b/test/compress/destructured.js index 4b21ff29..5c0e9654 100644 --- a/test/compress/destructured.js +++ b/test/compress/destructured.js @@ -1130,7 +1130,7 @@ drop_unused_2: { } f(); } - expect:{ + expect: { (function(a) { console.log("PASS"); })(); @@ -3406,6 +3406,7 @@ issue_5288: { options = { conditionals: true, inline: true, + keep_fargs: false, reduce_vars: true, toplevel: true, unused: true, @@ -3421,7 +3422,7 @@ issue_5288: { }() ])); } expect: { - while ([ [ console ? console.log("PASS") : 0 ] ], void 0); + while (console ? console.log("PASS") : 0, void 0); } expect_stdout: "PASS" node_version: ">=6" diff --git a/test/compress/rests.js b/test/compress/rests.js index 9a32bcce..5a79d5c1 100644 --- a/test/compress/rests.js +++ b/test/compress/rests.js @@ -349,6 +349,7 @@ retain_funarg_destructured_object_1: { retain_funarg_destructured_object_2: { options = { + keep_fargs: false, unused: true, } input: { @@ -1091,6 +1092,7 @@ issue_5100_2: { issue_5108: { options = { evaluate: true, + keep_fargs: false, reduce_vars: true, rests: true, unsafe: true, @@ -1102,9 +1104,7 @@ issue_5108: { }([ "PASS", "FAIL" ])); } expect: { - console.log(function([]) { - return "PASS"; - }([])); + console.log("PASS"); } expect_stdout: "PASS" node_version: ">=6" @@ -1208,6 +1208,7 @@ issue_5165_2: { issue_5246_1: { options = { + keep_fargs: false, reduce_vars: true, rests: true, unused: true, @@ -1218,9 +1219,9 @@ issue_5246_1: { }([ , function(){} ])[0]); } expect: { - console.log(typeof function([]) { + console.log(typeof function() { return this && [ function(){} ]; - }([])[0]); + }()[0]); } expect_stdout: "function" node_version: ">=6" @@ -1228,6 +1229,7 @@ issue_5246_1: { issue_5246_2: { options = { + keep_fargs: false, reduce_vars: true, rests: true, toplevel: true, @@ -1249,6 +1251,7 @@ issue_5246_2: { issue_5246_3: { options = { + keep_fargs: false, unused: true, } input: { diff --git a/test/compress/yields.js b/test/compress/yields.js index 39a4eca9..07b8e443 100644 --- a/test/compress/yields.js +++ b/test/compress/yields.js @@ -1375,6 +1375,7 @@ issue_5076_1: { options = { evaluate: true, hoist_vars: true, + keep_fargs: false, pure_getters: "strict", sequences: true, side_effects: true, @@ -1404,6 +1405,7 @@ issue_5076_2: { options = { evaluate: true, hoist_vars: true, + keep_fargs: false, passes: 2, pure_getters: "strict", sequences: true, diff --git a/test/mocha/awaits.js b/test/mocha/awaits.js index d4e96609..f25c9f25 100644 --- a/test/mocha/awaits.js +++ b/test/mocha/awaits.js @@ -7,7 +7,7 @@ describe("async", function() { "function await() {}", "function(await) {}", "function() { await; }", - "function() { await:{} }", + "function() { await: {} }", "function() { var await; }", "function() { function await() {} }", "function() { try {} catch (await) {} }", diff --git a/test/mocha/yields.js b/test/mocha/yields.js index d995d61d..e93d65ee 100644 --- a/test/mocha/yields.js +++ b/test/mocha/yields.js @@ -6,7 +6,7 @@ describe("generator", function() { [ "function yield() {}", "function(yield) {}", - "function() { yield:{} }", + "function() { yield: {} }", "function() { var yield; }", "function() { function yield() {} }", "function() { try {} catch (yield) {} }",