Skip to content

Commit e3ef427

Browse files
committed
Restore some monomorphism
1 parent c91efd4 commit e3ef427

File tree

3 files changed

+36
-21
lines changed

3 files changed

+36
-21
lines changed

Diff for: src/compiler/emitter.ts

+22-13
Original file line numberDiff line numberDiff line change
@@ -2297,7 +2297,7 @@ namespace ts {
22972297
emitTokenWithComment(token.kind, node.expression.end, writePunctuation, node);
22982298
writeLinesAndIndent(linesAfterDot, /*writeSpaceIfNotIndenting*/ false);
22992299
emit(node.name);
2300-
decreaseIndentIf(linesBeforeDot, linesAfterDot);
2300+
decreaseIndentIf(linesBeforeDot > 0, linesAfterDot > 0);
23012301
}
23022302

23032303
// 1..toString is a valid property access, emit a dot after the literal
@@ -2475,7 +2475,7 @@ namespace ts {
24752475
case EmitBinaryExpressionState.FinishEmit: {
24762476
const linesBeforeOperator = getLinesBetweenNodes(node, node.left, node.operatorToken);
24772477
const linesAfterOperator = getLinesBetweenNodes(node, node.operatorToken, node.right);
2478-
decreaseIndentIf(linesBeforeOperator, linesAfterOperator);
2478+
decreaseIndentIf(linesBeforeOperator > 0, linesAfterOperator > 0);
24792479
stackIndex--;
24802480
break;
24812481
}
@@ -2529,13 +2529,13 @@ namespace ts {
25292529
emit(node.questionToken);
25302530
writeLinesAndIndent(linesAfterQuestion, /*writeSpaceIfNotIndenting*/ true);
25312531
emitExpression(node.whenTrue);
2532-
decreaseIndentIf(linesBeforeQuestion, linesAfterQuestion);
2532+
decreaseIndentIf(linesBeforeQuestion > 0, linesAfterQuestion > 0);
25332533

25342534
writeLinesAndIndent(linesBeforeColon, /*writeSpaceIfNotIndenting*/ true);
25352535
emit(node.colonToken);
25362536
writeLinesAndIndent(linesAfterColon, /*writeSpaceIfNotIndenting*/ true);
25372537
emitExpression(node.whenFalse);
2538-
decreaseIndentIf(linesBeforeColon, linesAfterColon);
2538+
decreaseIndentIf(linesBeforeColon > 0, linesAfterColon > 0);
25392539
}
25402540

25412541
function emitTemplateExpression(node: TemplateExpression) {
@@ -4010,7 +4010,7 @@ namespace ts {
40104010
let shouldEmitInterveningComments = mayEmitInterveningComments;
40114011
const leadingLineTerminatorCount = getLeadingLineTerminatorCount(parentNode, children!, format); // TODO: GH#18217
40124012
if (leadingLineTerminatorCount) {
4013-
writeLine(leadingLineTerminatorCount);
4013+
writeBlankLines(leadingLineTerminatorCount);
40144014
shouldEmitInterveningComments = false;
40154015
}
40164016
else if (format & ListFormat.SpaceBetweenBraces) {
@@ -4058,7 +4058,7 @@ namespace ts {
40584058
shouldDecreaseIndentAfterEmit = true;
40594059
}
40604060

4061-
writeLine(separatingLineTerminatorCount);
4061+
writeBlankLines(separatingLineTerminatorCount);
40624062
shouldEmitInterveningComments = false;
40634063
}
40644064
else if (previousSibling && format & ListFormat.SpaceBetweenSiblings) {
@@ -4115,7 +4115,7 @@ namespace ts {
41154115
// Write the closing line terminator or closing whitespace.
41164116
const closingLineTerminatorCount = getClosingLineTerminatorCount(parentNode, children!, format);
41174117
if (closingLineTerminatorCount) {
4118-
writeLine(closingLineTerminatorCount);
4118+
writeBlankLines(closingLineTerminatorCount);
41194119
}
41204120
else if (format & ListFormat.SpaceBetweenBraces) {
41214121
writeSpace();
@@ -4185,10 +4185,8 @@ namespace ts {
41854185
writer.writeProperty(s);
41864186
}
41874187

4188-
function writeLine(count = 1) {
4189-
for (let i = 0; i < count; i++) {
4190-
writer.writeLine(i > 0);
4191-
}
4188+
function writeLine() {
4189+
writer.writeLine();
41924190
}
41934191

41944192
function increaseIndent() {
@@ -4244,10 +4242,21 @@ namespace ts {
42444242
}
42454243
}
42464244

4245+
function writeBlankLines(lineCount: number) {
4246+
for (let i = 0; i < lineCount; i++) {
4247+
if (i === 0) {
4248+
writer.writeLine();
4249+
}
4250+
else {
4251+
writer.forceWriteLine();
4252+
}
4253+
}
4254+
}
4255+
42474256
function writeLinesAndIndent(lineCount: number, writeSpaceIfNotIndenting: boolean) {
42484257
if (lineCount) {
42494258
increaseIndent();
4250-
writeLine(lineCount);
4259+
writeBlankLines(lineCount);
42514260
}
42524261
else if (writeSpaceIfNotIndenting) {
42534262
writeSpace();
@@ -4258,7 +4267,7 @@ namespace ts {
42584267
// previous indent values to be considered at a time. This also allows caller to just
42594268
// call this once, passing in all their appropriate indent values, instead of needing
42604269
// to call this helper function multiple times.
4261-
function decreaseIndentIf(value1: boolean | number, value2: boolean | number) {
4270+
function decreaseIndentIf(value1: boolean, value2: boolean) {
42624271
if (value1) {
42634272
decreaseIndent();
42644273
}

Diff for: src/compiler/types.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -3753,7 +3753,7 @@ namespace ts {
37533753
writeParameter(text: string): void;
37543754
writeProperty(text: string): void;
37553755
writeSymbol(text: string, symbol: Symbol): void;
3756-
writeLine(force?: boolean): void;
3756+
writeLine(): void;
37573757
increaseIndent(): void;
37583758
decreaseIndent(): void;
37593759
clear(): void;
@@ -6328,6 +6328,7 @@ namespace ts {
63286328
getText(): string;
63296329
rawWrite(s: string): void;
63306330
writeLiteral(s: string): void;
6331+
forceWriteLine(): void;
63316332
getTextPos(): number;
63326333
getLine(): number;
63336334
getColumn(): number;

Diff for: src/compiler/utilities.ts

+12-7
Original file line numberDiff line numberDiff line change
@@ -3569,13 +3569,17 @@ namespace ts {
35693569
}
35703570
}
35713571

3572-
function writeLine(force?: boolean) {
3573-
if (!lineStart || force) {
3574-
output += newLine;
3575-
lineCount++;
3576-
linePos = output.length;
3577-
lineStart = true;
3578-
hasTrailingComment = false;
3572+
function forceWriteLine() {
3573+
output += newLine;
3574+
lineCount++;
3575+
linePos = output.length;
3576+
lineStart = true;
3577+
hasTrailingComment = false;
3578+
}
3579+
3580+
function writeLine() {
3581+
if (!lineStart) {
3582+
forceWriteLine();
35793583
}
35803584
}
35813585

@@ -3590,6 +3594,7 @@ namespace ts {
35903594
rawWrite,
35913595
writeLiteral,
35923596
writeLine,
3597+
forceWriteLine,
35933598
increaseIndent: () => { indent++; },
35943599
decreaseIndent: () => { indent--; },
35953600
getIndent: () => indent,

0 commit comments

Comments
 (0)