From 8328f638c2b8a9beeb24fb8698b794d0cfe057f4 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Tue, 10 Mar 2015 17:20:26 +1100 Subject: [PATCH] add support for if and block statements to t.toSequenceExpression --- src/babel/types/index.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/babel/types/index.js b/src/babel/types/index.js index a137fd367d..436b69dec0 100644 --- a/src/babel/types/index.js +++ b/src/babel/types/index.js @@ -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, scope: Scope): Object { @@ -158,6 +158,14 @@ t.toSequenceExpression = function (nodes: Array, 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); } });