check for body existence before length in dead code elimination transformer - fixes #931

This commit is contained in:
Sebastian McKenzie
2015-03-03 09:37:52 +11:00
parent 727208f376
commit 8dda8838ba

View File

@@ -77,7 +77,7 @@ export var IfStatement = {
// if (foo) {} else { bar; } -> if (!foo) { bar; }
//
if (t.blockStatement(consequent) && !consequent.body.length && t.isBlockStatement(alternate) && alternate.body.length) {
if (t.blockStatement(consequent) && consequent.body && !consequent.body.length && t.isBlockStatement(alternate) && alternate.body && alternate.body.length) {
node.consequent = node.alternate;
node.alternate = null;
node.test = t.unaryExpression("!", test, true);