Skip to content

Commit c71e6cc

Browse files
authored
add a new line if after writing trailing comments (#12894)
1 parent e5e1533 commit c71e6cc

File tree

6 files changed

+49
-12
lines changed

6 files changed

+49
-12
lines changed

src/compiler/comments.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ namespace ts {
156156

157157
if (!skipTrailingComments) {
158158
emitLeadingComments(detachedRange.end, /*isEmittedNode*/ true);
159+
if (hasWrittenComment && !writer.isAtStartOfLine()) {
160+
writer.writeLine();
161+
}
159162
}
160163

161164
if (extendedDiagnostics) {

src/compiler/transformers/module/system.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,20 +101,21 @@ namespace ts {
101101
// So the helper will be emit at the correct position instead of at the top of the source-file
102102
const moduleName = tryGetModuleNameFromFile(node, host, compilerOptions);
103103
const dependencies = createArrayLiteral(map(dependencyGroups, dependencyGroup => dependencyGroup.name));
104-
const updated = updateSourceFileNode(
105-
node,
106-
createNodeArray([
107-
createStatement(
108-
createCall(
109-
createPropertyAccess(createIdentifier("System"), "register"),
104+
const updated = setEmitFlags(
105+
updateSourceFileNode(
106+
node,
107+
createNodeArray([
108+
createStatement(
109+
createCall(
110+
createPropertyAccess(createIdentifier("System"), "register"),
110111
/*typeArguments*/ undefined,
111-
moduleName
112-
? [moduleName, dependencies, moduleBodyFunction]
113-
: [dependencies, moduleBodyFunction]
112+
moduleName
113+
? [moduleName, dependencies, moduleBodyFunction]
114+
: [dependencies, moduleBodyFunction]
115+
)
114116
)
115-
)
116-
], node.statements)
117-
);
117+
], node.statements)
118+
), EmitFlags.NoTrailingComments);
118119

119120
if (!(compilerOptions.outFile || compilerOptions.out)) {
120121
moveEmitHelpers(updated, moduleBodyBlock, helper => !helper.scoped);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//// [systemModuleTrailingComments.ts]
2+
export const test = "TEST";
3+
4+
//some comment
5+
6+
//// [systemModuleTrailingComments.js]
7+
System.register([], function (exports_1, context_1) {
8+
"use strict";
9+
var __moduleName = context_1 && context_1.id;
10+
var test;
11+
return {
12+
setters: [],
13+
execute: function () {
14+
exports_1("test", test = "TEST");
15+
//some comment
16+
}
17+
};
18+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
=== tests/cases/compiler/systemModuleTrailingComments.ts ===
2+
export const test = "TEST";
3+
>test : Symbol(test, Decl(systemModuleTrailingComments.ts, 0, 12))
4+
5+
//some comment
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
=== tests/cases/compiler/systemModuleTrailingComments.ts ===
2+
export const test = "TEST";
3+
>test : "TEST"
4+
>"TEST" : "TEST"
5+
6+
//some comment
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// @module: system
2+
export const test = "TEST";
3+
4+
//some comment

0 commit comments

Comments
 (0)