@@ -5,13 +5,16 @@ namespace ts {
55 export interface CommentWriter {
66 reset ( ) : void ;
77 setSourceFile ( sourceFile : SourceFile ) : void ;
8+ setWriter ( writer : EmitTextWriter ) : void ;
89 emitNodeWithComments ( hint : EmitHint , node : Node , emitCallback : ( hint : EmitHint , node : Node ) => void ) : void ;
910 emitBodyWithDetachedComments ( node : Node , detachedRange : TextRange , emitCallback : ( node : Node ) => void ) : void ;
1011 emitTrailingCommentsOfPosition ( pos : number ) : void ;
1112 }
1213
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 ;
1518 let containerPos = - 1 ;
1619 let containerEnd = - 1 ;
1720 let declarationListContainerEnd = - 1 ;
@@ -20,10 +23,11 @@ namespace ts {
2023 let currentLineMap : number [ ] ;
2124 let detachedCommentsInfo : { nodePos : number , detachedCommentEndPos : number } [ ] ;
2225 let hasWrittenComment = false ;
23- let disabled : boolean = compilerOptions . removeComments ;
26+ let disabled : boolean = printerOptions . removeComments ;
2427
2528 return {
2629 reset,
30+ setWriter,
2731 setSourceFile,
2832 emitNodeWithComments,
2933 emitBodyWithDetachedComments,
@@ -194,9 +198,9 @@ namespace ts {
194198 }
195199
196200 // Leading comments are emitted at /*leading comment1 */space/*leading comment*/space
197- emitPos ( commentPos ) ;
201+ if ( emitPos ) emitPos ( commentPos ) ;
198202 writeCommentRange ( currentText , currentLineMap , writer , commentPos , commentEnd , newLine ) ;
199- emitPos ( commentEnd ) ;
203+ if ( emitPos ) emitPos ( commentEnd ) ;
200204
201205 if ( hasTrailingNewLine ) {
202206 writer . writeLine ( ) ;
@@ -216,9 +220,9 @@ namespace ts {
216220 writer . write ( " " ) ;
217221 }
218222
219- emitPos ( commentPos ) ;
223+ if ( emitPos ) emitPos ( commentPos ) ;
220224 writeCommentRange ( currentText , currentLineMap , writer , commentPos , commentEnd , newLine ) ;
221- emitPos ( commentEnd ) ;
225+ if ( emitPos ) emitPos ( commentEnd ) ;
222226
223227 if ( hasTrailingNewLine ) {
224228 writer . writeLine ( ) ;
@@ -244,9 +248,9 @@ namespace ts {
244248 function emitTrailingCommentOfPosition ( commentPos : number , commentEnd : number , _kind : SyntaxKind , hasTrailingNewLine : boolean ) {
245249 // trailing comments of a position are emitted at /*trailing comment1 */space/*trailing comment*/space
246250
247- emitPos ( commentPos ) ;
251+ if ( emitPos ) emitPos ( commentPos ) ;
248252 writeCommentRange ( currentText , currentLineMap , writer , commentPos , commentEnd , newLine ) ;
249- emitPos ( commentEnd ) ;
253+ if ( emitPos ) emitPos ( commentEnd ) ;
250254
251255 if ( hasTrailingNewLine ) {
252256 writer . writeLine ( ) ;
@@ -282,6 +286,10 @@ namespace ts {
282286 detachedCommentsInfo = undefined ;
283287 }
284288
289+ function setWriter ( output : EmitTextWriter ) : void {
290+ writer = output ;
291+ }
292+
285293 function setSourceFile ( sourceFile : SourceFile ) {
286294 currentSourceFile = sourceFile ;
287295 currentText = currentSourceFile . text ;
@@ -319,9 +327,9 @@ namespace ts {
319327 }
320328
321329 function writeComment ( text : string , lineMap : number [ ] , writer : EmitTextWriter , commentPos : number , commentEnd : number , newLine : string ) {
322- emitPos ( commentPos ) ;
330+ if ( emitPos ) emitPos ( commentPos ) ;
323331 writeCommentRange ( text , lineMap , writer , commentPos , commentEnd , newLine ) ;
324- emitPos ( commentEnd ) ;
332+ if ( emitPos ) emitPos ( commentEnd ) ;
325333 }
326334
327335 /**
0 commit comments