Skip to content

Commit

Permalink
fix corner case in inline
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlamsl committed Jun 16, 2024
1 parent 0934c0e commit 8821125
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ function Compressor(options, false_by_default) {
};
}

Compressor.prototype = new TreeTransformer(function(node, descend, in_list) {
Compressor.prototype = new TreeTransformer(function(node, descend) {
if (node._squeezed) return node;
var is_scope = node instanceof AST_Scope;
if (is_scope) {
Expand Down Expand Up @@ -270,7 +270,7 @@ Compressor.prototype.compress = function(node) {
};

(function(OPT) {
OPT(AST_Node, function(self, compressor) {
OPT(AST_Node, function(self) {
return self;
});

Expand Down Expand Up @@ -10926,7 +10926,7 @@ Compressor.prototype.compress = function(node) {
if (can_substitute_directly()) {
var args = self.args.slice();
var refs = [];
var retValue = value.clone(true).transform(new TreeTransformer(function(node) {
var retValue = value.optimize(compressor).clone(true).transform(new TreeTransformer(function(node) {
if (node instanceof AST_SymbolRef) {
var def = node.definition();
if (fn.variables.get(node.name) !== def) {
Expand Down
100 changes: 100 additions & 0 deletions test/compress/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8817,3 +8817,103 @@ issue_5766_2: {
}
expect_stdout: "function"
}

issue_5841_1: {
options = {
conditionals: true,
evaluate: true,
inline: true,
join_vars: true,
passes: 2,
reduce_funcs: true,
reduce_vars: true,
side_effects: true,
unused: true,
}
input: {
var a = 42;
(function() {
f();
var b = f();
function f() {
if (console && a)
g && g();
}
function g() {
var c;
for (;console.log("foo"););
(function h(d) {
d && d.p;
})();
}
})();
}
expect: {
var a = 42;
(function() {
f();
f();
function f() {
{
if (console && a) {
for (;console.log("foo"););
return;
}
return;
}
}
})();
}
expect_stdout: [
"foo",
"foo",
]
}

issue_5841_2: {
options = {
conditionals: true,
evaluate: true,
if_return: true,
inline: true,
join_vars: true,
passes: 2,
reduce_funcs: true,
reduce_vars: true,
side_effects: true,
unused: true,
}
input: {
var a = 42;
(function() {
f();
var b = f();
function f() {
if (console && a)
g && g();
}
function g() {
var c;
for (;console.log("foo"););
(function h(d) {
d && d.p;
})();
}
})();
}
expect: {
var a = 42;
(function() {
f();
f();
function f() {
if (console && a)
for (;console.log("foo"););
}
})();
}
expect_stdout: [
"foo",
"foo",
]
}

0 comments on commit 8821125

Please sign in to comment.