enhance conditionals (#3557)
This commit is contained in:
@@ -4665,11 +4665,6 @@ merge(Compressor.prototype, {
|
|||||||
self.body = self.alternative || make_node(AST_EmptyStatement, self);
|
self.body = self.alternative || make_node(AST_EmptyStatement, self);
|
||||||
self.alternative = tmp;
|
self.alternative = tmp;
|
||||||
}
|
}
|
||||||
if (is_empty(self.body) && is_empty(self.alternative)) {
|
|
||||||
return make_node(AST_SimpleStatement, self.condition, {
|
|
||||||
body: self.condition.clone()
|
|
||||||
}).optimize(compressor);
|
|
||||||
}
|
|
||||||
if (self.body instanceof AST_SimpleStatement
|
if (self.body instanceof AST_SimpleStatement
|
||||||
&& self.alternative instanceof AST_SimpleStatement) {
|
&& self.alternative instanceof AST_SimpleStatement) {
|
||||||
return make_node(AST_SimpleStatement, self, {
|
return make_node(AST_SimpleStatement, self, {
|
||||||
@@ -4703,15 +4698,22 @@ merge(Compressor.prototype, {
|
|||||||
}).transform(compressor)
|
}).transform(compressor)
|
||||||
}).optimize(compressor);
|
}).optimize(compressor);
|
||||||
}
|
}
|
||||||
if (self.body instanceof AST_EmptyStatement
|
if (is_empty(self.body)) {
|
||||||
&& self.alternative instanceof AST_SimpleStatement) {
|
if (is_empty(self.alternative)) return make_node(AST_SimpleStatement, self.condition, {
|
||||||
return make_node(AST_SimpleStatement, self, {
|
body: self.condition.clone()
|
||||||
|
}).optimize(compressor);
|
||||||
|
if (self.alternative instanceof AST_SimpleStatement) return make_node(AST_SimpleStatement, self, {
|
||||||
body: make_node(AST_Binary, self, {
|
body: make_node(AST_Binary, self, {
|
||||||
operator : "||",
|
operator : "||",
|
||||||
left : self.condition,
|
left : self.condition,
|
||||||
right : self.alternative.body
|
right : self.alternative.body
|
||||||
}).transform(compressor)
|
}).transform(compressor)
|
||||||
}).optimize(compressor);
|
}).optimize(compressor);
|
||||||
|
self = make_node(AST_If, self, {
|
||||||
|
condition: negated,
|
||||||
|
body: self.alternative,
|
||||||
|
alternative: null
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (self.body instanceof AST_Exit
|
if (self.body instanceof AST_Exit
|
||||||
&& self.alternative instanceof AST_Exit
|
&& self.alternative instanceof AST_Exit
|
||||||
|
|||||||
@@ -161,6 +161,24 @@ ifs_6: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ifs_7: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
if (A); else;
|
||||||
|
if (A) while (B); else;
|
||||||
|
if (A); else while (C);
|
||||||
|
if (A) while (B); else while (C);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
A;
|
||||||
|
if (A) while (B);
|
||||||
|
if (!A) while (C);
|
||||||
|
if (A) while (B); else while (C);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cond_1: {
|
cond_1: {
|
||||||
options = {
|
options = {
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user