Skip to content

Commit 6ab3adf

Browse files
committed
Modified the emitComment logic to handle emitting leading or trailing spaces depending on flags
Leading comments have trailing separator while trailing comments have leading space This removes the extra trailing space in the trailing comments
1 parent 45e8ff8 commit 6ab3adf

File tree

143 files changed

+171
-163
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

143 files changed

+171
-163
lines changed

src/compiler/emitter.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,23 @@ module ts {
167167
});
168168
}
169169

170-
function emitComments(comments: Comment[], writer: EmitTextWriter, writeComment: (comment: Comment, writer: EmitTextWriter) => void) {
170+
function emitComments(comments: Comment[], trailingSeparator: boolean, writer: EmitTextWriter, writeComment: (comment: Comment, writer: EmitTextWriter) => void) {
171+
var emitLeadingSpace = !trailingSeparator;
171172
forEach(comments, comment => {
173+
if (emitLeadingSpace) {
174+
writer.write(" ");
175+
emitLeadingSpace = false;
176+
}
172177
writeComment(comment, writer);
173178
if (comment.hasTrailingNewLine) {
174179
writer.writeLine();
175-
} else {
180+
} else if (trailingSeparator) {
176181
writer.write(" ");
177182
}
183+
else {
184+
// Emit leading space to separate comment during next comment emit
185+
emitLeadingSpace = true;
186+
}
178187
});
179188
}
180189

@@ -1941,18 +1950,16 @@ module ts {
19411950
function emitLeadingDeclarationComments(node: Declaration) {
19421951
var leadingComments = getLeadingComments(currentSourceFile.text, node.pos);
19431952
emitNewLineBeforeLeadingComments(node, leadingComments, writer);
1944-
emitComments(leadingComments, writer, writeComment);
1953+
// Leading comments are emitted at /*leading comment1 */space/*leading comment*/space
1954+
emitComments(leadingComments, /*trailingSeparator*/ true, writer, writeComment);
19451955
}
19461956

19471957
function emitTrailingDeclarationComments(node: Declaration) {
19481958
// Emit the trailing declaration comments only if the parent's end doesnt match
19491959
if (node.parent.kind === SyntaxKind.SourceFile || node.end !== node.parent.end) {
19501960
var trailingComments = getTrailingComments(currentSourceFile.text, node.end);
1951-
if (trailingComments && trailingComments.length) {
1952-
// Trailing comments are emitting on same line, so write a space between comment
1953-
writer.write(" ");
1954-
}
1955-
emitComments(trailingComments, writer, writeComment);
1961+
// trailing comments are emitted at space/*trailing comment1 */space/*trailing comment*/
1962+
emitComments(trailingComments, /*trailingSeparator*/ false, writer, writeComment);
19561963
}
19571964
}
19581965

@@ -2068,7 +2075,8 @@ module ts {
20682075
if (declaration) {
20692076
var jsDocComments = getJsDocComments(declaration, currentSourceFile);
20702077
emitNewLineBeforeLeadingComments(declaration, jsDocComments, writer);
2071-
emitComments(jsDocComments, writer, writeCommentRange);
2078+
// jsDoc comments are emitted at /*leading comment1 */space/*leading comment*/space
2079+
emitComments(jsDocComments, /*trailingSeparator*/ true, writer, writeCommentRange);
20722080
}
20732081
}
20742082

tests/baselines/reference/AmbientModuleAndNonAmbientClassWithSameNameAndCommonRoot.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ var A;
3737
//// [test.js]
3838
var p;
3939
var p = A.Point.Origin;
40-
var p = new A.Point(0, 0); // unexpected error here, bug 840000
40+
var p = new A.Point(0, 0); // unexpected error here, bug 840000

tests/baselines/reference/ambiguousOverloadResolution.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ var B = (function (_super) {
2828
return B;
2929
})(A);
3030
var x;
31-
var t = f(x, x); // Not an error
31+
var t = f(x, x); // Not an error

tests/baselines/reference/anyAsConstructor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ var a = new x();
1818
var b = new x('hello');
1919
var c = new x(x);
2020
// grammar allows this for constructors
21-
var d = new x(x); // no error
21+
var d = new x(x); // no error

tests/baselines/reference/anyAssignabilityInInheritance.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,4 @@ var CC;
135135
})(CC || (CC = {}));
136136
var r3 = foo3(a); // any
137137
var r3 = foo3(a); // any
138-
var r3 = foo3(a); // any
138+
var r3 = foo3(a); // any

tests/baselines/reference/arrayLiteralsWithRecursiveGenerics.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@ var xs = [list, myList]; // {}[]
5656
var ys = [list, list2]; // {}[]
5757
var zs = [list, null]; // List<number>[]
5858
var myDerivedList;
59-
var as = [list, myDerivedList]; // List<number>[]
59+
var as = [list, myDerivedList]; // List<number>[]

tests/baselines/reference/arrayOfFunctionTypes3.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@ var b2;
5050
var c2;
5151
var z2 = [a2, b2, c2];
5252
var r6 = z2[0];
53-
var r7 = r6(''); // any not string
53+
var r7 = r6(''); // any not string

tests/baselines/reference/arrayTypeOfFunctionTypes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ var r4b = new r3(); // error
2929
var x3;
3030
var r5 = x2[1];
3131
var r6 = r5();
32-
var r6b = new r5(); // error
32+
var r6b = new r5(); // error

tests/baselines/reference/assignmentToObjectAndFunction.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,4 @@ var bad;
5959
(function (bad) {
6060
bad.apply = 0;
6161
})(bad || (bad = {}));
62-
var badFundule = bad; // error
62+
var badFundule = bad; // error

tests/baselines/reference/augmentedTypeAssignmentCompatIndexSignature.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ var o = {};
2626
var f = function () {
2727
};
2828
var v1 = o; // Should be allowed
29-
var v2 = f; // Should be allowed
29+
var v2 = f; // Should be allowed

0 commit comments

Comments
 (0)