From aef70652620741e6312ab8b99ea38d894cf999a2 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Wed, 23 Nov 2022 01:26:08 +0200 Subject: [PATCH] fix corner case in `inline` (#5742) fixes #5741 --- lib/compress.js | 1 + test/compress/let.js | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/lib/compress.js b/lib/compress.js index f426cf028d5..494f9db16b4 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -11160,6 +11160,7 @@ Compressor.prototype.compress = function(node) { function append_var(decls, expressions, name, value) { var def = name.definition(); if (!scope.var_names().has(name.name)) { + if (def.first_decl === name) def.first_decl = null; scope.var_names().set(name.name, true); decls.push(make_node(AST_VarDef, name, { name: name, diff --git a/test/compress/let.js b/test/compress/let.js index 69d0d370b6e..7e5185c987c 100644 --- a/test/compress/let.js +++ b/test/compress/let.js @@ -2294,3 +2294,37 @@ issue_5591: { ] node_version: ">=4" } + +issue_5741: { + options = { + inline: true, + join_vars: true, + reduce_vars: true, + } + input: { + "use strict"; + (function(a) { + let b = function() { + var c = a; + console.log(c); + }(); + function g() { + a++; + b; + } + })("PASS"); + } + expect: { + "use strict"; + (function(a) { + let b = (c = a, void console.log(c)); + var c; + function g() { + a++; + b; + } + })("PASS"); + } + expect_stdout: "PASS" + node_version: ">=4" +}