Remove optimization of eliding the preamble code for functions without statements.

This commit is contained in:
Cyrus Najmabadi
2015-02-25 13:32:45 -08:00
parent e9874a2a4f
commit ebd63c0fde
60 changed files with 638 additions and 168 deletions

View File

@@ -3992,46 +3992,6 @@ module ts {
}
function emitBlockFunctionBody(node: FunctionLikeDeclaration, body: Block) {
// If the body has no statements, and we know there's no code that would cause any
// prologue to be emitted, then just do a simple emit if the empty block.
if (body.statements.length === 0 && !anyParameterHasBindingPatternOrInitializer(node)) {
emitFunctionBodyWithNoStatements(node, body);
}
else {
emitFunctionBodyWithStatements(node, body);
}
}
function anyParameterHasBindingPatternOrInitializer(func: FunctionLikeDeclaration) {
return forEach(func.parameters, hasBindingPatternOrInitializer);
}
function hasBindingPatternOrInitializer(parameter: ParameterDeclaration) {
return parameter.initializer || isBindingPattern(parameter.name);
}
function emitFunctionBodyWithNoStatements(node: FunctionLikeDeclaration, body: Block) {
var singleLine = isSingleLineEmptyBlock(node.body);
write(" {");
if (singleLine) {
write(" ");
}
else {
increaseIndent();
writeLine();
}
emitLeadingCommentsOfPosition(body.statements.end);
if (!singleLine) {
decreaseIndent();
}
emitToken(SyntaxKind.CloseBraceToken, body.statements.end);
}
function emitFunctionBodyWithStatements(node: FunctionLikeDeclaration, body: Block) {
write(" {");
scopeEmitStart(node);
@@ -4046,7 +4006,7 @@ module ts {
var preambleEmitted = writer.getTextPos() !== outPos;
if (!preambleEmitted && nodeEndIsOnSameLineAsNodeStart(body, body)) {
for (var i = 0, n = body.statements.length; i < n; i++) {
for (var i = startIndex, n = body.statements.length; i < n; i++) {
write(" ");
emit(body.statements[i]);
}