@@ -5,13 +5,16 @@ namespace ts {
5
5
export interface CommentWriter {
6
6
reset ( ) : void ;
7
7
setSourceFile ( sourceFile : SourceFile ) : void ;
8
+ setWriter ( writer : EmitTextWriter ) : void ;
8
9
emitNodeWithComments ( hint : EmitHint , node : Node , emitCallback : ( hint : EmitHint , node : Node ) => void ) : void ;
9
10
emitBodyWithDetachedComments ( node : Node , detachedRange : TextRange , emitCallback : ( node : Node ) => void ) : void ;
10
11
emitTrailingCommentsOfPosition ( pos : number ) : void ;
11
12
}
12
13
13
- export function createCommentWriter ( writer : EmitTextWriter , compilerOptions : CompilerOptions , newLine : string , emitPos : ( pos : number ) => void ) : CommentWriter {
14
- const extendedDiagnostics = compilerOptions . extendedDiagnostics ;
14
+ export function createCommentWriter ( printerOptions : PrinterOptions , emitPos : ( pos : number ) => void ) : CommentWriter {
15
+ const extendedDiagnostics = printerOptions . extendedDiagnostics ;
16
+ const newLine = getNewLineCharacter ( printerOptions ) ;
17
+ let writer : EmitTextWriter ;
15
18
let containerPos = - 1 ;
16
19
let containerEnd = - 1 ;
17
20
let declarationListContainerEnd = - 1 ;
@@ -20,10 +23,11 @@ namespace ts {
20
23
let currentLineMap : number [ ] ;
21
24
let detachedCommentsInfo : { nodePos : number , detachedCommentEndPos : number } [ ] ;
22
25
let hasWrittenComment = false ;
23
- let disabled : boolean = compilerOptions . removeComments ;
26
+ let disabled : boolean = printerOptions . removeComments ;
24
27
25
28
return {
26
29
reset,
30
+ setWriter,
27
31
setSourceFile,
28
32
emitNodeWithComments,
29
33
emitBodyWithDetachedComments,
@@ -194,9 +198,9 @@ namespace ts {
194
198
}
195
199
196
200
// Leading comments are emitted at /*leading comment1 */space/*leading comment*/space
197
- emitPos ( commentPos ) ;
201
+ if ( emitPos ) emitPos ( commentPos ) ;
198
202
writeCommentRange ( currentText , currentLineMap , writer , commentPos , commentEnd , newLine ) ;
199
- emitPos ( commentEnd ) ;
203
+ if ( emitPos ) emitPos ( commentEnd ) ;
200
204
201
205
if ( hasTrailingNewLine ) {
202
206
writer . writeLine ( ) ;
@@ -216,9 +220,9 @@ namespace ts {
216
220
writer . write ( " " ) ;
217
221
}
218
222
219
- emitPos ( commentPos ) ;
223
+ if ( emitPos ) emitPos ( commentPos ) ;
220
224
writeCommentRange ( currentText , currentLineMap , writer , commentPos , commentEnd , newLine ) ;
221
- emitPos ( commentEnd ) ;
225
+ if ( emitPos ) emitPos ( commentEnd ) ;
222
226
223
227
if ( hasTrailingNewLine ) {
224
228
writer . writeLine ( ) ;
@@ -244,9 +248,9 @@ namespace ts {
244
248
function emitTrailingCommentOfPosition ( commentPos : number , commentEnd : number , _kind : SyntaxKind , hasTrailingNewLine : boolean ) {
245
249
// trailing comments of a position are emitted at /*trailing comment1 */space/*trailing comment*/space
246
250
247
- emitPos ( commentPos ) ;
251
+ if ( emitPos ) emitPos ( commentPos ) ;
248
252
writeCommentRange ( currentText , currentLineMap , writer , commentPos , commentEnd , newLine ) ;
249
- emitPos ( commentEnd ) ;
253
+ if ( emitPos ) emitPos ( commentEnd ) ;
250
254
251
255
if ( hasTrailingNewLine ) {
252
256
writer . writeLine ( ) ;
@@ -282,6 +286,10 @@ namespace ts {
282
286
detachedCommentsInfo = undefined ;
283
287
}
284
288
289
+ function setWriter ( output : EmitTextWriter ) : void {
290
+ writer = output ;
291
+ }
292
+
285
293
function setSourceFile ( sourceFile : SourceFile ) {
286
294
currentSourceFile = sourceFile ;
287
295
currentText = currentSourceFile . text ;
@@ -319,9 +327,9 @@ namespace ts {
319
327
}
320
328
321
329
function writeComment ( text : string , lineMap : number [ ] , writer : EmitTextWriter , commentPos : number , commentEnd : number , newLine : string ) {
322
- emitPos ( commentPos ) ;
330
+ if ( emitPos ) emitPos ( commentPos ) ;
323
331
writeCommentRange ( text , lineMap , writer , commentPos , commentEnd , newLine ) ;
324
- emitPos ( commentEnd ) ;
332
+ if ( emitPos ) emitPos ( commentEnd ) ;
325
333
}
326
334
327
335
/**
0 commit comments