@@ -177,6 +177,10 @@ module ts {
177
177
return text . substring ( skipTrivia ( text , node . pos ) , node . end ) ;
178
178
}
179
179
180
+ function getLineOfLocalPosition ( pos : number ) {
181
+ return currentSourceFile . getLineAndCharacterFromPosition ( pos ) . line ;
182
+ }
183
+
180
184
function writeFile ( filename : string , data : string , writeByteOrderMark : boolean ) {
181
185
compilerHost . writeFile ( filename , data , writeByteOrderMark , hostErrorMessage => {
182
186
diagnostics . push ( createCompilerDiagnostic ( Diagnostics . Could_not_write_file_0_Colon_1 , filename , hostErrorMessage ) ) ;
@@ -193,7 +197,8 @@ module ts {
193
197
writeComment ( comment , writer ) ;
194
198
if ( comment . hasTrailingNewLine ) {
195
199
writer . writeLine ( ) ;
196
- } else if ( trailingSeparator ) {
200
+ }
201
+ else if ( trailingSeparator ) {
197
202
writer . write ( " " ) ;
198
203
}
199
204
else {
@@ -206,7 +211,7 @@ module ts {
206
211
function emitNewLineBeforeLeadingComments ( node : TextRange , leadingComments : Comment [ ] , writer : EmitTextWriter ) {
207
212
// If the leading comments start on different line than the start of node, write new line
208
213
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 ) ) {
210
215
writer . writeLine ( ) ;
211
216
}
212
217
}
@@ -1229,7 +1234,6 @@ module ts {
1229
1234
emitLeadingComments ( node ) ;
1230
1235
emitModuleMemberName ( node ) ;
1231
1236
emitOptional ( " = " , node . initializer ) ;
1232
- var variableStatement = < VariableStatement > node . parent ;
1233
1237
emitTrailingComments ( node ) ;
1234
1238
}
1235
1239
@@ -2114,8 +2118,8 @@ module ts {
2114
2118
2115
2119
forEach ( leadingComments , comment => {
2116
2120
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 ) ;
2119
2123
2120
2124
if ( commentLine >= lastCommentLine + 2 ) {
2121
2125
// There was a blank line between the last comment and this comment. This
@@ -2133,8 +2137,8 @@ module ts {
2133
2137
// All comments look like they could have been part of the copyright header. Make
2134
2138
// sure there is at least one blank line between it and the node. If not, it's not
2135
2139
// 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 ) ) ;
2138
2142
if ( astLine >= lastCommentLine + 2 ) {
2139
2143
// Valid detachedComments
2140
2144
emitNewLineBeforeLeadingComments ( node , leadingComments , writer ) ;
0 commit comments