From 29dcc5ba41cd45b7bf74004ba6019bf69a0f80ab Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 15 Aug 2014 12:17:36 -0700 Subject: [PATCH] Start leading comments on new line if the comment starts on different line as node --- src/compiler/emitter.ts | 5 ++++ tests/baselines/reference/commentsFunction.js | 3 ++- .../reference/declFileConstructors.js | 6 +++-- .../baselines/reference/declFileFunctions.js | 9 ++++--- tests/baselines/reference/declFileMethods.js | 24 ++++++++++++------- 5 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 8456407ad3..5ae2b9a0ae 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1932,6 +1932,11 @@ module ts { function emitLeadingDeclarationComments(node: Declaration) { var leadingComments = getLeadingComments(currentSourceFile.text, node.pos); + // If the leading comments start on different line than the start of node, write new line + if (leadingComments && leadingComments.length && node.pos !== leadingComments[0].pos && + currentSourceFile.getLineAndCharacterFromPosition(node.pos).line !== currentSourceFile.getLineAndCharacterFromPosition(leadingComments[0].pos).line) { + writer.writeLine(); + } emitComments(leadingComments, writer, writeComment); } diff --git a/tests/baselines/reference/commentsFunction.js b/tests/baselines/reference/commentsFunction.js index 8f2bb57679..ccb58b4036 100644 --- a/tests/baselines/reference/commentsFunction.js +++ b/tests/baselines/reference/commentsFunction.js @@ -30,7 +30,8 @@ function foo() { } foo(); /** This is comment for function signature*/ -function fooWithParameters(a, /** this is comment for b*/ +function fooWithParameters(a, + /** this is comment for b*/ b) { var d = a; } diff --git a/tests/baselines/reference/declFileConstructors.js b/tests/baselines/reference/declFileConstructors.js index 5fba6ffdde..be28cdeb6a 100644 --- a/tests/baselines/reference/declFileConstructors.js +++ b/tests/baselines/reference/declFileConstructors.js @@ -107,7 +107,8 @@ var SimpleConstructor = (function () { exports.SimpleConstructor = SimpleConstructor; var ConstructorWithParameters = (function () { /** This is comment for function signature*/ - function ConstructorWithParameters(a, /** this is comment for b*/ + function ConstructorWithParameters(a, + /** this is comment for b*/ b) { var d = a; } @@ -169,7 +170,8 @@ var GlobalSimpleConstructor = (function () { })(); var GlobalConstructorWithParameters = (function () { /** This is comment for function signature*/ - function GlobalConstructorWithParameters(a, /** this is comment for b*/ + function GlobalConstructorWithParameters(a, + /** this is comment for b*/ b) { var d = a; } diff --git a/tests/baselines/reference/declFileFunctions.js b/tests/baselines/reference/declFileFunctions.js index 5b07da353e..fe6d55455a 100644 --- a/tests/baselines/reference/declFileFunctions.js +++ b/tests/baselines/reference/declFileFunctions.js @@ -65,7 +65,8 @@ function foo() { } exports.foo = foo; /** This is comment for function signature*/ -function fooWithParameters(a, /** this is comment for b*/ +function fooWithParameters(a, + /** this is comment for b*/ b) { var d = a; } @@ -86,7 +87,8 @@ exports.fooWithOverloads = fooWithOverloads; function nonExportedFoo() { } /** This is comment for function signature*/ -function nonExportedFooWithParameters(a, /** this is comment for b*/ +function nonExportedFooWithParameters(a, + /** this is comment for b*/ b) { var d = a; } @@ -105,7 +107,8 @@ function nonExportedFooWithOverloads(a) { function globalfoo() { } /** This is comment for function signature*/ -function globalfooWithParameters(a, /** this is comment for b*/ +function globalfooWithParameters(a, + /** this is comment for b*/ b) { var d = a; } diff --git a/tests/baselines/reference/declFileMethods.js b/tests/baselines/reference/declFileMethods.js index f654402fb5..82fa6d1474 100644 --- a/tests/baselines/reference/declFileMethods.js +++ b/tests/baselines/reference/declFileMethods.js @@ -198,7 +198,8 @@ var c1 = (function () { c1.prototype.foo = function () { }; /** This is comment for function signature*/ - c1.prototype.fooWithParameters = function (a, /** this is comment for b*/ + c1.prototype.fooWithParameters = function (a, + /** this is comment for b*/ b) { var d = a; }; @@ -216,7 +217,8 @@ var c1 = (function () { c1.prototype.privateFoo = function () { }; /** This is comment for function signature*/ - c1.prototype.privateFooWithParameters = function (a, /** this is comment for b*/ + c1.prototype.privateFooWithParameters = function (a, + /** this is comment for b*/ b) { var d = a; }; @@ -234,7 +236,8 @@ var c1 = (function () { c1.staticFoo = function () { }; /** This is comment for function signature*/ - c1.staticFooWithParameters = function (a, /** this is comment for b*/ + c1.staticFooWithParameters = function (a, + /** this is comment for b*/ b) { var d = a; }; @@ -252,7 +255,8 @@ var c1 = (function () { c1.privateStaticFoo = function () { }; /** This is comment for function signature*/ - c1.privateStaticFooWithParameters = function (a, /** this is comment for b*/ + c1.privateStaticFooWithParameters = function (a, + /** this is comment for b*/ b) { var d = a; }; @@ -277,7 +281,8 @@ var c2 = (function () { c2.prototype.foo = function () { }; /** This is comment for function signature*/ - c2.prototype.fooWithParameters = function (a, /** this is comment for b*/ + c2.prototype.fooWithParameters = function (a, + /** this is comment for b*/ b) { var d = a; }; @@ -295,7 +300,8 @@ var c2 = (function () { c2.prototype.privateFoo = function () { }; /** This is comment for function signature*/ - c2.prototype.privateFooWithParameters = function (a, /** this is comment for b*/ + c2.prototype.privateFooWithParameters = function (a, + /** this is comment for b*/ b) { var d = a; }; @@ -313,7 +319,8 @@ var c2 = (function () { c2.staticFoo = function () { }; /** This is comment for function signature*/ - c2.staticFooWithParameters = function (a, /** this is comment for b*/ + c2.staticFooWithParameters = function (a, + /** this is comment for b*/ b) { var d = a; }; @@ -331,7 +338,8 @@ var c2 = (function () { c2.privateStaticFoo = function () { }; /** This is comment for function signature*/ - c2.privateStaticFooWithParameters = function (a, /** this is comment for b*/ + c2.privateStaticFooWithParameters = function (a, + /** this is comment for b*/ b) { var d = a; };