Skip to content

Commit

Permalink
fix corner case in inline (#5853)
Browse files Browse the repository at this point in the history
fixes #5851
  • Loading branch information
alexlamsl authored Jun 17, 2024
1 parent 23d74be commit dc7aa32
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -10928,9 +10928,11 @@ Compressor.prototype.compress = function(node) {
&& (value = can_flatten_body(stat))) {
var replacing = exp === fn || def.single_use && def.references.length - def.replaced == 1;
if (can_substitute_directly()) {
self._optimized = true;
var retValue = value.optimize(compressor).clone(true);
var args = self.args.slice();
var refs = [];
var retValue = value.optimize(compressor).clone(true).transform(new TreeTransformer(function(node) {
retValue = retValue.transform(new TreeTransformer(function(node) {
if (node instanceof AST_SymbolRef) {
var def = node.definition();
if (fn.variables.get(node.name) !== def) {
Expand Down
54 changes: 54 additions & 0 deletions test/compress/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8917,3 +8917,57 @@ issue_5841_2: {
"foo",
]
}

issue_5851_1: {
options = {
inline: true,
reduce_vars: true,
toplevel: true,
}
input: {
console.log("PASS") && f();
function f() {
return f();
}
f;
}
expect: {
console.log("PASS") && f();
function f() {
return f();
}
f;
}
expect_stdout: "PASS"
}

issue_5851_2: {
options = {
conditionals: true,
inline: true,
passes: 2,
reduce_vars: true,
side_effects: true,
toplevel: true,
unused: true,
}
input: {
var a = f();
f();
function f() {
if (console.log("foo"))
console && f();
}
}
expect: {
f();
f();
function f() {
console.log("foo") && console && f();
}
}
expect_stdout: [
"foo",
"foo",
]
}

0 comments on commit dc7aa32

Please sign in to comment.