Skip to content

Commit 5353128

Browse files
committed
Emit pinned/tripleslash reference comments of ambient declarations
Fixes #501
1 parent 393464e commit 5353128

18 files changed

+222
-4
lines changed

src/compiler/emitter.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1989,7 +1989,14 @@ module ts {
19891989
}
19901990

19911991
function emitNode(node: Node) {
1992-
if (!node || node.flags & NodeFlags.Ambient) return;
1992+
if (!node) {
1993+
return;
1994+
}
1995+
1996+
if (node.flags & NodeFlags.Ambient) {
1997+
return emitPinnedOrTripleSlashComments(node);
1998+
}
1999+
19932000
switch (node.kind) {
19942001
case SyntaxKind.Identifier:
19952002
return emitIdentifier(<Identifier>node);
Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
1-
//// [commentOnAmbientClass1.ts]
1+
//// [tests/cases/compiler/commentOnAmbientClass1.ts] ////
2+
3+
//// [a.ts]
24
/*! Keep this pinned comment */
35
declare class C {
46
}
57

68
// Don't keep this comment.
79
declare class D {
10+
}
11+
12+
//// [b.ts]
13+
///<reference path="a.ts"/>
14+
declare class E extends C {
815
}
916

10-
//// [commentOnAmbientClass1.js]
17+
//// [a.js]
18+
/*! Keep this pinned comment */
19+
//// [b.js]
20+
///<reference path="a.ts"/>

tests/baselines/reference/commentOnAmbientClass1.types

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
=== tests/cases/compiler/commentOnAmbientClass1.ts ===
1+
=== tests/cases/compiler/b.ts ===
2+
///<reference path="a.ts"/>
3+
declare class E extends C {
4+
>E : E
5+
>C : C
6+
}
7+
=== tests/cases/compiler/a.ts ===
28
/*! Keep this pinned comment */
39
declare class C {
410
>C : C
@@ -8,3 +14,4 @@ declare class C {
814
declare class D {
915
>D : D
1016
}
17+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//// [tests/cases/compiler/commentOnAmbientEnum.ts] ////
2+
3+
//// [a.ts]
4+
/*! Keep this pinned comment */
5+
declare enum C {
6+
a,
7+
b,
8+
c
9+
}
10+
11+
// Don't keep this comment.
12+
declare enum D {
13+
}
14+
15+
//// [b.ts]
16+
///<reference path="a.ts"/>
17+
declare enum E {
18+
}
19+
20+
//// [a.js]
21+
/*! Keep this pinned comment */
22+
//// [b.js]
23+
///<reference path="a.ts"/>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
=== tests/cases/compiler/b.ts ===
2+
///<reference path="a.ts"/>
3+
declare enum E {
4+
>E : E
5+
}
6+
=== tests/cases/compiler/a.ts ===
7+
/*! Keep this pinned comment */
8+
declare enum C {
9+
>C : C
10+
11+
a,
12+
>a : C
13+
14+
b,
15+
>b : C
16+
17+
c
18+
>c : C
19+
}
20+
21+
// Don't keep this comment.
22+
declare enum D {
23+
>D : D
24+
}
25+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//// [tests/cases/compiler/commentOnAmbientModule.ts] ////
2+
3+
//// [a.ts]
4+
/*! Keep this pinned comment */
5+
declare module C {
6+
function foo();
7+
}
8+
9+
// Don't keep this comment.
10+
declare module D {
11+
class bar { }
12+
}
13+
14+
//// [b.ts]
15+
///<reference path="a.ts"/>
16+
declare module E {
17+
class foobar extends D.bar {
18+
foo();
19+
}
20+
}
21+
22+
//// [a.js]
23+
/*! Keep this pinned comment */
24+
//// [b.js]
25+
///<reference path="a.ts"/>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
=== tests/cases/compiler/b.ts ===
2+
///<reference path="a.ts"/>
3+
declare module E {
4+
>E : typeof E
5+
6+
class foobar extends D.bar {
7+
>foobar : foobar
8+
>D : D
9+
>bar : bar
10+
11+
foo();
12+
>foo : () => any
13+
}
14+
}
15+
=== tests/cases/compiler/a.ts ===
16+
/*! Keep this pinned comment */
17+
declare module C {
18+
>C : typeof C
19+
20+
function foo();
21+
>foo : () => any
22+
}
23+
24+
// Don't keep this comment.
25+
declare module D {
26+
>D : typeof D
27+
28+
class bar { }
29+
>bar : bar
30+
}
31+

tests/baselines/reference/commentOnAmbientVariable1.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ declare var v: number;
66
declare var y: number;
77

88
//// [commentOnAmbientVariable1.js]
9+
/*! Keep this pinned comment */

tests/baselines/reference/commentOnAmbientVariable2.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ x = 2;
1111
//// [commentOnAmbientVariable2_1.js]
1212
var y = 1;
1313
//// [commentOnAmbientVariable2_2.js]
14+
/// <reference path='commentOnAmbientVariable2_1.ts'/>
1415
x = 2;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//// [tests/cases/compiler/commentOnAmbientfunction.ts] ////
2+
3+
//// [a.ts]
4+
/*! Keep this pinned comment */
5+
declare function foo();
6+
7+
// Don't keep this comment.
8+
declare function bar();
9+
10+
//// [b.ts]
11+
///<reference path="a.ts"/>
12+
declare function foobar(a: typeof foo): typeof bar;
13+
14+
//// [a.js]
15+
/*! Keep this pinned comment */
16+
//// [b.js]
17+
///<reference path="a.ts"/>

0 commit comments

Comments
 (0)