Skip to content

Commit 8050959

Browse files
committed
Some minor changes as per code review feedback
1 parent b5bd1bf commit 8050959

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/compiler/emitter.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ module ts {
177177
return text.substring(skipTrivia(text, node.pos), node.end);
178178
}
179179

180+
function getLineOfLocalPosition(pos: number) {
181+
return currentSourceFile.getLineAndCharacterFromPosition(pos).line;
182+
}
183+
180184
function writeFile(filename: string, data: string, writeByteOrderMark: boolean) {
181185
compilerHost.writeFile(filename, data, writeByteOrderMark, hostErrorMessage => {
182186
diagnostics.push(createCompilerDiagnostic(Diagnostics.Could_not_write_file_0_Colon_1, filename, hostErrorMessage));
@@ -193,7 +197,8 @@ module ts {
193197
writeComment(comment, writer);
194198
if (comment.hasTrailingNewLine) {
195199
writer.writeLine();
196-
} else if (trailingSeparator) {
200+
}
201+
else if (trailingSeparator) {
197202
writer.write(" ");
198203
}
199204
else {
@@ -206,7 +211,7 @@ module ts {
206211
function emitNewLineBeforeLeadingComments(node: TextRange, leadingComments: Comment[], writer: EmitTextWriter) {
207212
// If the leading comments start on different line than the start of node, write new line
208213
if (leadingComments && leadingComments.length && node.pos !== leadingComments[0].pos &&
209-
currentSourceFile.getLineAndCharacterFromPosition(node.pos).line !== currentSourceFile.getLineAndCharacterFromPosition(leadingComments[0].pos).line) {
214+
getLineOfLocalPosition(node.pos) !== getLineOfLocalPosition(leadingComments[0].pos)) {
210215
writer.writeLine();
211216
}
212217
}
@@ -1229,7 +1234,6 @@ module ts {
12291234
emitLeadingComments(node);
12301235
emitModuleMemberName(node);
12311236
emitOptional(" = ", node.initializer);
1232-
var variableStatement = <VariableStatement>node.parent;
12331237
emitTrailingComments(node);
12341238
}
12351239

@@ -2114,8 +2118,8 @@ module ts {
21142118

21152119
forEach(leadingComments, comment => {
21162120
if (lastComment) {
2117-
var lastCommentLine = currentSourceFile.getLineAndCharacterFromPosition(lastComment.end).line;
2118-
var commentLine = currentSourceFile.getLineAndCharacterFromPosition(comment.pos).line;
2121+
var lastCommentLine = getLineOfLocalPosition(lastComment.end);
2122+
var commentLine = getLineOfLocalPosition(comment.pos);
21192123

21202124
if (commentLine >= lastCommentLine + 2) {
21212125
// There was a blank line between the last comment and this comment. This
@@ -2133,8 +2137,8 @@ module ts {
21332137
// All comments look like they could have been part of the copyright header. Make
21342138
// sure there is at least one blank line between it and the node. If not, it's not
21352139
// a copyright header.
2136-
var lastCommentLine = currentSourceFile.getLineAndCharacterFromPosition(detachedComments[detachedComments.length - 1].end).line;
2137-
var astLine = currentSourceFile.getLineAndCharacterFromPosition(skipTrivia(currentSourceFile.text, node.pos)).line;
2140+
var lastCommentLine = getLineOfLocalPosition(detachedComments[detachedComments.length - 1].end);
2141+
var astLine = getLineOfLocalPosition(skipTrivia(currentSourceFile.text, node.pos));
21382142
if (astLine >= lastCommentLine + 2) {
21392143
// Valid detachedComments
21402144
emitNewLineBeforeLeadingComments(node, leadingComments, writer);

0 commit comments

Comments
 (0)