Handle curly brackets in SwitchCase types

master
James Long 2017-01-09 12:07:39 -05:00
parent 6b582f808c
commit aed3c1af71
3 changed files with 20 additions and 18 deletions

View File

@ -1057,15 +1057,22 @@ else
parts.push("default:"); parts.push("default:");
if (n.consequent.length > 0) { if (n.consequent.length > 0) {
parts.push(indent(options.tabWidth, concat([ const cons = path.call(
hardline, function(consequentPath) {
path.call( return printStatementSequence(consequentPath, options, print);
function(consequentPath) { },
return printStatementSequence(consequentPath, options, print); "consequent"
}, );
"consequent"
parts.push(
indent(
options.tabWidth,
concat([
isCurlyBracket(cons) ? " " : hardline,
cons
])
) )
]))); );
} }
return concat(parts); return concat(parts);

View File

@ -113,13 +113,11 @@ function bar2(b) {
if (x == null) if (x == null)
return; return;
switch (\"\") { switch (\"\") {
case 0: case 0: {
{
let y: number = x; let y: number = x;
x = \"\"; x = \"\";
} }
case 1: case 1: {
{
let z: number = x; let z: number = x;
break; break;
} }

View File

@ -251,20 +251,17 @@ export function emitExpression(node: TypedNode): t.Expression {
b.identifier(node.name), b.identifier(node.name),
false false
); );
case \"binary_op\": case \"binary_op\": {
{
const lhs = emitExpression(node.lhs); const lhs = emitExpression(node.lhs);
const rhs = emitExpression(node.rhs); const rhs = emitExpression(node.rhs);
const op = getBinaryOp(node.binaryOp); const op = getBinaryOp(node.binaryOp);
return b.binaryExpression(op, lhs, rhs); return b.binaryExpression(op, lhs, rhs);
} }
case \"unary_minus\": case \"unary_minus\": {
{
const operand = emitExpression(node.op); const operand = emitExpression(node.op);
return b.unaryExpression(\"-\", operand, true); return b.unaryExpression(\"-\", operand, true);
} }
case \"function_invocation\": case \"function_invocation\": {
{
const callee = b.memberExpression( const callee = b.memberExpression(
b.identifier(\"fns\"), b.identifier(\"fns\"),
b.identifier(node.name), b.identifier(node.name),