Skip to content

Commit 83ea28c

Browse files
committed
Declaration comments for the variable declaration in .d.ts
1 parent 77a3366 commit 83ea28c

File tree

8 files changed

+30
-0
lines changed

8 files changed

+30
-0
lines changed

src/compiler/emitter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2447,6 +2447,7 @@ module ts {
24472447
function emitVariableStatement(node: VariableStatement) {
24482448
var hasDeclarationWithEmit = forEach(node.declarations, varDeclaration => resolver.isDeclarationVisible(varDeclaration));
24492449
if (hasDeclarationWithEmit) {
2450+
emitJsDocComments(node);
24502451
emitDeclarationFlags(node);
24512452
write("var ");
24522453
emitCommaList(node.declarations, emitVariableDeclaration);

tests/baselines/reference/commentsExternalModules.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,25 +140,29 @@ define(["require", "exports", "commentsExternalModules_0"], function (require, e
140140
//// [commentsExternalModules_0.d.ts]
141141
/** Module comment*/
142142
export declare module m1 {
143+
/** b's comment*/
143144
var b: number;
144145
/** m2 comments*/
145146
module m2 {
146147
/** class comment;*/
147148
class c {
148149
}
150+
/** i*/
149151
var i: c;
150152
}
151153
function fooExport(): number;
152154
}
153155
/** Module comment */
154156
export declare module m4 {
157+
/** b's comment */
155158
var b: number;
156159
/** m2 comments
157160
*/
158161
module m2 {
159162
/** class comment; */
160163
class c {
161164
}
165+
/** i */
162166
var i: c;
163167
}
164168
function fooExport(): number;

tests/baselines/reference/commentsExternalModules2.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,25 +140,29 @@ define(["require", "exports", "commentsExternalModules2_0"], function (require,
140140
//// [commentsExternalModules2_0.d.ts]
141141
/** Module comment*/
142142
export declare module m1 {
143+
/** b's comment*/
143144
var b: number;
144145
/** m2 comments*/
145146
module m2 {
146147
/** class comment;*/
147148
class c {
148149
}
150+
/** i*/
149151
var i: c;
150152
}
151153
function fooExport(): number;
152154
}
153155
/** Module comment */
154156
export declare module m4 {
157+
/** b's comment */
155158
var b: number;
156159
/** m2 comments
157160
*/
158161
module m2 {
159162
/** class comment; */
160163
class c {
161164
}
165+
/** i */
162166
var i: c;
163167
}
164168
function fooExport(): number;

tests/baselines/reference/commentsFunction.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ lambddaNoVarComment(10, 20);
5151
//// [commentsFunction.d.ts]
5252
declare function foo(): void;
5353
declare function fooWithParameters(a: string, b: number): void;
54+
/** fooFunc
55+
* comment
56+
*/
5457
declare var fooFunc: (b: string) => string;
5558
declare var lambdaFoo: (a: number, b: number) => number;
5659
declare var lambddaNoVarComment: (a: number, b: number) => number;

tests/baselines/reference/commentsModules.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,14 @@ new m7.m8.m9.c();
273273
//// [commentsModules.d.ts]
274274
/** Module comment*/
275275
declare module m1 {
276+
/** b's comment*/
276277
var b: number;
277278
/** m2 comments*/
278279
module m2 {
279280
/** class comment;*/
280281
class c {
281282
}
283+
/** i*/
282284
var i: c;
283285
}
284286
function fooExport(): number;

tests/baselines/reference/commentsVarDecl.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,25 @@ n4 = z2;
7474

7575

7676
//// [commentsVarDecl.d.ts]
77+
/** Variable comments*/
7778
declare var myVariable: number;
79+
/** This is another variable comment*/
7880
declare var anotherVariable: number;
7981
declare var aVar: string;
82+
/** this is multiline comment
83+
* All these variables are of number type */
8084
declare var anotherAnotherVariable: number;
85+
/** Triple slash multiline comment*/
86+
/** another line in the comment*/
87+
/** comment line 2*/
8188
declare var x: number;
89+
/** triple slash comment1*/
90+
/** jsdocstyle comment - only this comment should be in .d.ts file*/
8291
declare var n: number;
92+
/** var deckaration with comment on type as well*/
8393
declare var y: number;
8494
declare var yy: number;
95+
/** comment2 */
8596
declare var z: (x: number, y: number) => number;
8697
declare var z2: (x: number) => string;
8798
declare var x2: (x: number) => string;

tests/baselines/reference/commentsVariableStatement1.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ var v = 1;
99

1010

1111
//// [commentsVariableStatement1.d.ts]
12+
/** Comment */
1213
declare var v: number;

tests/baselines/reference/commentsemitComments.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,10 @@ var m1;
146146

147147

148148
//// [commentsemitComments.d.ts]
149+
/** Variable comments*/
149150
declare var myVariable: number;
150151
declare function foo(p: number): void;
152+
/** variable with function type comment*/
151153
declare var fooVar: () => void;
152154
/**class comment*/
153155
declare class c {
@@ -159,6 +161,7 @@ declare class c {
159161
foo1(a: number): string;
160162
foo1(b: string): string;
161163
}
164+
/**instance comment*/
162165
declare var i: c;
163166
/** interface comments*/
164167
interface i1 {
@@ -169,6 +172,7 @@ interface i1 {
169172
/** prop*/
170173
prop: string;
171174
}
175+
/**interface instance comments*/
172176
declare var i1_i: i1;
173177
/** this is module comment*/
174178
declare module m1 {

0 commit comments

Comments
 (0)