Address code review: move only expose emitLeadingCommentsOfPosition

This commit is contained in:
Kanchalai Tanglertsampan
2017-02-08 10:17:58 -08:00
parent 80eae169ee
commit a928ad3bd3
2 changed files with 17 additions and 16 deletions

View File

@@ -9,7 +9,7 @@ namespace ts {
emitNodeWithComments(hint: EmitHint, node: Node, emitCallback: (hint: EmitHint, node: Node) => void): void;
emitBodyWithDetachedComments(node: Node, detachedRange: TextRange, emitCallback: (node: Node) => void): void;
emitTrailingCommentsOfPosition(pos: number): void;
emitLeadingComments(pos: number, isEmittedNode: boolean): void;
emitLeadingCommentsOfPosition(pos: number): void;
}
export function createCommentWriter(printerOptions: PrinterOptions, emitPos: ((pos: number) => void) | undefined): CommentWriter {
@@ -33,7 +33,7 @@ namespace ts {
emitNodeWithComments,
emitBodyWithDetachedComments,
emitTrailingCommentsOfPosition,
emitLeadingComments,
emitLeadingCommentsOfPosition,
};
function emitNodeWithComments(hint: EmitHint, node: Node, emitCallback: (hint: EmitHint, node: Node) => void) {
@@ -169,10 +169,6 @@ namespace ts {
}
function emitLeadingComments(pos: number, isEmittedNode: boolean) {
if (disabled) {
return;
}
hasWrittenComment = false;
if (isEmittedNode) {
@@ -216,6 +212,14 @@ namespace ts {
}
}
function emitLeadingCommentsOfPosition(pos: number) {
if (disabled || pos === -1) {
return;
}
emitLeadingComments(pos, /*isEmittedNode*/ true);
}
function emitTrailingComments(pos: number) {
forEachTrailingCommentToEmit(pos, emitTrailingComment);
}

View File

@@ -1,4 +1,4 @@
/// <reference path="checker.ts" />
/// <reference path="checker.ts" />
/// <reference path="transformer.ts" />
/// <reference path="declarationEmitter.ts" />
/// <reference path="sourcemap.ts" />
@@ -211,7 +211,7 @@ namespace ts {
emitNodeWithComments,
emitBodyWithDetachedComments,
emitTrailingCommentsOfPosition,
emitLeadingComments,
emitLeadingCommentsOfPosition,
} = comments;
let currentSourceFile: SourceFile;
@@ -1348,7 +1348,7 @@ namespace ts {
writeToken(SyntaxKind.OpenBraceToken, node.pos, /*contextNode*/ node);
emitBlockStatements(node);
// We have to call emitLeadingComments explicitly here because otherwise leading comments of the close brace token will not be emitted
emitLeadingComments(node.statements.end, /*isEmittedNode*/true);
emitLeadingCommentsOfPosition(node.statements.end);
writeToken(SyntaxKind.CloseBraceToken, node.statements.end, /*contextNode*/ node);
}
}
@@ -2235,10 +2235,10 @@ namespace ts {
// function commentedParameters(
// /* Parameter a */
// a
// /* End of parameter a */ -> this comment doesn't consider to be trailing comment of parameter "a" due to newline
// /* End of parameter a */ -> this comment isn't considered to be trailing comment of parameter "a" due to newline
// ,
if (emitLeadingComments && delimiter && previousSibling.end !== parentNode.end) {
emitLeadingComments(previousSibling.end, /*isEmittedNode*/ previousSibling.kind !== SyntaxKind.NotEmittedStatement);
if (emitLeadingCommentsOfPosition && delimiter && previousSibling.end !== parentNode.end) {
emitLeadingCommentsOfPosition(previousSibling.end);
}
write(delimiter);
@@ -2294,10 +2294,7 @@ namespace ts {
// /* end of element 2 */
// ];
if (previousSibling && delimiter && previousSibling.end !== parentNode.end) {
emitLeadingComments(previousSibling.end, /*isEmittedNode*/ previousSibling.kind !== SyntaxKind.NotEmittedStatement);
if (hasTrailingComma) {
emitLeadingComments(previousSibling.end, /*isEmittedNode*/ previousSibling.kind !== SyntaxKind.NotEmittedStatement);
}
emitLeadingCommentsOfPosition(previousSibling.end);
}
// Decrease the indent, if requested.