From 9fe7e63818fe9f5b75fdadcb71e4fd079dc34c0c Mon Sep 17 00:00:00 2001 From: alexlamsl Date: Tue, 21 May 2019 11:36:52 +0800 Subject: [PATCH] fix corner case in `keep_fargs` fixes #3423 --- lib/compress.js | 2 +- test/compress/keep_fargs.js | 38 +++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/lib/compress.js b/lib/compress.js index e1f0105c3e..e99ce50888 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -108,7 +108,7 @@ function Compressor(options, false_by_default) { this.drop_fargs = keep_fargs == "strict" ? function(lambda, parent) { if (lambda.length_read) return false; var name = lambda.name; - if (!name) return parent && parent.TYPE == "Call"; + if (!name) return parent && parent.TYPE == "Call" && parent.expression === lambda; if (name.fixed_value() !== lambda) return false; var def = name.definition(); if (def.direct_access) return false; diff --git a/test/compress/keep_fargs.js b/test/compress/keep_fargs.js index 558b10bbb7..74b801d360 100644 --- a/test/compress/keep_fargs.js +++ b/test/compress/keep_fargs.js @@ -1117,3 +1117,41 @@ issue_3420_3: { } expect_stdout: "4" } + +issue_3423_1: { + options = { + keep_fargs: "strict", + unused: true, + } + input: { + function f(g) { + console.log(g.length); + } + f(function(a) {}); + } + expect: { + function f(g) { + console.log(g.length); + } + f(function(a) {}); + } + expect_stdout: "1" +} + +issue_3423_2: { + options = { + keep_fargs: "strict", + unused: true, + } + input: { + new function(a) { + console.log(this.constructor.length); + }(); + } + expect: { + new function(a) { + console.log(this.constructor.length); + }(); + } + expect_stdout: "1" +}