Skip to content

Commit 001f6f9

Browse files
authored
fix corner case in inline (#5664)
fixes #5662
1 parent e0b302d commit 001f6f9

File tree

3 files changed

+44
-8
lines changed

3 files changed

+44
-8
lines changed

lib/compress.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6278,21 +6278,24 @@ Compressor.prototype.compress = function(node) {
62786278
var call = stat.value;
62796279
if (!call || call.TYPE != "Call") break;
62806280
if (call.is_expr_pure(compressor)) break;
6281-
var fn = call.expression;
6282-
if (fn instanceof AST_SymbolRef) {
6283-
if (self.name && self.name.definition() === fn.definition()) break;
6284-
fn = fn.fixed_value();
6281+
var exp = call.expression, fn;
6282+
if (!(exp instanceof AST_SymbolRef)) {
6283+
fn = exp;
6284+
} else if (self.name && self.name.definition() === exp.definition()) {
6285+
break;
6286+
} else {
6287+
fn = exp.fixed_value();
62856288
}
62866289
if (!(fn instanceof AST_Defun || fn instanceof AST_Function)) break;
62876290
if (fn.rest) break;
62886291
if (fn.uses_arguments) break;
6289-
if (fn === call.expression) {
6292+
if (fn === exp) {
62906293
if (fn.parent_scope !== self) break;
62916294
if (!all(fn.enclosed, function(def) {
62926295
return def.scope !== self;
62936296
})) break;
62946297
}
6295-
if (fn.name
6298+
if ((fn !== exp || fn.name)
62966299
&& (parent instanceof AST_ClassMethod || parent instanceof AST_ObjectMethod)
62976300
&& parent.value === compressor.self()) break;
62986301
if (fn.contains_this()) break;
@@ -6321,7 +6324,7 @@ Compressor.prototype.compress = function(node) {
63216324
fn.argnames.push(fn.make_var(AST_SymbolFunarg, fn, "argument_" + len));
63226325
} while (++len < self.argnames.length);
63236326
}
6324-
return call.expression;
6327+
return exp;
63256328
}
63266329
break;
63276330
}

test/compress/classes.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3586,3 +3586,36 @@ issue_5531_3: {
35863586
expect_stdout: "foo"
35873587
node_version: ">=16"
35883588
}
3589+
3590+
issue_5662: {
3591+
options = {
3592+
inline: true,
3593+
reduce_vars: true,
3594+
}
3595+
input: {
3596+
console.log(new (function() {
3597+
var g = function(a) {
3598+
return a;
3599+
};
3600+
return class {
3601+
h(b) {
3602+
return g(b);
3603+
}
3604+
};
3605+
}())().h("PASS"));
3606+
}
3607+
expect: {
3608+
console.log(new (function() {
3609+
var g = function(a) {
3610+
return a;
3611+
};
3612+
return class {
3613+
h(b) {
3614+
return g(b);
3615+
}
3616+
};
3617+
}())().h("PASS"));
3618+
}
3619+
expect_stdout: "PASS"
3620+
node_version: ">=6"
3621+
}

test/reduce.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ module.exports = function reduce_test(testcase, minify_options, reduce_options)
466466
}
467467
}
468468
else if (node instanceof U.AST_VarDef) {
469-
if (node.value && !(parent instanceof U.AST_Const)) {
469+
if (node.value && !(node.name instanceof U.AST_Destructured || parent instanceof U.AST_Const)) {
470470
node.start._permute++;
471471
CHANGED = true;
472472
return new U.AST_VarDef({

0 commit comments

Comments
 (0)