Print a block when encountering consequents that are if statements
This commit is contained in:
@@ -5,6 +5,7 @@ var res = transform('', {
|
||||
visitor: {
|
||||
Program: function(path) {
|
||||
if (this.done) return;
|
||||
// if (false) { if (true) 42; } else 23;
|
||||
var inner = t.ifStatement(t.booleanLiteral(true), t.expressionStatement(t.numericLiteral(42)), null);
|
||||
var outer = t.ifStatement(t.booleanLiteral(false), inner, t.expressionStatement(t.numericLiteral(23)));
|
||||
path.replaceWith(t.program([outer]));
|
||||
|
||||
@@ -16,8 +16,21 @@ export function IfStatement(node: Object) {
|
||||
this.push(")");
|
||||
this.space();
|
||||
|
||||
let consequentIsIf = t.isIfStatement(node.consequent);
|
||||
if (consequentIsIf) {
|
||||
this.push("{");
|
||||
this.newline();
|
||||
this.indent();
|
||||
}
|
||||
|
||||
this.printAndIndentOnComments(node.consequent, node);
|
||||
|
||||
if (consequentIsIf) {
|
||||
this.dedent();
|
||||
this.newline();
|
||||
this.push("}");
|
||||
}
|
||||
|
||||
if (node.alternate) {
|
||||
if (this.isLast("}")) this.space();
|
||||
this.push("else ");
|
||||
|
||||
Reference in New Issue
Block a user