Skip to content

Commit

Permalink
fix: functions may be compressed mistakenly if passes=2
Browse files Browse the repository at this point in the history
  • Loading branch information
gdh1995 committed Aug 23, 2021
1 parent 23e4211 commit ea9328d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/compress/index.js
Expand Up @@ -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()
Expand Down
27 changes: 27 additions & 0 deletions test/compress/inline.js
Expand Up @@ -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);
}
}

0 comments on commit ea9328d

Please sign in to comment.