File tree 6 files changed +61
-4
lines changed 6 files changed +61
-4
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ namespace ts {
8
8
setWriter ( writer : EmitTextWriter ) : void ;
9
9
emitNodeWithComments ( hint : EmitHint , node : Node , emitCallback : ( hint : EmitHint , node : Node ) => void ) : void ;
10
10
emitBodyWithDetachedComments ( node : Node , detachedRange : TextRange , emitCallback : ( node : Node ) => void ) : void ;
11
- emitTrailingCommentsOfPosition ( pos : number ) : void ;
11
+ emitTrailingCommentsOfPosition ( pos : number , prefixSpace ?: boolean ) : void ;
12
12
emitLeadingCommentsOfPosition ( pos : number ) : void ;
13
13
}
14
14
@@ -306,7 +306,7 @@ namespace ts {
306
306
}
307
307
}
308
308
309
- function emitTrailingCommentsOfPosition ( pos : number ) {
309
+ function emitTrailingCommentsOfPosition ( pos : number , prefixSpace ?: boolean ) {
310
310
if ( disabled ) {
311
311
return ;
312
312
}
@@ -315,7 +315,7 @@ namespace ts {
315
315
performance . mark ( "beforeEmitTrailingCommentsOfPosition" ) ;
316
316
}
317
317
318
- forEachTrailingCommentToEmit ( pos , emitTrailingCommentOfPosition ) ;
318
+ forEachTrailingCommentToEmit ( pos , prefixSpace ? emitTrailingComment : emitTrailingCommentOfPosition ) ;
319
319
320
320
if ( extendedDiagnostics ) {
321
321
performance . measure ( "commentTime" , "beforeEmitTrailingCommentsOfPosition" ) ;
Original file line number Diff line number Diff line change @@ -1572,8 +1572,20 @@ namespace ts {
1572
1572
write ( ";" ) ;
1573
1573
}
1574
1574
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
+
1575
1587
function emitReturnStatement ( node : ReturnStatement ) {
1576
- writeToken ( SyntaxKind . ReturnKeyword , node . pos , /*contextNode*/ node ) ;
1588
+ emitTokenWithComment ( SyntaxKind . ReturnKeyword , node . pos , /*contextNode*/ node ) ;
1577
1589
emitExpressionWithPrefix ( " " , node . expression ) ;
1578
1590
write ( ";" ) ;
1579
1591
}
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