Skip to content

Commit a928ad3

Browse files
author
Kanchalai Tanglertsampan
committed
Address code review: move only expose emitLeadingCommentsOfPosition
1 parent 80eae16 commit a928ad3

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

src/compiler/comments.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace ts {
99
emitNodeWithComments(hint: EmitHint, node: Node, emitCallback: (hint: EmitHint, node: Node) => void): void;
1010
emitBodyWithDetachedComments(node: Node, detachedRange: TextRange, emitCallback: (node: Node) => void): void;
1111
emitTrailingCommentsOfPosition(pos: number): void;
12-
emitLeadingComments(pos: number, isEmittedNode: boolean): void;
12+
emitLeadingCommentsOfPosition(pos: number): void;
1313
}
1414

1515
export function createCommentWriter(printerOptions: PrinterOptions, emitPos: ((pos: number) => void) | undefined): CommentWriter {
@@ -33,7 +33,7 @@ namespace ts {
3333
emitNodeWithComments,
3434
emitBodyWithDetachedComments,
3535
emitTrailingCommentsOfPosition,
36-
emitLeadingComments,
36+
emitLeadingCommentsOfPosition,
3737
};
3838

3939
function emitNodeWithComments(hint: EmitHint, node: Node, emitCallback: (hint: EmitHint, node: Node) => void) {
@@ -169,10 +169,6 @@ namespace ts {
169169
}
170170

171171
function emitLeadingComments(pos: number, isEmittedNode: boolean) {
172-
if (disabled) {
173-
return;
174-
}
175-
176172
hasWrittenComment = false;
177173

178174
if (isEmittedNode) {
@@ -216,6 +212,14 @@ namespace ts {
216212
}
217213
}
218214

215+
function emitLeadingCommentsOfPosition(pos: number) {
216+
if (disabled || pos === -1) {
217+
return;
218+
}
219+
220+
emitLeadingComments(pos, /*isEmittedNode*/ true);
221+
}
222+
219223
function emitTrailingComments(pos: number) {
220224
forEachTrailingCommentToEmit(pos, emitTrailingComment);
221225
}

src/compiler/emitter.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// <reference path="checker.ts" />
1+
/// <reference path="checker.ts" />
22
/// <reference path="transformer.ts" />
33
/// <reference path="declarationEmitter.ts" />
44
/// <reference path="sourcemap.ts" />
@@ -211,7 +211,7 @@ namespace ts {
211211
emitNodeWithComments,
212212
emitBodyWithDetachedComments,
213213
emitTrailingCommentsOfPosition,
214-
emitLeadingComments,
214+
emitLeadingCommentsOfPosition,
215215
} = comments;
216216

217217
let currentSourceFile: SourceFile;
@@ -1348,7 +1348,7 @@ namespace ts {
13481348
writeToken(SyntaxKind.OpenBraceToken, node.pos, /*contextNode*/ node);
13491349
emitBlockStatements(node);
13501350
// We have to call emitLeadingComments explicitly here because otherwise leading comments of the close brace token will not be emitted
1351-
emitLeadingComments(node.statements.end, /*isEmittedNode*/true);
1351+
emitLeadingCommentsOfPosition(node.statements.end);
13521352
writeToken(SyntaxKind.CloseBraceToken, node.statements.end, /*contextNode*/ node);
13531353
}
13541354
}
@@ -2235,10 +2235,10 @@ namespace ts {
22352235
// function commentedParameters(
22362236
// /* Parameter a */
22372237
// a
2238-
// /* End of parameter a */ -> this comment doesn't consider to be trailing comment of parameter "a" due to newline
2238+
// /* End of parameter a */ -> this comment isn't considered to be trailing comment of parameter "a" due to newline
22392239
// ,
2240-
if (emitLeadingComments && delimiter && previousSibling.end !== parentNode.end) {
2241-
emitLeadingComments(previousSibling.end, /*isEmittedNode*/ previousSibling.kind !== SyntaxKind.NotEmittedStatement);
2240+
if (emitLeadingCommentsOfPosition && delimiter && previousSibling.end !== parentNode.end) {
2241+
emitLeadingCommentsOfPosition(previousSibling.end);
22422242
}
22432243
write(delimiter);
22442244

@@ -2294,10 +2294,7 @@ namespace ts {
22942294
// /* end of element 2 */
22952295
// ];
22962296
if (previousSibling && delimiter && previousSibling.end !== parentNode.end) {
2297-
emitLeadingComments(previousSibling.end, /*isEmittedNode*/ previousSibling.kind !== SyntaxKind.NotEmittedStatement);
2298-
if (hasTrailingComma) {
2299-
emitLeadingComments(previousSibling.end, /*isEmittedNode*/ previousSibling.kind !== SyntaxKind.NotEmittedStatement);
2300-
}
2297+
emitLeadingCommentsOfPosition(previousSibling.end);
23012298
}
23022299

23032300
// Decrease the indent, if requested.

0 commit comments

Comments
 (0)