fix corner case in inline (#5297)

fixes #5296
This commit is contained in:
Alex Lam S.L
2022-01-14 20:18:35 +00:00
committed by GitHub
parent 87e8aca245
commit dfd6418878
4 changed files with 59 additions and 17 deletions

View File

@@ -3540,8 +3540,9 @@ Compressor.prototype.compress = function(node) {
changed = true;
}
}
var loop = in_loop && in_try && in_try.bfinally ? "try" : in_loop;
for (; index >= 0; index--) {
var inlined = statements[index].try_inline(compressor, block_scope, true, in_loop);
var inlined = statements[index].try_inline(compressor, block_scope, true, loop);
if (!inlined) continue;
statements[index] = inlined;
changed = true;
@@ -13263,6 +13264,11 @@ Compressor.prototype.compress = function(node) {
return this;
});
def(AST_New, noop);
def(AST_Return, function(compressor, scope, no_return, in_loop) {
var value = this.value;
if (value) value = value.try_inline(compressor, scope, undefined, in_loop === "try");
return value || this;
});
function inline_sequence(compressor, scope, no_return, in_loop, node, skip) {
var body = [], exprs = node.expressions, no_ret = no_return;
for (var i = exprs.length - (skip || 0), j = i; --i >= 0; no_ret = true) {
@@ -13363,10 +13369,8 @@ Compressor.prototype.compress = function(node) {
OPT(AST_Return, function(self, compressor) {
var value = self.value;
if (!value) return self;
var inlined = value.try_inline(compressor);
if (inlined) return inlined;
if (compressor.option("side_effects")
&& value
&& is_undefined(value, compressor)
&& !in_async_generator(compressor.find_parent(AST_Scope))) {
self.value = null;