fix recursive function inline

fixes #2737
This commit is contained in:
alexlamsl 2018-01-07 04:01:51 +08:00
parent 659c8a7632
commit 0ce389fd2a
2 changed files with 26 additions and 2 deletions

View File

@ -4075,9 +4075,10 @@ merge(Compressor.prototype, {
if (compressor.option("inline")
&& !fn.uses_arguments
&& !fn.uses_eval
&& !(fn.name && fn instanceof AST_Function)
&& (value = can_flatten_body(stat))
&& (exp === fn ? !fn.name
: compressor.option("unused")
&& (exp === fn
|| compressor.option("unused")
&& (def = exp.definition()).references.length == 1
&& !recursive_ref(compressor, def)
&& fn.is_constant_expression(exp.scope))

View File

@ -1905,3 +1905,26 @@ duplicate_arg_var: {
}
expect_stdout: "PASS"
}
issue_2737: {
options = {
inline: true,
reduce_vars: true,
unused: true,
}
input: {
(function(a) {
while (a());
})(function f() {
console.log(typeof f);
});
}
expect: {
(function(a) {
while (a());
})(function f() {
console.log(typeof f);
});
}
expect_stdout: "function"
}