close #2946 by ensuring let and const aren't put out of blocks
This commit is contained in:
parent
569757d14d
commit
55acf310f8
|
|
@ -3115,11 +3115,18 @@ merge(Compressor.prototype, {
|
|||
return self;
|
||||
});
|
||||
|
||||
function can_be_extracted_from_if_block(node) {
|
||||
return !(
|
||||
node instanceof AST_Const ||
|
||||
node instanceof AST_Let
|
||||
);
|
||||
}
|
||||
|
||||
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,30 @@ 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;
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
if (1) {
|
||||
const x = 6;
|
||||
} else {
|
||||
const y = 12;
|
||||
}
|
||||
if (2) {
|
||||
let z = 24;
|
||||
} else {
|
||||
let w = 48;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user