From ea9328d77268a69d1f7955ab7693b12a385def44 Mon Sep 17 00:00:00 2001 From: gdh1995 Date: Mon, 23 Aug 2021 12:19:56 +0800 Subject: [PATCH 1/2] fix: functions may be compressed mistakenly if passes=2 --- lib/compress/index.js | 3 +++ test/compress/inline.js | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/lib/compress/index.js b/lib/compress/index.js index be2288f4d..787f78dab 100644 --- a/lib/compress/index.js +++ b/lib/compress/index.js @@ -2166,6 +2166,9 @@ def_optimize(AST_Call, function(self, compressor) { if (can_inline && has_annotation(self, _INLINE)) { set_flag(fn, SQUEEZED); fn = make_node(fn.CTOR === AST_Defun ? AST_Function : fn.CTOR, fn, fn); + if (!exp.definition().single_use) { + fn = fn.clone(true); + } fn.figure_out_scope({}, { parent_scope: find_scope(compressor), toplevel: compressor.get_toplevel() diff --git a/test/compress/inline.js b/test/compress/inline.js index 03560dc2e..57b2a885b 100644 --- a/test/compress/inline.js +++ b/test/compress/inline.js @@ -459,3 +459,30 @@ do_not_repeat_when_variable_larger_than_inlined_node: { pass(s); } } + +inline_using_correct_arguments: { + options = { + reduce_vars: true, + inline: true, + passes: 2, + toplevel: true, + unused: true + } + + input: { + function run (s, t) { + return s.run(t); + } + + /*#__INLINE__*/ run(a, "foo"); + /*#__INLINE__*/ run(a, "bar"); + /*#__INLINE__*/ run(a, "123"); + } + + expect: { + s = a, t = "foo", s.run(t); + var s, t; + (function(s, t) { return s.run("bar") })(a); + (function(s, t) { return s.run("123") })(a); + } +} From ce1e3f65abefaeaa0da951df0aa5e9e95310a742 Mon Sep 17 00:00:00 2001 From: Dahan Gong Date: Thu, 26 Aug 2021 14:19:15 +0800 Subject: [PATCH 2/2] inline functions: always clone MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Fábio Santos --- lib/compress/index.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/compress/index.js b/lib/compress/index.js index 787f78dab..fae7a109f 100644 --- a/lib/compress/index.js +++ b/lib/compress/index.js @@ -2166,9 +2166,7 @@ def_optimize(AST_Call, function(self, compressor) { if (can_inline && has_annotation(self, _INLINE)) { set_flag(fn, SQUEEZED); fn = make_node(fn.CTOR === AST_Defun ? AST_Function : fn.CTOR, fn, fn); - if (!exp.definition().single_use) { - fn = fn.clone(true); - } + fn = fn.clone(true); fn.figure_out_scope({}, { parent_scope: find_scope(compressor), toplevel: compressor.get_toplevel()