enhance conditionals (#5371)
This commit is contained in:
@@ -9157,14 +9157,16 @@ Compressor.prototype.compress = function(node) {
|
||||
var cond = fuzzy_eval(compressor, self.condition);
|
||||
if (!cond) {
|
||||
AST_Node.warn("Condition always false [{file}:{line},{col}]", self.condition.start);
|
||||
var body = [ make_node(AST_SimpleStatement, self.condition, { body: self.condition }) ];
|
||||
var body = [
|
||||
make_node(AST_SimpleStatement, self.condition, { body: self.condition }).transform(compressor),
|
||||
];
|
||||
extract_declarations_from_unreachable_code(compressor, self.body, body);
|
||||
if (self.alternative) body.push(self.alternative);
|
||||
return make_node(AST_BlockStatement, self, { body: body }).optimize(compressor);
|
||||
} else if (!(cond instanceof AST_Node)) {
|
||||
AST_Node.warn("Condition always true [{file}:{line},{col}]", self.condition.start);
|
||||
var body = [
|
||||
make_node(AST_SimpleStatement, self.condition, { body: self.condition }),
|
||||
make_node(AST_SimpleStatement, self.condition, { body: self.condition }).transform(compressor),
|
||||
self.body,
|
||||
];
|
||||
if (self.alternative) extract_declarations_from_unreachable_code(compressor, self.alternative, body);
|
||||
@@ -9493,20 +9495,12 @@ Compressor.prototype.compress = function(node) {
|
||||
left: self.expression,
|
||||
right: exp,
|
||||
}),
|
||||
body: make_node(AST_BlockStatement, self, {
|
||||
body: statements,
|
||||
}),
|
||||
body: make_node(AST_BlockStatement, self, { body: statements }),
|
||||
alternative: null,
|
||||
}).optimize(compressor);
|
||||
if (exp) statements.unshift(make_node(AST_SimpleStatement, exp, {
|
||||
body: exp,
|
||||
}));
|
||||
statements.unshift(make_node(AST_SimpleStatement, self.expression, {
|
||||
body:self.expression,
|
||||
}));
|
||||
return make_node(AST_BlockStatement, self, {
|
||||
body: statements,
|
||||
}).optimize(compressor);
|
||||
if (exp) statements.unshift(make_node(AST_SimpleStatement, exp, { body: exp }));
|
||||
statements.unshift(make_node(AST_SimpleStatement, self.expression, { body: self.expression }));
|
||||
return make_node(AST_BlockStatement, self, { body: statements }).optimize(compressor);
|
||||
case 2:
|
||||
if (!member(default_branch, body) || !no_break(body[1])) break;
|
||||
var statements = body[0].body.slice();
|
||||
@@ -9524,14 +9518,10 @@ Compressor.prototype.compress = function(node) {
|
||||
left: self.expression,
|
||||
right: body[0].expression,
|
||||
}),
|
||||
body: make_node(AST_BlockStatement, body[0], {
|
||||
body: statements,
|
||||
}),
|
||||
body: make_node(AST_BlockStatement, body[0], { body: statements }),
|
||||
alternative: exclusive && alternative || null,
|
||||
});
|
||||
if (!exclusive && alternative) node = make_node(AST_BlockStatement, self, {
|
||||
body: [ node, alternative ],
|
||||
});
|
||||
if (!exclusive && alternative) node = make_node(AST_BlockStatement, self, { body: [ node, alternative ] });
|
||||
return node.optimize(compressor);
|
||||
}
|
||||
return self;
|
||||
|
||||
Reference in New Issue
Block a user