Skip to content

Commit d970c89

Browse files
committed
Declaration comments for function declarations in .d.ts
1 parent 758fc93 commit d970c89

15 files changed

+144
-0
lines changed

src/compiler/emitter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2523,6 +2523,7 @@ module ts {
25232523
// so no need to verify if the declaration is visible
25242524
if ((node.kind !== SyntaxKind.FunctionDeclaration || resolver.isDeclarationVisible(node)) &&
25252525
!resolver.isImplementationOfOverload(node)) {
2526+
emitJsDocComments(node);
25262527
emitDeclarationFlags(node);
25272528
if (node.kind === SyntaxKind.FunctionDeclaration) {
25282529
write("function ");

tests/baselines/reference/commentsClass.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,14 @@ declare class c2 {
137137
declare var i2: c2;
138138
declare var i2_c: typeof c2;
139139
declare class c3 {
140+
/** Constructor comment*/
140141
constructor();
141142
}
142143
declare var i3: c3;
143144
declare var i3_c: typeof c3;
144145
/** Class comment*/
145146
declare class c4 {
147+
/** Constructor comment*/
146148
constructor();
147149
}
148150
declare var i4: c4;
@@ -170,6 +172,8 @@ declare var i7_c: typeof c7;
170172
declare class c8 {
171173
/** s1 comment */
172174
static s1: number;
175+
/** constructor comment
176+
*/
173177
constructor();
174178
}
175179
declare var i8: c8;

tests/baselines/reference/commentsClassMembers.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,19 +475,23 @@ cProperties_i.nc_p2 = cProperties_i.nc_p1;
475475
declare class c1 {
476476
/** p1 is property of c1*/
477477
p1: number;
478+
/** sum with property*/
478479
p2(b: number): number;
479480
/** getter property*/
480481
/** setter property*/
481482
p3: number;
482483
/** pp1 is property of c1*/
483484
private pp1;
485+
/** sum with property*/
484486
private pp2(b);
485487
/** getter property*/
486488
/** setter property*/
487489
private pp3;
490+
/** Constructor method*/
488491
constructor();
489492
/** s1 is static property of c1*/
490493
static s1: number;
494+
/** static sum with property*/
491495
static s2(b: number): number;
492496
/** static getter property*/
493497
/** setter property*/
@@ -512,18 +516,21 @@ declare class c1 {
512516
static a_s3: number;
513517
/** p1 is property of c1 */
514518
b_p1: number;
519+
/** sum with property */
515520
b_p2(b: number): number;
516521
/** getter property */
517522
/** setter property */
518523
b_p3: number;
519524
/** pp1 is property of c1 */
520525
private b_pp1;
526+
/** sum with property */
521527
private b_pp2(b);
522528
/** getter property */
523529
/** setter property */
524530
private b_pp3;
525531
/** s1 is static property of c1 */
526532
static b_s1: number;
533+
/** static sum with property */
527534
static b_s2(b: number): number;
528535
/** static getter property
529536
*/

tests/baselines/reference/commentsCommentParsing.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,25 +294,77 @@ var NoQuickInfoClass = (function () {
294294
//// [commentsCommentParsing.d.ts]
295295
declare function simple(): void;
296296
declare function multiLine(): void;
297+
/** this is eg of single line jsdoc style comment */
297298
declare function jsDocSingleLine(): void;
299+
/** this is multiple line jsdoc stule comment
300+
*New line1
301+
*New Line2*/
298302
declare function jsDocMultiLine(): void;
303+
/** this is multiple line jsdoc stule comment
304+
*New line1
305+
*New Line2*/
306+
/** Shoul mege this line as well
307+
* and this too*/ /** Another this one too*/
299308
declare function jsDocMultiLineMerge(): void;
309+
/** jsdoc comment */
300310
declare function jsDocMixedComments1(): void;
311+
/** jsdoc comment */ /*** another jsDocComment*/
301312
declare function jsDocMixedComments2(): void;
313+
/** jsdoc comment */ /*** another jsDocComment*/
302314
declare function jsDocMixedComments3(): void;
315+
/** jsdoc comment */ /*** another jsDocComment*/
303316
declare function jsDocMixedComments4(): void;
317+
/** jsdoc comment */ /*** another jsDocComment*/
304318
declare function jsDocMixedComments5(): void;
319+
/*** another jsDocComment*/
320+
/** jsdoc comment */
305321
declare function jsDocMixedComments6(): void;
306322
declare function noHelpComment1(): void;
307323
declare function noHelpComment2(): void;
308324
declare function noHelpComment3(): void;
325+
/** Adds two integers and returns the result
326+
* @param {number} a first number
327+
* @param b second number
328+
*/
309329
declare function sum(a: number, b: number): number;
330+
/** This is multiplication function*/
331+
/** @param */
332+
/** @param a first number*/
333+
/** @param b */
334+
/** @param c {
335+
@param d @anotherTag*/
336+
/** @param e LastParam @anotherTag*/
310337
declare function multiply(a: number, b: number, c?: number, d?: any, e?: any): void;
338+
/** fn f1 with number
339+
* @param { string} b about b
340+
*/
311341
declare function f1(a: number): any;
312342
declare function f1(b: string): any;
343+
/** This is subtract function
344+
@param { a
345+
*@param { number | } b this is about b
346+
@param { { () => string; } } c this is optional param c
347+
@param { { () => string; } d this is optional param d
348+
@param { { () => string; } } e this is optional param e
349+
@param { { { () => string; } } f this is optional param f
350+
*/
313351
declare function subtract(a: number, b: number, c?: () => string, d?: () => string, e?: () => string, f?: () => string): void;
352+
/** this is square function
353+
@paramTag { number } a this is input number of paramTag
354+
@param { number } a this is input number
355+
@returnType { number } it is return type
356+
*/
314357
declare function square(a: number): number;
358+
/** this is divide function
359+
@param { number} a this is a
360+
@paramTag { number } g this is optional param g
361+
@param { number} b this is b
362+
*/
315363
declare function divide(a: number, b: number): void;
364+
/** this is jsdoc style function with param tag as well as inline parameter help
365+
*@param a it is first parameter
366+
*@param c it is third parameter
367+
*/
316368
declare function jsDocParamTest(a: number, b: number, c: number, d: number): number;
317369
declare class NoQuickInfoClass {
318370
}

tests/baselines/reference/commentsExternalModules.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ export declare module m1 {
150150
/** i*/
151151
var i: c;
152152
}
153+
/** exported function*/
153154
function fooExport(): number;
154155
}
155156
/** Module comment */
@@ -165,6 +166,7 @@ export declare module m4 {
165166
/** i */
166167
var i: c;
167168
}
169+
/** exported function */
168170
function fooExport(): number;
169171
}
170172
//// [commentsExternalModules_1.d.ts]

tests/baselines/reference/commentsExternalModules2.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ export declare module m1 {
150150
/** i*/
151151
var i: c;
152152
}
153+
/** exported function*/
153154
function fooExport(): number;
154155
}
155156
/** Module comment */
@@ -165,6 +166,7 @@ export declare module m4 {
165166
/** i */
166167
var i: c;
167168
}
169+
/** exported function */
168170
function fooExport(): number;
169171
}
170172
//// [commentsExternalModules_1.d.ts]

tests/baselines/reference/commentsFunction.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ lambddaNoVarComment(10, 20);
4949

5050

5151
//// [commentsFunction.d.ts]
52+
/** This comment should appear for foo*/
5253
declare function foo(): void;
54+
/** This is comment for function signature*/
5355
declare function fooWithParameters(a: string, b: number): void;
5456
/** fooFunc
5557
* comment

tests/baselines/reference/commentsInheritance.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ i2_i = i3_i;
272272
interface i1 {
273273
/** i1_p1*/
274274
i1_p1: number;
275+
/** i1_f1*/
275276
i1_f1(): void;
276277
/** i1_l1*/
277278
i1_l1: () => void;
@@ -294,11 +295,13 @@ declare class c1 implements i1 {
294295
i1_nc_l1: () => void;
295296
/** c1_p1*/
296297
p1: number;
298+
/** c1_f1*/
297299
f1(): void;
298300
/** c1_l1*/
299301
l1: () => void;
300302
/** c1_nc_p1*/
301303
nc_p1: number;
304+
/** c1_nc_f1*/
302305
nc_f1(): void;
303306
/** c1_nc_l1*/
304307
nc_l1: () => void;
@@ -308,6 +311,7 @@ declare var c1_i: c1;
308311
declare class c2 {
309312
/** c2 c2_p1*/
310313
c2_p1: number;
314+
/** c2 c2_f1*/
311315
c2_f1(): void;
312316
/** c2 c2_prop*/
313317
c2_prop: number;
@@ -316,18 +320,21 @@ declare class c2 {
316320
c2_nc_prop: number;
317321
/** c2 p1*/
318322
p1: number;
323+
/** c2 f1*/
319324
f1(): void;
320325
/** c2 prop*/
321326
prop: number;
322327
nc_p1: number;
323328
nc_f1(): void;
324329
nc_prop: number;
330+
/** c2 constructor*/
325331
constructor(a: number);
326332
}
327333
declare class c3 extends c2 {
328334
constructor();
329335
/** c3 p1*/
330336
p1: number;
337+
/** c3 f1*/
331338
f1(): void;
332339
/** c3 prop*/
333340
prop: number;
@@ -343,6 +350,7 @@ declare var c4_i: c4;
343350
interface i2 {
344351
/** i2_p1*/
345352
i2_p1: number;
353+
/** i2_f1*/
346354
i2_f1(): void;
347355
/** i2_l1*/
348356
i2_l1: () => void;
@@ -351,6 +359,7 @@ interface i2 {
351359
i2_nc_l1: () => void;
352360
/** i2 p1*/
353361
p1: number;
362+
/** i2 f1*/
354363
f1(): void;
355364
/** i2 l1*/
356365
l1: () => void;
@@ -361,6 +370,9 @@ interface i2 {
361370
interface i3 extends i2 {
362371
/** i3 p1 */
363372
p1: number;
373+
/**
374+
* i3 f1
375+
*/
364376
f1(): void;
365377
/** i3 l1*/
366378
l1: () => void;

tests/baselines/reference/commentsInterface.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ interface i2 {
123123
nc_foo: (b: number) => string;
124124
[i: number]: number;
125125
(a: number, b: number): number;
126+
/** this is fnfoo*/
126127
fnfoo(b: number): string;
127128
nc_fnfoo(b: number): string;
128129
nc_y: number;
@@ -145,6 +146,7 @@ declare var i2_i_nc_fnfoo_r: string;
145146
interface i3 {
146147
/** Comment i3 x*/
147148
x: number;
149+
/** Function i3 f*/
148150
f(a: number): string;
149151
/** i3 l*/
150152
l: (b: number) => string;

tests/baselines/reference/commentsModules.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,12 @@ declare module m1 {
283283
/** i*/
284284
var i: c;
285285
}
286+
/** exported function*/
286287
function fooExport(): number;
287288
function foo2Export(a: string): void;
289+
/** foo3Export
290+
* comment
291+
*/
288292
function foo3Export(): void;
289293
}
290294
declare var myvar: m1.m2.c;

0 commit comments

Comments
 (0)