enhance inline (#5105)
This commit is contained in:
@@ -7300,12 +7300,11 @@ merge(Compressor.prototype, {
|
|||||||
if (node instanceof AST_Destructured) {
|
if (node instanceof AST_Destructured) {
|
||||||
if (value === null) {
|
if (value === null) {
|
||||||
value = make_node(AST_Number, node, { value: 0 });
|
value = make_node(AST_Number, node, { value: 0 });
|
||||||
} else if (value) {
|
} else if (value && (value.tail_node().write_only === true
|
||||||
if (value.tail_node().write_only === true || value.may_throw_on_access(compressor, true)) {
|
|| value.may_throw_on_access(compressor, true))) {
|
||||||
value = make_node(AST_Array, node, {
|
value = make_node(AST_Array, node, {
|
||||||
elements: value instanceof AST_Sequence ? value.expressions : [ value ],
|
elements: value instanceof AST_Sequence ? value.expressions : [ value ],
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return make_node(AST_DestructuredObject, node, { properties: [] });
|
return make_node(AST_DestructuredObject, node, { properties: [] });
|
||||||
}
|
}
|
||||||
@@ -7935,9 +7934,10 @@ merge(Compressor.prototype, {
|
|||||||
exprs = trim(exprs, compressor, first_in_statement, array_spread);
|
exprs = trim(exprs, compressor, first_in_statement, array_spread);
|
||||||
return exprs && make_sequence(self, exprs.map(convert_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;
|
return self;
|
||||||
});
|
});
|
||||||
function drop_class(self, compressor, first_in_statement) {
|
function drop_class(self, compressor, first_in_statement) {
|
||||||
@@ -9711,13 +9711,19 @@ merge(Compressor.prototype, {
|
|||||||
return safe;
|
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) {
|
function return_value(stat) {
|
||||||
if (!stat) return make_node(AST_Undefined, self);
|
if (!stat) return noop_value();
|
||||||
if (stat instanceof AST_Return) return stat.value || make_node(AST_Undefined, self);
|
if (stat instanceof AST_Return) return stat.value || noop_value();
|
||||||
if (stat instanceof AST_SimpleStatement) return make_node(AST_UnaryPrefix, stat, {
|
if (stat instanceof AST_SimpleStatement) {
|
||||||
operator: "void",
|
return self.call_only ? stat.body : make_node(AST_UnaryPrefix, stat, {
|
||||||
expression: stat.body
|
operator: "void",
|
||||||
});
|
expression: stat.body,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function can_flatten_body(stat) {
|
function can_flatten_body(stat) {
|
||||||
|
|||||||
@@ -227,7 +227,7 @@ inline_await_1_trim: {
|
|||||||
console.log("PASS");
|
console.log("PASS");
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
void 0;
|
0;
|
||||||
console.log("PASS");
|
console.log("PASS");
|
||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
@@ -571,7 +571,7 @@ drop_async_1: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
console.log(function(a) {
|
console.log(function(a) {
|
||||||
void (a *= 7);
|
a *= 7;
|
||||||
return a;
|
return a;
|
||||||
}(6));
|
}(6));
|
||||||
}
|
}
|
||||||
@@ -1774,7 +1774,7 @@ issue_5001: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var a = 0;
|
var a = 0;
|
||||||
void a++;
|
a++;
|
||||||
console.log(a ? "PASS" : "FAIL");
|
console.log(a ? "PASS" : "FAIL");
|
||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
|
|||||||
@@ -1557,9 +1557,9 @@ issue_2665: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var a = 1;
|
var a = 1;
|
||||||
!function g() {
|
(function g() {
|
||||||
a-- && g();
|
a-- && g();
|
||||||
}();
|
})();
|
||||||
console.log(a);
|
console.log(a);
|
||||||
}
|
}
|
||||||
expect_stdout: "-1"
|
expect_stdout: "-1"
|
||||||
@@ -3379,7 +3379,7 @@ issue_4834: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
try {
|
try {
|
||||||
void b.p;
|
b.p;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log("PASS");
|
console.log("PASS");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1171,11 +1171,11 @@ issue_2620_4: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var c = "FAIL";
|
var c = "FAIL";
|
||||||
!function() {
|
(function() {
|
||||||
switch (NaN) {
|
switch (NaN) {
|
||||||
case void (c = "PASS"):
|
case void (c = "PASS"):
|
||||||
}
|
}
|
||||||
}();
|
})();
|
||||||
console.log(c);
|
console.log(c);
|
||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
@@ -6565,3 +6565,38 @@ issue_5098: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
shorter_without_void: {
|
||||||
|
options = {
|
||||||
|
inline: true,
|
||||||
|
passes: 2,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a;
|
||||||
|
function f(b) {
|
||||||
|
a = b;
|
||||||
|
}
|
||||||
|
f("foo");
|
||||||
|
console.log(a) || f("bar");
|
||||||
|
console.log(a, f("baz"));
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a;
|
||||||
|
function f(b) {
|
||||||
|
a = b;
|
||||||
|
}
|
||||||
|
a = "foo";
|
||||||
|
console.log(a) || (a = "bar");
|
||||||
|
console.log(a, f("baz"));
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"foo",
|
||||||
|
"bar undefined",
|
||||||
|
"baz",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user