enhance inline (#5105)

This commit is contained in:
Alex Lam S.L
2021-07-27 14:47:01 +01:00
committed by GitHub
parent e219a9a78a
commit 4fe2cac35e
4 changed files with 62 additions and 21 deletions

View File

@@ -7300,12 +7300,11 @@ merge(Compressor.prototype, {
if (node instanceof AST_Destructured) {
if (value === null) {
value = make_node(AST_Number, node, { value: 0 });
} else if (value) {
if (value.tail_node().write_only === true || value.may_throw_on_access(compressor, true)) {
value = make_node(AST_Array, node, {
elements: value instanceof AST_Sequence ? value.expressions : [ value ],
});
}
} else if (value && (value.tail_node().write_only === true
|| value.may_throw_on_access(compressor, true))) {
value = make_node(AST_Array, node, {
elements: value instanceof AST_Sequence ? value.expressions : [ value ],
});
}
return make_node(AST_DestructuredObject, node, { properties: [] });
}
@@ -7935,9 +7934,10 @@ merge(Compressor.prototype, {
exprs = trim(exprs, compressor, first_in_statement, array_spread);
return exprs && make_sequence(self, exprs.map(convert_spread));
}
if (!fn.contains_this()) return make_node(AST_Call, self, self);
if (!fn.contains_this()) self = make_node(AST_Call, self, self);
}
}
self.call_only = true;
return self;
});
function drop_class(self, compressor, first_in_statement) {
@@ -9711,13 +9711,19 @@ merge(Compressor.prototype, {
return safe;
}
function noop_value() {
return self.call_only ? make_node(AST_Number, self, { value: 0 }) : make_node(AST_Undefined, self);
}
function return_value(stat) {
if (!stat) return make_node(AST_Undefined, self);
if (stat instanceof AST_Return) return stat.value || make_node(AST_Undefined, self);
if (stat instanceof AST_SimpleStatement) return make_node(AST_UnaryPrefix, stat, {
operator: "void",
expression: stat.body
});
if (!stat) return noop_value();
if (stat instanceof AST_Return) return stat.value || noop_value();
if (stat instanceof AST_SimpleStatement) {
return self.call_only ? stat.body : make_node(AST_UnaryPrefix, stat, {
operator: "void",
expression: stat.body,
});
}
}
function can_flatten_body(stat) {