diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 757cddda42..198adc4c37 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1652,8 +1652,11 @@ module ts { if (superCall) statements = statements.slice(1); emitLines(statements); } - decreaseIndent(); writeLine(); + if (ctor) { + emitLeadingCommentsOfPosition((ctor.body).statements.end); + } + decreaseIndent(); emitToken(SyntaxKind.CloseBraceToken, ctor ? (ctor.body).statements.end : node.members.end); scopeEmitEnd(); emitEnd(ctor || node); diff --git a/tests/baselines/reference/callOverloads1.js b/tests/baselines/reference/callOverloads1.js index 4d595108ab..dc76fcba98 100644 --- a/tests/baselines/reference/callOverloads1.js +++ b/tests/baselines/reference/callOverloads1.js @@ -20,6 +20,7 @@ Foo(); //// [callOverloads1.js] var Foo = (function () { function Foo(x) { + // WScript.Echo("Constructor function has executed"); } Foo.prototype.bar1 = function () { }; diff --git a/tests/baselines/reference/callOverloads2.js b/tests/baselines/reference/callOverloads2.js index f152bde71a..be42753bc3 100644 --- a/tests/baselines/reference/callOverloads2.js +++ b/tests/baselines/reference/callOverloads2.js @@ -28,6 +28,7 @@ Foo(); //// [callOverloads2.js] var Foo = (function () { function Foo(x) { + // WScript.Echo("Constructor function has executed"); } Foo.prototype.bar1 = function () { }; diff --git a/tests/baselines/reference/callOverloads3.js b/tests/baselines/reference/callOverloads3.js index 0791be6530..93176cc1ed 100644 --- a/tests/baselines/reference/callOverloads3.js +++ b/tests/baselines/reference/callOverloads3.js @@ -21,6 +21,7 @@ Foo("s"); //// [callOverloads3.js] var Foo = (function () { function Foo(x) { + // WScript.Echo("Constructor function has executed"); } Foo.prototype.bar1 = function () { }; diff --git a/tests/baselines/reference/callOverloads4.js b/tests/baselines/reference/callOverloads4.js index 19bed1db43..86ec2b91e7 100644 --- a/tests/baselines/reference/callOverloads4.js +++ b/tests/baselines/reference/callOverloads4.js @@ -21,6 +21,7 @@ Foo("s"); //// [callOverloads4.js] var Foo = (function () { function Foo(x) { + // WScript.Echo("Constructor function has executed"); } Foo.prototype.bar1 = function () { }; diff --git a/tests/baselines/reference/callOverloads5.js b/tests/baselines/reference/callOverloads5.js index 4b93fee7a4..30cc65915e 100644 --- a/tests/baselines/reference/callOverloads5.js +++ b/tests/baselines/reference/callOverloads5.js @@ -22,6 +22,7 @@ Foo("s"); //// [callOverloads5.js] var Foo = (function () { function Foo(x) { + // WScript.Echo("Constructor function has executed"); } Foo.prototype.bar1 = function (a) { }; diff --git a/tests/baselines/reference/commentsClass.js b/tests/baselines/reference/commentsClass.js index f7f6025dc1..b42235e9af 100644 --- a/tests/baselines/reference/commentsClass.js +++ b/tests/baselines/reference/commentsClass.js @@ -63,6 +63,14 @@ class c8 { } var i8 = new c8(); var i8_c = c8; + +class c9 { + constructor() { + /// This is some detached comment + + // should emit this leading comment of } too + } +} //// [commentsClass.js] @@ -123,11 +131,20 @@ var c8 = (function () { /** constructor comment */ function c8() { + /** constructor comment2 + */ } return c8; })(); var i8 = new c8(); var i8_c = c8; +var c9 = (function () { + function c9() { + /// This is some detached comment + // should emit this leading comment of } too + } + return c9; +})(); //// [commentsClass.d.ts] @@ -178,3 +195,6 @@ declare class c8 { } declare var i8: c8; declare var i8_c: typeof c8; +declare class c9 { + constructor(); +} diff --git a/tests/baselines/reference/commentsClass.types b/tests/baselines/reference/commentsClass.types index 5719059adf..a4aca2ba15 100644 --- a/tests/baselines/reference/commentsClass.types +++ b/tests/baselines/reference/commentsClass.types @@ -130,3 +130,13 @@ var i8_c = c8; >i8_c : typeof c8 >c8 : typeof c8 +class c9 { +>c9 : c9 + + constructor() { + /// This is some detached comment + + // should emit this leading comment of } too + } +} + diff --git a/tests/cases/compiler/commentsClass.ts b/tests/cases/compiler/commentsClass.ts index 6bc5103ad4..e9a8f3cee1 100644 --- a/tests/cases/compiler/commentsClass.ts +++ b/tests/cases/compiler/commentsClass.ts @@ -65,3 +65,11 @@ class c8 { } var i8 = new c8(); var i8_c = c8; + +class c9 { + constructor() { + /// This is some detached comment + + // should emit this leading comment of } too + } +}