fix corner case in inline (#4223)

fixes #4222
This commit is contained in:
Alex Lam S.L
2020-10-15 14:52:40 +01:00
committed by GitHub
parent 3d71e97dd1
commit 4f833937fe
2 changed files with 31 additions and 1 deletions

View File

@@ -7041,7 +7041,7 @@ merge(Compressor.prototype, {
&& fn.is_constant_expression(find_scope(compressor)))
&& (value = can_flatten_body(stat))
&& !fn.contains_this()) {
var replacing = exp === fn || compressor.option("unused") && def.references.length - def.replaced == 1;
var replacing = exp === fn || def.single_use && def.references.length - def.replaced == 1;
if (can_substitute_directly()) {
var args = self.args.slice();
var refs = [];

View File

@@ -1104,3 +1104,33 @@ issue_4220: {
}
expect_stdout: true
}
issue_4222: {
options = {
inline: true,
reduce_vars: true,
toplevel: true,
unused: true,
}
input: {
{
const a = function() {
return function() {};
};
var b = a();
}
b();
console.log(typeof a);
}
expect: {
{
const a = function() {
return function() {};
};
var b = a();
}
b();
console.log(typeof a);
}
expect_stdout: true
}