From e374b7990522ebfc295d6fef62a330c5b4ec1793 Mon Sep 17 00:00:00 2001 From: alexlamsl Date: Wed, 21 Aug 2024 14:12:17 +0300 Subject: [PATCH] fix corner case in `collapse_vars` fixes #5924 fixes #5925 --- lib/compress.js | 1 + test/compress/functions.js | 65 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/lib/compress.js b/lib/compress.js index 19b7256049..0fea284d93 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -3409,6 +3409,7 @@ Compressor.prototype.compress = function(node) { var find_arguments = scope.uses_arguments && !compressor.has_directive("use strict"); var scan_toplevel = scope instanceof AST_Toplevel; var tw = new TreeWalker(function(node) { + if (node.inlined_node) node.inlined_node.walk(tw); var value; if (node instanceof AST_SymbolRef) { value = node.fixed_value(); diff --git a/test/compress/functions.js b/test/compress/functions.js index d900d32809..c8b5b532c1 100644 --- a/test/compress/functions.js +++ b/test/compress/functions.js @@ -9076,3 +9076,68 @@ issue_5895_2: { "foo", ] } + +issue_5924: { + options = { + collapse_vars: true, + inline: true, + reduce_vars: true, + toplevel: true, + } + input: { + var a = 42; + function f() { + return a - 41; + } + function g() { + return f; + } + var b = f(); + a--; + console.log(b ? "PASS" : "FAIL"); + } + expect: { + var a = 42; + function f() { + return a - 41; + } + function g() { + return f; + } + var b = f(); + a--; + console.log(b ? "PASS" : "FAIL"); + } + expect_stdout: "PASS" +} + +issue_5925: { + options = { + collapse_vars: true, + inline: true, + reduce_vars: true, + } + input: { + var a = 42; + console.log(function() { + function f() { + return +a - 41; + } + var b = f(f); + a--; + return b; + }() ? "PASS" : "FAIL"); + } + expect: { + var a = 42; + console.log(function() { + function f() { + return +a - 41; + } + var b = f(f); + a--; + return b; + }() ? "PASS" : "FAIL"); + } + expect_stdout: "PASS" +}