enhance if_return & side_effects (#4494)
This commit is contained in:
@@ -2600,10 +2600,18 @@ merge(Compressor.prototype, {
|
|||||||
statements.splice(i, 1);
|
statements.splice(i, 1);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (stat.value instanceof AST_UnaryPrefix && stat.value.operator == "void") {
|
var tail = stat.value.tail_node();
|
||||||
|
if (tail instanceof AST_UnaryPrefix && tail.operator == "void") {
|
||||||
CHANGED = true;
|
CHANGED = true;
|
||||||
|
var body;
|
||||||
|
if (tail === stat.value) {
|
||||||
|
body = tail.expression;
|
||||||
|
} else {
|
||||||
|
body = stat.value.clone();
|
||||||
|
body.expressions[body.length - 1] = tail.expression;
|
||||||
|
}
|
||||||
statements[i] = make_node(AST_SimpleStatement, stat, {
|
statements[i] = make_node(AST_SimpleStatement, stat, {
|
||||||
body: stat.value.expression
|
body: body,
|
||||||
});
|
});
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -6642,6 +6650,13 @@ merge(Compressor.prototype, {
|
|||||||
return this;
|
return this;
|
||||||
});
|
});
|
||||||
def(AST_AsyncFunction, return_null);
|
def(AST_AsyncFunction, return_null);
|
||||||
|
def(AST_Await, function(compressor) {
|
||||||
|
var exp = this.expression.drop_side_effect_free(compressor);
|
||||||
|
if (exp === this.expression) return this;
|
||||||
|
var node = this.clone();
|
||||||
|
node.expression = exp || make_node(AST_Number, this, { value: 0 });
|
||||||
|
return node;
|
||||||
|
});
|
||||||
def(AST_Binary, function(compressor, first_in_statement) {
|
def(AST_Binary, function(compressor, first_in_statement) {
|
||||||
if (this.operator == "in" && !is_object(this.right)) {
|
if (this.operator == "in" && !is_object(this.right)) {
|
||||||
var left = this.left.drop_side_effect_free(compressor, first_in_statement);
|
var left = this.left.drop_side_effect_free(compressor, first_in_statement);
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ inline_await_1_trim: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
(async function() {
|
(async function() {
|
||||||
await 42;
|
await 0;
|
||||||
})();
|
})();
|
||||||
console.log("PASS");
|
console.log("PASS");
|
||||||
}
|
}
|
||||||
@@ -228,7 +228,7 @@ inline_await_2_trim: {
|
|||||||
input: {
|
input: {
|
||||||
(async function() {
|
(async function() {
|
||||||
async function f(a) {
|
async function f(a) {
|
||||||
await a;
|
await a.log;
|
||||||
}
|
}
|
||||||
return await f(console);
|
return await f(console);
|
||||||
})();
|
})();
|
||||||
@@ -236,7 +236,7 @@ inline_await_2_trim: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
(async function() {
|
(async function() {
|
||||||
await console;
|
await console.log;
|
||||||
})();
|
})();
|
||||||
console.log("PASS");
|
console.log("PASS");
|
||||||
}
|
}
|
||||||
@@ -299,18 +299,22 @@ await_unary: {
|
|||||||
side_effects: true,
|
side_effects: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
|
var a;
|
||||||
(async function() {
|
(async function() {
|
||||||
console.log("PASS");
|
a = "PASS";
|
||||||
await +[];
|
await delete a.p;
|
||||||
console.log("FAIL");
|
a = "FAIL";
|
||||||
})();
|
})();
|
||||||
|
console.log(a);
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
|
var a;
|
||||||
(async function() {
|
(async function() {
|
||||||
console.log("PASS");
|
a = "PASS";
|
||||||
await +[];
|
await delete a.p;
|
||||||
console.log("FAIL");
|
a = "FAIL";
|
||||||
})();
|
})();
|
||||||
|
console.log(a);
|
||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
node_version: ">=8"
|
node_version: ">=8"
|
||||||
|
|||||||
Reference in New Issue
Block a user