Skip to content

Commit 53d79a2

Browse files
committed
Emit leading comments for '}' of the constructor block
Fixes #503
1 parent 45e76e2 commit 53d79a2

File tree

9 files changed

+47
-1
lines changed

9 files changed

+47
-1
lines changed

src/compiler/emitter.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1652,8 +1652,11 @@ module ts {
16521652
if (superCall) statements = statements.slice(1);
16531653
emitLines(statements);
16541654
}
1655-
decreaseIndent();
16561655
writeLine();
1656+
if (ctor) {
1657+
emitLeadingCommentsOfPosition((<Block>ctor.body).statements.end);
1658+
}
1659+
decreaseIndent();
16571660
emitToken(SyntaxKind.CloseBraceToken, ctor ? (<Block>ctor.body).statements.end : node.members.end);
16581661
scopeEmitEnd();
16591662
emitEnd(<Node>ctor || node);

tests/baselines/reference/callOverloads1.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Foo();
2020
//// [callOverloads1.js]
2121
var Foo = (function () {
2222
function Foo(x) {
23+
// WScript.Echo("Constructor function has executed");
2324
}
2425
Foo.prototype.bar1 = function () {
2526
};

tests/baselines/reference/callOverloads2.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Foo();
2828
//// [callOverloads2.js]
2929
var Foo = (function () {
3030
function Foo(x) {
31+
// WScript.Echo("Constructor function has executed");
3132
}
3233
Foo.prototype.bar1 = function () {
3334
};

tests/baselines/reference/callOverloads3.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Foo("s");
2121
//// [callOverloads3.js]
2222
var Foo = (function () {
2323
function Foo(x) {
24+
// WScript.Echo("Constructor function has executed");
2425
}
2526
Foo.prototype.bar1 = function () {
2627
};

tests/baselines/reference/callOverloads4.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Foo("s");
2121
//// [callOverloads4.js]
2222
var Foo = (function () {
2323
function Foo(x) {
24+
// WScript.Echo("Constructor function has executed");
2425
}
2526
Foo.prototype.bar1 = function () {
2627
};

tests/baselines/reference/callOverloads5.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Foo("s");
2222
//// [callOverloads5.js]
2323
var Foo = (function () {
2424
function Foo(x) {
25+
// WScript.Echo("Constructor function has executed");
2526
}
2627
Foo.prototype.bar1 = function (a) {
2728
};

tests/baselines/reference/commentsClass.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ class c8 {
6363
}
6464
var i8 = new c8();
6565
var i8_c = c8;
66+
67+
class c9 {
68+
constructor() {
69+
/// This is some detached comment
70+
71+
// should emit this leading comment of } too
72+
}
73+
}
6674

6775

6876
//// [commentsClass.js]
@@ -123,11 +131,20 @@ var c8 = (function () {
123131
/** constructor comment
124132
*/
125133
function c8() {
134+
/** constructor comment2
135+
*/
126136
}
127137
return c8;
128138
})();
129139
var i8 = new c8();
130140
var i8_c = c8;
141+
var c9 = (function () {
142+
function c9() {
143+
/// This is some detached comment
144+
// should emit this leading comment of } too
145+
}
146+
return c9;
147+
})();
131148

132149

133150
//// [commentsClass.d.ts]
@@ -178,3 +195,6 @@ declare class c8 {
178195
}
179196
declare var i8: c8;
180197
declare var i8_c: typeof c8;
198+
declare class c9 {
199+
constructor();
200+
}

tests/baselines/reference/commentsClass.types

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,13 @@ var i8_c = c8;
130130
>i8_c : typeof c8
131131
>c8 : typeof c8
132132

133+
class c9 {
134+
>c9 : c9
135+
136+
constructor() {
137+
/// This is some detached comment
138+
139+
// should emit this leading comment of } too
140+
}
141+
}
142+

tests/cases/compiler/commentsClass.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,11 @@ class c8 {
6565
}
6666
var i8 = new c8();
6767
var i8_c = c8;
68+
69+
class c9 {
70+
constructor() {
71+
/// This is some detached comment
72+
73+
// should emit this leading comment of } too
74+
}
75+
}

0 commit comments

Comments
 (0)