fix block elimination (#2023)

fixes #1664
fixes #1672
This commit is contained in:
Alex Lam S.L
2017-05-30 14:59:54 +08:00
committed by GitHub
parent ec63588496
commit 0cc6dedccc
2 changed files with 142 additions and 1 deletions

View File

@@ -668,6 +668,7 @@ merge(Compressor.prototype, {
function can_be_evicted_from_block(node) {
return !(
node instanceof AST_DefClass ||
node instanceof AST_Defun ||
node instanceof AST_Let ||
node instanceof AST_Const
);
@@ -1997,7 +1998,8 @@ merge(Compressor.prototype, {
self.body = tighten_body(self.body, compressor);
switch (self.body.length) {
case 1:
if (can_be_evicted_from_block(self.body[0])) {
if (!compressor.has_directive("use strict") && compressor.parent() instanceof AST_If
|| can_be_evicted_from_block(self.body[0])) {
return self.body[0];
}
break;