Skip to content

Commit

Permalink
fix corner case in inline (#5664)
Browse files Browse the repository at this point in the history
fixes #5662
  • Loading branch information
alexlamsl authored Sep 17, 2022
1 parent e0b302d commit 001f6f9
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 8 deletions.
17 changes: 10 additions & 7 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -6278,21 +6278,24 @@ Compressor.prototype.compress = function(node) {
var call = stat.value;
if (!call || call.TYPE != "Call") break;
if (call.is_expr_pure(compressor)) break;
var fn = call.expression;
if (fn instanceof AST_SymbolRef) {
if (self.name && self.name.definition() === fn.definition()) break;
fn = fn.fixed_value();
var exp = call.expression, fn;
if (!(exp instanceof AST_SymbolRef)) {
fn = exp;
} else if (self.name && self.name.definition() === exp.definition()) {
break;
} else {
fn = exp.fixed_value();
}
if (!(fn instanceof AST_Defun || fn instanceof AST_Function)) break;
if (fn.rest) break;
if (fn.uses_arguments) break;
if (fn === call.expression) {
if (fn === exp) {
if (fn.parent_scope !== self) break;
if (!all(fn.enclosed, function(def) {
return def.scope !== self;
})) break;
}
if (fn.name
if ((fn !== exp || fn.name)
&& (parent instanceof AST_ClassMethod || parent instanceof AST_ObjectMethod)
&& parent.value === compressor.self()) break;
if (fn.contains_this()) break;
Expand Down Expand Up @@ -6321,7 +6324,7 @@ Compressor.prototype.compress = function(node) {
fn.argnames.push(fn.make_var(AST_SymbolFunarg, fn, "argument_" + len));
} while (++len < self.argnames.length);
}
return call.expression;
return exp;
}
break;
}
Expand Down
33 changes: 33 additions & 0 deletions test/compress/classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3586,3 +3586,36 @@ issue_5531_3: {
expect_stdout: "foo"
node_version: ">=16"
}

issue_5662: {
options = {
inline: true,
reduce_vars: true,
}
input: {
console.log(new (function() {
var g = function(a) {
return a;
};
return class {
h(b) {
return g(b);
}
};
}())().h("PASS"));
}
expect: {
console.log(new (function() {
var g = function(a) {
return a;
};
return class {
h(b) {
return g(b);
}
};
}())().h("PASS"));
}
expect_stdout: "PASS"
node_version: ">=6"
}
2 changes: 1 addition & 1 deletion test/reduce.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ module.exports = function reduce_test(testcase, minify_options, reduce_options)
}
}
else if (node instanceof U.AST_VarDef) {
if (node.value && !(parent instanceof U.AST_Const)) {
if (node.value && !(node.name instanceof U.AST_Destructured || parent instanceof U.AST_Const)) {
node.start._permute++;
CHANGED = true;
return new U.AST_VarDef({
Expand Down

0 comments on commit 001f6f9

Please sign in to comment.