File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ namespace ts {
88 setWriter ( writer : EmitTextWriter ) : void ;
99 emitNodeWithComments ( hint : EmitHint , node : Node , emitCallback : ( hint : EmitHint , node : Node ) => void ) : void ;
1010 emitBodyWithDetachedComments ( node : Node , detachedRange : TextRange , emitCallback : ( node : Node ) => void ) : void ;
11- emitTrailingCommentsOfPosition ( pos : number ) : void ;
11+ emitTrailingCommentsOfPosition ( pos : number , prefixSpace ?: boolean ) : void ;
1212 emitLeadingCommentsOfPosition ( pos : number ) : void ;
1313 }
1414
@@ -306,7 +306,7 @@ namespace ts {
306306 }
307307 }
308308
309- function emitTrailingCommentsOfPosition ( pos : number ) {
309+ function emitTrailingCommentsOfPosition ( pos : number , prefixSpace ?: boolean ) {
310310 if ( disabled ) {
311311 return ;
312312 }
@@ -315,7 +315,7 @@ namespace ts {
315315 performance . mark ( "beforeEmitTrailingCommentsOfPosition" ) ;
316316 }
317317
318- forEachTrailingCommentToEmit ( pos , emitTrailingCommentOfPosition ) ;
318+ forEachTrailingCommentToEmit ( pos , prefixSpace ? emitTrailingComment : emitTrailingCommentOfPosition ) ;
319319
320320 if ( extendedDiagnostics ) {
321321 performance . measure ( "commentTime" , "beforeEmitTrailingCommentsOfPosition" ) ;
Original file line number Diff line number Diff line change @@ -1572,8 +1572,20 @@ namespace ts {
15721572 write ( ";" ) ;
15731573 }
15741574
1575+ function emitTokenWithComment ( token : SyntaxKind , pos : number , contextNode ?: Node ) {
1576+ const node = contextNode && getParseTreeNode ( contextNode ) ;
1577+ if ( node && node . kind === contextNode . kind ) {
1578+ pos = skipTrivia ( currentSourceFile . text , pos ) ;
1579+ }
1580+ pos = writeToken ( token , pos , /*contextNode*/ contextNode ) ;
1581+ if ( node && node . kind === contextNode . kind ) {
1582+ emitTrailingCommentsOfPosition ( pos , /*prefixSpace*/ true ) ;
1583+ }
1584+ return pos ;
1585+ }
1586+
15751587 function emitReturnStatement ( node : ReturnStatement ) {
1576- writeToken ( SyntaxKind . ReturnKeyword , node . pos , /*contextNode*/ node ) ;
1588+ emitTokenWithComment ( SyntaxKind . ReturnKeyword , node . pos , /*contextNode*/ node ) ;
15771589 emitExpressionWithPrefix ( " " , node . expression ) ;
15781590 write ( ";" ) ;
15791591 }
Original file line number Diff line number Diff line change 1+ //// [jsdocCastCommentEmit.ts]
2+ // allowJs: true
3+ // checkJs: true
4+ // outDir: out/
5+ // filename: input.js
6+ function f ( ) {
7+ return /* @type {number } */ 42 ;
8+ }
9+
10+ //// [jsdocCastCommentEmit.js]
11+ // allowJs: true
12+ // checkJs: true
13+ // outDir: out/
14+ // filename: input.js
15+ function f ( ) {
16+ return /* @type {number } */ 42 ;
17+ }
Original file line number Diff line number Diff line change 1+ === tests/cases/compiler/jsdocCastCommentEmit.ts ===
2+ // allowJs: true
3+ // checkJs: true
4+ // outDir: out/
5+ // filename: input.js
6+ function f() {
7+ >f : Symbol(f, Decl(jsdocCastCommentEmit.ts, 0, 0))
8+
9+ return /* @type {number} */ 42;
10+ }
Original file line number Diff line number Diff line change 1+ === tests/cases/compiler/jsdocCastCommentEmit.ts ===
2+ // allowJs: true
3+ // checkJs: true
4+ // outDir: out/
5+ // filename: input.js
6+ function f() {
7+ >f : () => number
8+
9+ return /* @type {number} */ 42;
10+ >42 : 42
11+ }
Original file line number Diff line number Diff line change 1+ // allowJs: true
2+ // checkJs: true
3+ // outDir: out/
4+ // filename: input.js
5+ function f ( ) {
6+ return /* @type {number } */ 42 ;
7+ }
You can’t perform that action at this time.
0 commit comments