Skip to content

Commit

Permalink
fix corner case in inline (#4223)
Browse files Browse the repository at this point in the history
fixes #4222
  • Loading branch information
alexlamsl committed Oct 15, 2020
1 parent 3d71e97 commit 4f83393
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down
30 changes: 30 additions & 0 deletions test/compress/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 4f83393

Please sign in to comment.