From 0407f29d5a5e878815148f6a97a4ee0a1565639f Mon Sep 17 00:00:00 2001 From: Martin Vseticka Date: Tue, 29 Sep 2015 23:59:05 +0200 Subject: [PATCH] Trim trailing whitespace --- .gitignore | 1 + src/compiler/emitter.ts | 11 +++++++++-- .../commentsArgumentsOfCallExpression2.js | 2 +- tests/baselines/reference/commentsFunction.js | 2 +- .../baselines/reference/declFileConstructors.js | 4 ++-- tests/baselines/reference/declFileFunctions.js | 6 +++--- tests/baselines/reference/declFileMethods.js | 16 ++++++++-------- 7 files changed, 25 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index 8d05f8f3337b1..417b7f003009b 100644 --- a/.gitignore +++ b/.gitignore @@ -53,3 +53,4 @@ internal/ .settings .vscode/* !.vscode/tasks.json +.idea/* diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index efc45273b474e..5ab1012028225 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -833,6 +833,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } for (let i = 0; i < count; i++) { + let node = nodes[start + i]; + if (multiLine) { if (i || leadingComma) { write(","); @@ -841,10 +843,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } else { if (i || leadingComma) { - write(", "); + write(","); + + let comments = getLeadingCommentsToEmit(node); + + if (!comments || !comments[0].hasTrailingNewLine) { + write(" "); + } } } - let node = nodes[start + i]; // This emitting is to make sure we emit following comment properly // ...(x, /*comment1*/ y)... // ^ => node.pos diff --git a/tests/baselines/reference/commentsArgumentsOfCallExpression2.js b/tests/baselines/reference/commentsArgumentsOfCallExpression2.js index a7065410ff4fe..02d35bbc02537 100644 --- a/tests/baselines/reference/commentsArgumentsOfCallExpression2.js +++ b/tests/baselines/reference/commentsArgumentsOfCallExpression2.js @@ -18,6 +18,6 @@ foo(/*c3*/ function () { }, /*d2*/ function () { }, /*e2*/ a + b); foo(/*c3*/ function () { }, /*d3*/ function () { }, /*e3*/ (a + b)); foo( /*c4*/ function () { }, -/*d4*/ function () { }, +/*d4*/ function () { }, /*e4*/ /*e5*/ "hello"); diff --git a/tests/baselines/reference/commentsFunction.js b/tests/baselines/reference/commentsFunction.js index 0ffb271410879..a4231aa379c98 100644 --- a/tests/baselines/reference/commentsFunction.js +++ b/tests/baselines/reference/commentsFunction.js @@ -61,7 +61,7 @@ function foo() { } /* trailing comment of function */ foo(); /** This is comment for function signature*/ -function fooWithParameters(/** this is comment about a*/ a, +function fooWithParameters(/** this is comment about a*/ 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 327221debf805..be9b242689ee1 100644 --- a/tests/baselines/reference/declFileConstructors.js +++ b/tests/baselines/reference/declFileConstructors.js @@ -107,7 +107,7 @@ var SimpleConstructor = (function () { exports.SimpleConstructor = SimpleConstructor; var ConstructorWithParameters = (function () { /** This is comment for function signature*/ - function ConstructorWithParameters(/** this is comment about a*/ a, + function ConstructorWithParameters(/** this is comment about a*/ a, /** this is comment for b*/ b) { var d = a; @@ -170,7 +170,7 @@ var GlobalSimpleConstructor = (function () { })(); var GlobalConstructorWithParameters = (function () { /** This is comment for function signature*/ - function GlobalConstructorWithParameters(/** this is comment about a*/ a, + function GlobalConstructorWithParameters(/** this is comment about a*/ 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 163fa1905c8e7..c11db56fe95bd 100644 --- a/tests/baselines/reference/declFileFunctions.js +++ b/tests/baselines/reference/declFileFunctions.js @@ -83,7 +83,7 @@ function foo() { } exports.foo = foo; /** This is comment for function signature*/ -function fooWithParameters(/** this is comment about a*/ a, +function fooWithParameters(/** this is comment about a*/ a, /** this is comment for b*/ b) { var d = a; @@ -129,7 +129,7 @@ exports.fooWithTypeTypePredicateAndRestParam = fooWithTypeTypePredicateAndRestPa function nonExportedFoo() { } /** This is comment for function signature*/ -function nonExportedFooWithParameters(/** this is comment about a*/ a, +function nonExportedFooWithParameters(/** this is comment about a*/ a, /** this is comment for b*/ b) { var d = a; @@ -149,7 +149,7 @@ function nonExportedFooWithOverloads(a) { function globalfoo() { } /** This is comment for function signature*/ -function globalfooWithParameters(/** this is comment about a*/ a, +function globalfooWithParameters(/** this is comment about a*/ 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 2b82a4b71b525..dc9f1e70511f9 100644 --- a/tests/baselines/reference/declFileMethods.js +++ b/tests/baselines/reference/declFileMethods.js @@ -198,7 +198,7 @@ var c1 = (function () { c1.prototype.foo = function () { }; /** This is comment for function signature*/ - c1.prototype.fooWithParameters = function (/** this is comment about a*/ a, + c1.prototype.fooWithParameters = function (/** this is comment about a*/ a, /** this is comment for b*/ b) { var d = a; @@ -217,7 +217,7 @@ var c1 = (function () { c1.prototype.privateFoo = function () { }; /** This is comment for function signature*/ - c1.prototype.privateFooWithParameters = function (/** this is comment about a*/ a, + c1.prototype.privateFooWithParameters = function (/** this is comment about a*/ a, /** this is comment for b*/ b) { var d = a; @@ -236,7 +236,7 @@ var c1 = (function () { c1.staticFoo = function () { }; /** This is comment for function signature*/ - c1.staticFooWithParameters = function (/** this is comment about a*/ a, + c1.staticFooWithParameters = function (/** this is comment about a*/ a, /** this is comment for b*/ b) { var d = a; @@ -255,7 +255,7 @@ var c1 = (function () { c1.privateStaticFoo = function () { }; /** This is comment for function signature*/ - c1.privateStaticFooWithParameters = function (/** this is comment about a*/ a, + c1.privateStaticFooWithParameters = function (/** this is comment about a*/ a, /** this is comment for b*/ b) { var d = a; @@ -281,7 +281,7 @@ var c2 = (function () { c2.prototype.foo = function () { }; /** This is comment for function signature*/ - c2.prototype.fooWithParameters = function (/** this is comment about a*/ a, + c2.prototype.fooWithParameters = function (/** this is comment about a*/ a, /** this is comment for b*/ b) { var d = a; @@ -300,7 +300,7 @@ var c2 = (function () { c2.prototype.privateFoo = function () { }; /** This is comment for function signature*/ - c2.prototype.privateFooWithParameters = function (/** this is comment about a*/ a, + c2.prototype.privateFooWithParameters = function (/** this is comment about a*/ a, /** this is comment for b*/ b) { var d = a; @@ -319,7 +319,7 @@ var c2 = (function () { c2.staticFoo = function () { }; /** This is comment for function signature*/ - c2.staticFooWithParameters = function (/** this is comment about a*/ a, + c2.staticFooWithParameters = function (/** this is comment about a*/ a, /** this is comment for b*/ b) { var d = a; @@ -338,7 +338,7 @@ var c2 = (function () { c2.privateStaticFoo = function () { }; /** This is comment for function signature*/ - c2.privateStaticFooWithParameters = function (/** this is comment about a*/ a, + c2.privateStaticFooWithParameters = function (/** this is comment about a*/ a, /** this is comment for b*/ b) { var d = a;