add support for if and block statements to t.toSequenceExpression

This commit is contained in:
Sebastian McKenzie 2015-03-10 17:20:26 +11:00
parent 5586ce280f
commit 8328f638c2

View File

@ -139,7 +139,7 @@ t.toComputedKey = function (node: Object, key: Object = node.key): Object {
* Variable declarations are turned into simple assignments and their
* declarations hoisted to the top of the current scope.
*
* Expression statements are just resolved to their standard expression.
* Expression statements are just resolved to their expression.
*/
t.toSequenceExpression = function (nodes: Array<Object>, scope: Scope): Object {
@ -158,6 +158,14 @@ t.toSequenceExpression = function (nodes: Array<Object>, scope: Scope): Object {
});
exprs.push(t.assignmentExpression("=", declar.id, declar.init));
});
} else if (t.isIfStatement(node)) {
return t.conditionalExpression(
node.test,
node.consequent ? t.toSequenceExpression([node.consequent]) : t.identifier("undefined"),
node.alternate ? t.toSequenceExpression([node.alternate]) : t.identifier("undefined")
);
} else if (t.isBlockStatement(node)) {
return t.toSequenceExpression(node.body);
}
});