fix corner case in awaits & inline (#5259)

fixes #5258
This commit is contained in:
Alex Lam S.L
2022-01-03 12:57:24 +00:00
committed by GitHub
parent 1a054e869e
commit dec359ce58
2 changed files with 70 additions and 2 deletions

View File

@@ -5414,7 +5414,6 @@ Compressor.prototype.compress = function(node) {
def(AST_Node, return_true); def(AST_Node, return_true);
def(AST_Constant, return_false); def(AST_Constant, return_false);
def(AST_Destructured, return_true);
def(AST_EmptyStatement, return_false); def(AST_EmptyStatement, return_false);
def(AST_Lambda, return_false); def(AST_Lambda, return_false);
def(AST_ObjectIdentity, return_false); def(AST_ObjectIdentity, return_false);
@@ -5448,6 +5447,9 @@ Compressor.prototype.compress = function(node) {
} }
return this.left.may_throw(compressor); return this.left.may_throw(compressor);
}); });
def(AST_Await, function(compressor) {
return this.expression.may_throw(compressor);
});
def(AST_Binary, function(compressor) { def(AST_Binary, function(compressor) {
return this.left.may_throw(compressor) return this.left.may_throw(compressor)
|| this.right.may_throw(compressor) || this.right.may_throw(compressor)
@@ -5484,6 +5486,12 @@ Compressor.prototype.compress = function(node) {
return !this.optional && this.expression.may_throw_on_access(compressor) return !this.optional && this.expression.may_throw_on_access(compressor)
|| this.expression.may_throw(compressor); || this.expression.may_throw(compressor);
}); });
def(AST_ForEnumeration, function(compressor) {
if (this.init.may_throw(compressor)) return true;
var obj = this.object.tail_node();
if (!(obj instanceof AST_Array || obj.is_string(compressor))) return true;
return this.body.may_throw(compressor);
});
def(AST_If, function(compressor) { def(AST_If, function(compressor) {
return this.condition.may_throw(compressor) return this.condition.may_throw(compressor)
|| this.body && this.body.may_throw(compressor) || this.body && this.body.may_throw(compressor)
@@ -12931,7 +12939,11 @@ Compressor.prototype.compress = function(node) {
defined.set("arguments", true); defined.set("arguments", true);
} }
var async = is_async(fn); var async = is_async(fn);
if (async && !(compressor.option("awaits") && is_async(scope))) return; if (async) {
if (!compressor.option("awaits")) return;
if (!is_async(scope)) return;
if (call.may_throw(compressor)) return;
}
var names = scope.var_names(); var names = scope.var_names();
if (in_loop) in_loop = []; if (in_loop) in_loop = [];
if (!fn.variables.all(function(def, name) { if (!fn.variables.all(function(def, name) {

View File

@@ -2605,3 +2605,59 @@ issue_5250: {
] ]
node_version: ">=8" node_version: ">=8"
} }
issue_5258_1: {
options = {
awaits: true,
inline: true,
}
input: {
(async function() {
(async function() {
throw "FAIL";
})();
return "PASS";
})().catch(console.log).then(console.log);
}
expect: {
(async function() {
(async function() {
throw "FAIL";
})();
return "PASS";
})().catch(console.log).then(console.log);
}
expect_stdout: "PASS"
node_version: ">=8"
}
issue_5258_2: {
options = {
awaits: true,
inline: true,
}
input: {
function f() {
throw "FAIL";
}
(async function() {
(async function() {
f();
})();
return "PASS";
})().catch(console.log).then(console.log);
}
expect: {
function f() {
throw "FAIL";
}
(async function() {
(async function() {
f();
})();
return "PASS";
})().catch(console.log).then(console.log);
}
expect_stdout: "PASS"
node_version: ">=8"
}