aboutsummaryrefslogtreecommitdiff
path: root/lib/compress.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2019-10-31 09:33:46 +0800
committerGitHub <noreply@github.com>2019-10-31 09:33:46 +0800
commit379745836510c23ac980a3c28f6754181aba12b9 (patch)
tree510cd3a7a0adece707358b851ebeaab885b4f63e /lib/compress.js
parent1858c2018c0e872e17e31599bd6bed5063322f28 (diff)
downloadtracifyjs-379745836510c23ac980a3c28f6754181aba12b9.tar.gz
tracifyjs-379745836510c23ac980a3c28f6754181aba12b9.zip
enhance `conditionals` (#3557)
Diffstat (limited to 'lib/compress.js')
-rw-r--r--lib/compress.js18
1 files changed, 10 insertions, 8 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 9e2b6895..a6f5d20b 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -4665,11 +4665,6 @@ merge(Compressor.prototype, {
self.body = self.alternative || make_node(AST_EmptyStatement, self);
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
&& self.alternative instanceof AST_SimpleStatement) {
return make_node(AST_SimpleStatement, self, {
@@ -4703,15 +4698,22 @@ merge(Compressor.prototype, {
}).transform(compressor)
}).optimize(compressor);
}
- if (self.body instanceof AST_EmptyStatement
- && self.alternative instanceof AST_SimpleStatement) {
- return make_node(AST_SimpleStatement, self, {
+ if (is_empty(self.body)) {
+ if (is_empty(self.alternative)) return make_node(AST_SimpleStatement, self.condition, {
+ body: self.condition.clone()
+ }).optimize(compressor);
+ if (self.alternative instanceof AST_SimpleStatement) return make_node(AST_SimpleStatement, self, {
body: make_node(AST_Binary, self, {
operator : "||",
left : self.condition,
right : self.alternative.body
}).transform(compressor)
}).optimize(compressor);
+ self = make_node(AST_If, self, {
+ condition: negated,
+ body: self.alternative,
+ alternative: null
+ });
}
if (self.body instanceof AST_Exit
&& self.alternative instanceof AST_Exit