Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix corner case in inline #5664

Merged
merged 1 commit into from
Sep 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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