From cc764299e01b3368077d87ff19591f08bc095d19 Mon Sep 17 00:00:00 2001 From: alexlamsl Date: Sun, 29 Sep 2024 00:14:58 +0300 Subject: [PATCH] fix corner case in `dead_code` fixes #5941 --- lib/compress.js | 4 ++-- test/compress/dead-code.js | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index 831050c9ef..e33a297c54 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -13141,8 +13141,8 @@ Compressor.prototype.compress = function(node) { var scope = def.scope.resolve(); var local = scope === compressor.find_parent(AST_Lambda); var level = 0, node; - parent = compressor.self(); - if (!(scope.uses_arguments && is_funarg(def)) || compressor.has_directive("use strict")) do { + if ((compressor.has_directive("use strict") || !(scope.uses_arguments && is_funarg(def))) + && (parent = compressor.self()) === self) do { node = parent; parent = compressor.parent(level++); if (parent instanceof AST_Assign) { diff --git a/test/compress/dead-code.js b/test/compress/dead-code.js index 3a49eb0c11..2868013c83 100644 --- a/test/compress/dead-code.js +++ b/test/compress/dead-code.js @@ -1776,3 +1776,20 @@ issue_5882_3: { } expect_stdout: "true" } + +issue_5941: { + options = { + assignments: true, + conditionals: true, + dead_code: true, + } + input: { + var a = 1; + a = a &&= (a = console) && console.log(typeof a); + } + expect: { + var a = 1; + a = (a = a && console) && console.log(typeof a); + } + expect_stdout: "object" +}