@@ -89,7 +89,31 @@ assert(sourceFile, "Failed to load source file");
8989const moduleSymbol = typeChecker . getSymbolAtLocation ( sourceFile ) ;
9090assert ( moduleSymbol , "Failed to get module's symbol" ) ;
9191
92- const printer = ts . createPrinter ( { newLine : newLineKind } ) ;
92+ /** @type {{ writeNode(hint: ts.EmitHint, node: ts.Node, sourceFile: ts.SourceFile | undefined, writer: any): void } } */
93+ const printer = /** @type {any } */ ( ts . createPrinter ( { newLine : newLineKind } ) ) ;
94+ /** @type {{ writeComment(s: string): void; getText(): string; clear(): void } } */
95+ const writer = /** @type {any } */ ( ts ) . createTextWriter ( "\n" ) ;
96+ const originalWriteComment = writer . writeComment . bind ( writer ) ;
97+ writer . writeComment = s => {
98+ // Hack; undo https://github.com/microsoft/TypeScript/pull/50097
99+ // We printNode directly, so we get all of the original source comments.
100+ // If we were using actual declaration emit instead, this wouldn't be needed.
101+ if ( s . startsWith ( "//" ) ) {
102+ return ;
103+ }
104+ originalWriteComment ( s ) ;
105+ } ;
106+
107+ /**
108+ * @param {ts.Node } node
109+ * @param {ts.SourceFile } sourceFile
110+ */
111+ function printNode ( node , sourceFile ) {
112+ printer . writeNode ( ts . EmitHint . Unspecified , node , sourceFile , writer ) ;
113+ const text = writer . getText ( ) ;
114+ writer . clear ( ) ;
115+ return text ;
116+ }
93117
94118/** @type {string[] } */
95119const publicLines = [ ] ;
@@ -141,7 +165,7 @@ function write(s, target) {
141165 * @param {WriteTarget } target
142166 */
143167function writeNode ( node , sourceFile , target ) {
144- write ( printer . printNode ( ts . EmitHint . Unspecified , node , sourceFile ) , target ) ;
168+ write ( printNode ( node , sourceFile ) , target ) ;
145169}
146170
147171/** @type {Map<ts.Symbol, boolean> } */
0 commit comments