Emit functions on a singline line if they were originally written on a single line.

This commit is contained in:
Cyrus Najmabadi
2015-02-06 20:03:24 -08:00
parent 11aa4d362b
commit 0fbbbffde6
541 changed files with 4412 additions and 9120 deletions

View File

@@ -3487,19 +3487,34 @@ module ts {
write(" {");
scopeEmitStart(node);
var outPos = writer.getTextPos();
increaseIndent();
emitDetachedComments(body.statements);
var startIndex = emitDirectivePrologues(body.statements, /*startWithNewLine*/ true);
emitFunctionBodyPreamble(node);
emitLinesStartingAt(body.statements, startIndex);
emitTempDeclarations(/*newLine*/ true);
writeLine();
emitLeadingCommentsOfPosition(body.statements.end);
decreaseIndent();
emitToken(SyntaxKind.CloseBraceToken, body.statements.end);
var preambleEmitted = writer.getTextPos() !== outPos;
if (!preambleEmitted && nodeEndIsOnSameLineAsNodeStart(body, body)) {
for (var i = 0, n = body.statements.length; i < n; i++) {
write(" ");
emit(body.statements[i]);
}
emitTempDeclarations(/*newLine*/ false);
write(" ");
emitLeadingCommentsOfPosition(body.statements.end);
}
else {
increaseIndent();
emitLinesStartingAt(body.statements, startIndex);
emitTempDeclarations(/*newLine*/ true);
writeLine();
emitLeadingCommentsOfPosition(body.statements.end);
decreaseIndent();
}
emitToken(SyntaxKind.CloseBraceToken, body.statements.end);
scopeEmitEnd();
}