Skip to content

Commit

Permalink
Restore some monomorphism
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbranch committed Feb 19, 2020
1 parent c91efd4 commit e3ef427
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 21 deletions.
35 changes: 22 additions & 13 deletions src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2297,7 +2297,7 @@ namespace ts {
emitTokenWithComment(token.kind, node.expression.end, writePunctuation, node);
writeLinesAndIndent(linesAfterDot, /*writeSpaceIfNotIndenting*/ false);
emit(node.name);
decreaseIndentIf(linesBeforeDot, linesAfterDot);
decreaseIndentIf(linesBeforeDot > 0, linesAfterDot > 0);
}

// 1..toString is a valid property access, emit a dot after the literal
Expand Down Expand Up @@ -2475,7 +2475,7 @@ namespace ts {
case EmitBinaryExpressionState.FinishEmit: {
const linesBeforeOperator = getLinesBetweenNodes(node, node.left, node.operatorToken);
const linesAfterOperator = getLinesBetweenNodes(node, node.operatorToken, node.right);
decreaseIndentIf(linesBeforeOperator, linesAfterOperator);
decreaseIndentIf(linesBeforeOperator > 0, linesAfterOperator > 0);
stackIndex--;
break;
}
Expand Down Expand Up @@ -2529,13 +2529,13 @@ namespace ts {
emit(node.questionToken);
writeLinesAndIndent(linesAfterQuestion, /*writeSpaceIfNotIndenting*/ true);
emitExpression(node.whenTrue);
decreaseIndentIf(linesBeforeQuestion, linesAfterQuestion);
decreaseIndentIf(linesBeforeQuestion > 0, linesAfterQuestion > 0);

writeLinesAndIndent(linesBeforeColon, /*writeSpaceIfNotIndenting*/ true);
emit(node.colonToken);
writeLinesAndIndent(linesAfterColon, /*writeSpaceIfNotIndenting*/ true);
emitExpression(node.whenFalse);
decreaseIndentIf(linesBeforeColon, linesAfterColon);
decreaseIndentIf(linesBeforeColon > 0, linesAfterColon > 0);
}

function emitTemplateExpression(node: TemplateExpression) {
Expand Down Expand Up @@ -4010,7 +4010,7 @@ namespace ts {
let shouldEmitInterveningComments = mayEmitInterveningComments;
const leadingLineTerminatorCount = getLeadingLineTerminatorCount(parentNode, children!, format); // TODO: GH#18217
if (leadingLineTerminatorCount) {
writeLine(leadingLineTerminatorCount);
writeBlankLines(leadingLineTerminatorCount);
shouldEmitInterveningComments = false;
}
else if (format & ListFormat.SpaceBetweenBraces) {
Expand Down Expand Up @@ -4058,7 +4058,7 @@ namespace ts {
shouldDecreaseIndentAfterEmit = true;
}

writeLine(separatingLineTerminatorCount);
writeBlankLines(separatingLineTerminatorCount);
shouldEmitInterveningComments = false;
}
else if (previousSibling && format & ListFormat.SpaceBetweenSiblings) {
Expand Down Expand Up @@ -4115,7 +4115,7 @@ namespace ts {
// Write the closing line terminator or closing whitespace.
const closingLineTerminatorCount = getClosingLineTerminatorCount(parentNode, children!, format);
if (closingLineTerminatorCount) {
writeLine(closingLineTerminatorCount);
writeBlankLines(closingLineTerminatorCount);
}
else if (format & ListFormat.SpaceBetweenBraces) {
writeSpace();
Expand Down Expand Up @@ -4185,10 +4185,8 @@ namespace ts {
writer.writeProperty(s);
}

function writeLine(count = 1) {
for (let i = 0; i < count; i++) {
writer.writeLine(i > 0);
}
function writeLine() {
writer.writeLine();
}

function increaseIndent() {
Expand Down Expand Up @@ -4244,10 +4242,21 @@ namespace ts {
}
}

function writeBlankLines(lineCount: number) {
for (let i = 0; i < lineCount; i++) {
if (i === 0) {
writer.writeLine();
}
else {
writer.forceWriteLine();
}
}
}

function writeLinesAndIndent(lineCount: number, writeSpaceIfNotIndenting: boolean) {
if (lineCount) {
increaseIndent();
writeLine(lineCount);
writeBlankLines(lineCount);
}
else if (writeSpaceIfNotIndenting) {
writeSpace();
Expand All @@ -4258,7 +4267,7 @@ namespace ts {
// previous indent values to be considered at a time. This also allows caller to just
// call this once, passing in all their appropriate indent values, instead of needing
// to call this helper function multiple times.
function decreaseIndentIf(value1: boolean | number, value2: boolean | number) {
function decreaseIndentIf(value1: boolean, value2: boolean) {
if (value1) {
decreaseIndent();
}
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3753,7 +3753,7 @@ namespace ts {
writeParameter(text: string): void;
writeProperty(text: string): void;
writeSymbol(text: string, symbol: Symbol): void;
writeLine(force?: boolean): void;
writeLine(): void;
increaseIndent(): void;
decreaseIndent(): void;
clear(): void;
Expand Down Expand Up @@ -6328,6 +6328,7 @@ namespace ts {
getText(): string;
rawWrite(s: string): void;
writeLiteral(s: string): void;
forceWriteLine(): void;
getTextPos(): number;
getLine(): number;
getColumn(): number;
Expand Down
19 changes: 12 additions & 7 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3569,13 +3569,17 @@ namespace ts {
}
}

function writeLine(force?: boolean) {
if (!lineStart || force) {
output += newLine;
lineCount++;
linePos = output.length;
lineStart = true;
hasTrailingComment = false;
function forceWriteLine() {
output += newLine;
lineCount++;
linePos = output.length;
lineStart = true;
hasTrailingComment = false;
}

function writeLine() {
if (!lineStart) {
forceWriteLine();
}
}

Expand All @@ -3590,6 +3594,7 @@ namespace ts {
rawWrite,
writeLiteral,
writeLine,
forceWriteLine,
increaseIndent: () => { indent++; },
decreaseIndent: () => { indent--; },
getIndent: () => indent,
Expand Down

0 comments on commit e3ef427

Please sign in to comment.