From 72805ea73a18a93793b0f3f5c64512a057d46e94 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Wed, 24 Feb 2021 21:31:12 +0000 Subject: [PATCH] fix corner case in `collapse_vars` (#4686) fixes #4685 --- lib/compress.js | 4 +++- test/compress/arrows.js | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/compress.js b/lib/compress.js index 5c38e407..ae96b764 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -2119,7 +2119,9 @@ merge(Compressor.prototype, { } arg = null; } - if (node instanceof AST_ObjectIdentity && (fn_strict || !tw.find_parent(AST_Scope))) { + if (node instanceof AST_ObjectIdentity && (fn_strict + || !tw.find_parent(AST_Scope) + || is_arrow(arg) && iife instanceof AST_New)) { arg = null; return true; } diff --git a/test/compress/arrows.js b/test/compress/arrows.js index 096503d6..a3a46871 100644 --- a/test/compress/arrows.js +++ b/test/compress/arrows.js @@ -703,3 +703,24 @@ issue_4666: { expect_stdout: "true" node_version: ">=4" } + +issue_4685: { + options = { + collapse_vars: true, + unused: true, + } + input: { + new function(f) { + if (f() !== this) + console.log("PASS"); + }(() => this); + } + expect: { + new function(f) { + if (f() !== this) + console.log("PASS"); + }(() => this); + } + expect_stdout: "PASS" + node_version: ">=4" +} -- 2.34.1