Merge 9fe8edc3f6 into 569757d14d
This commit is contained in:
commit
3dfa427d18
|
|
@ -3115,11 +3115,21 @@ merge(Compressor.prototype, {
|
|||
return self;
|
||||
});
|
||||
|
||||
function can_be_extracted_from_if_block(node) {
|
||||
return !(
|
||||
node instanceof AST_Const ||
|
||||
node instanceof AST_Let ||
|
||||
node instanceof AST_Class
|
||||
);
|
||||
}
|
||||
|
||||
OPT(AST_BlockStatement, function(self, compressor){
|
||||
tighten_body(self.body, compressor);
|
||||
switch (self.body.length) {
|
||||
case 1:
|
||||
if (!compressor.has_directive("use strict") && compressor.parent() instanceof AST_If
|
||||
if (!compressor.has_directive("use strict")
|
||||
&& compressor.parent() instanceof AST_If
|
||||
&& can_be_extracted_from_if_block(self.body[0])
|
||||
|| can_be_evicted_from_block(self.body[0])) {
|
||||
return self.body[0];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -187,3 +187,40 @@ issue_1672_if_strict: {
|
|||
expect_stdout: true
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
issue_2946_else_const: {
|
||||
input: {
|
||||
if (1) {
|
||||
const x = 6;
|
||||
} else {
|
||||
const y = 12;
|
||||
}
|
||||
if (2) {
|
||||
let z = 24;
|
||||
} else {
|
||||
let w = 48;
|
||||
}
|
||||
if (3) {
|
||||
class X {}
|
||||
} else {
|
||||
class Y {}
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
if (1) {
|
||||
const x = 6;
|
||||
} else {
|
||||
const y = 12;
|
||||
}
|
||||
if (2) {
|
||||
let z = 24;
|
||||
} else {
|
||||
let w = 48;
|
||||
}
|
||||
if (3) {
|
||||
class X {}
|
||||
} else {
|
||||
class Y {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user