|
|
|
@ -169,22 +169,38 @@ function postprocessNode(ctx, node) {
@@ -169,22 +169,38 @@ function postprocessNode(ctx, node) {
|
|
|
|
|
case 'BlockStatement': |
|
|
|
|
var subExpressionIndex = 0; |
|
|
|
|
while (subExpressionIndex < node.body.length) { |
|
|
|
|
if (node.body[subExpressionIndex].type === 'EmptyStatement') { |
|
|
|
|
// Removing empty statements from the blocks.
|
|
|
|
|
node.body.splice(subExpressionIndex, 1); |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
if (node.body[subExpressionIndex].type === 'BlockStatement') { |
|
|
|
|
// Block statements inside a block are moved to the parent one.
|
|
|
|
|
var subChildren = node.body[subExpressionIndex].body; |
|
|
|
|
Array.prototype.splice.apply(node.body, |
|
|
|
|
[subExpressionIndex, 1].concat(subChildren)); |
|
|
|
|
subExpressionIndex += subChildren.length; |
|
|
|
|
continue; |
|
|
|
|
switch (node.body[subExpressionIndex].type) { |
|
|
|
|
case 'EmptyStatement': |
|
|
|
|
// Removing empty statements from the blocks.
|
|
|
|
|
node.body.splice(subExpressionIndex, 1); |
|
|
|
|
continue; |
|
|
|
|
case 'BlockStatement': |
|
|
|
|
// Block statements inside a block are moved to the parent one.
|
|
|
|
|
var subChildren = node.body[subExpressionIndex].body; |
|
|
|
|
Array.prototype.splice.apply(node.body, |
|
|
|
|
[subExpressionIndex, 1].concat(subChildren)); |
|
|
|
|
subExpressionIndex += Math.max(subChildren.length - 1, 0); |
|
|
|
|
continue; |
|
|
|
|
case 'ReturnStatement': |
|
|
|
|
case 'ThrowStatement': |
|
|
|
|
// Removing dead code after return or throw.
|
|
|
|
|
node.body.splice(subExpressionIndex + 1, |
|
|
|
|
node.body.length - subExpressionIndex - 1); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
subExpressionIndex++; |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case 'FunctionDeclaration': |
|
|
|
|
case 'FunctionExpression': |
|
|
|
|
var block = node.body; |
|
|
|
|
if (block.body.length > 0 && |
|
|
|
|
block.body[block.body.length - 1].type === 'ReturnStatement' && |
|
|
|
|
!block.body[block.body.length - 1].argument) { |
|
|
|
|
// Function body ends with return without arg -- removing it.
|
|
|
|
|
block.body.pop(); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
return node; |
|
|
|
|
} |
|
|
|
|