in lib/src/source_visitor.dart [477:525]
void visitBlock(Block node) {
// Treat empty blocks specially. In most cases, they are not allowed to
// split. However, an empty block as the then statement of an if with an
// else is always split.
if (_isEmptyCollection(node.statements, node.rightBracket)) {
token(node.leftBracket);
if (_splitEmptyBlock(node)) newline();
token(node.rightBracket);
return;
}
// If the block is a function body, it may get expression-level indentation,
// so handle it specially. Otherwise, just bump the indentation and keep it
// in the current block.
if (node.parent is BlockFunctionBody) {
_startLiteralBody(node.leftBracket);
} else {
_beginBody(node.leftBracket);
}
var needsDouble = true;
for (var statement in node.statements) {
if (needsDouble) {
twoNewlines();
} else {
oneOrTwoNewlines();
}
visit(statement);
needsDouble = false;
if (statement is FunctionDeclarationStatement) {
// Add a blank line after non-empty block functions.
var body = statement.functionDeclaration.functionExpression.body;
if (body is BlockFunctionBody) {
needsDouble = body.block.statements.isNotEmpty;
}
}
}
if (node.statements.isNotEmpty) newline();
if (node.parent is BlockFunctionBody) {
_endLiteralBody(node.rightBracket,
forceSplit: node.statements.isNotEmpty);
} else {
_endBody(node.rightBracket);
}
}