From c71e6cc9ef9f9b8ae0f2036336b0489cdc61318b Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Tue, 13 Dec 2016 12:57:21 -0800 Subject: [PATCH] add a new line if after writing trailing comments (#12894) --- src/compiler/comments.ts | 3 +++ src/compiler/transformers/module/system.ts | 25 ++++++++++--------- .../reference/systemModuleTrailingComments.js | 18 +++++++++++++ .../systemModuleTrailingComments.symbols | 5 ++++ .../systemModuleTrailingComments.types | 6 +++++ .../compiler/systemModuleTrailingComments.ts | 4 +++ 6 files changed, 49 insertions(+), 12 deletions(-) create mode 100644 tests/baselines/reference/systemModuleTrailingComments.js create mode 100644 tests/baselines/reference/systemModuleTrailingComments.symbols create mode 100644 tests/baselines/reference/systemModuleTrailingComments.types create mode 100644 tests/cases/compiler/systemModuleTrailingComments.ts diff --git a/src/compiler/comments.ts b/src/compiler/comments.ts index cd96981c093..bd9190dbec7 100644 --- a/src/compiler/comments.ts +++ b/src/compiler/comments.ts @@ -156,6 +156,9 @@ namespace ts { if (!skipTrailingComments) { emitLeadingComments(detachedRange.end, /*isEmittedNode*/ true); + if (hasWrittenComment && !writer.isAtStartOfLine()) { + writer.writeLine(); + } } if (extendedDiagnostics) { diff --git a/src/compiler/transformers/module/system.ts b/src/compiler/transformers/module/system.ts index 91e29e09886..0e3a42da0d2 100644 --- a/src/compiler/transformers/module/system.ts +++ b/src/compiler/transformers/module/system.ts @@ -101,20 +101,21 @@ namespace ts { // So the helper will be emit at the correct position instead of at the top of the source-file const moduleName = tryGetModuleNameFromFile(node, host, compilerOptions); const dependencies = createArrayLiteral(map(dependencyGroups, dependencyGroup => dependencyGroup.name)); - const updated = updateSourceFileNode( - node, - createNodeArray([ - createStatement( - createCall( - createPropertyAccess(createIdentifier("System"), "register"), + const updated = setEmitFlags( + updateSourceFileNode( + node, + createNodeArray([ + createStatement( + createCall( + createPropertyAccess(createIdentifier("System"), "register"), /*typeArguments*/ undefined, - moduleName - ? [moduleName, dependencies, moduleBodyFunction] - : [dependencies, moduleBodyFunction] + moduleName + ? [moduleName, dependencies, moduleBodyFunction] + : [dependencies, moduleBodyFunction] + ) ) - ) - ], node.statements) - ); + ], node.statements) + ), EmitFlags.NoTrailingComments); if (!(compilerOptions.outFile || compilerOptions.out)) { moveEmitHelpers(updated, moduleBodyBlock, helper => !helper.scoped); diff --git a/tests/baselines/reference/systemModuleTrailingComments.js b/tests/baselines/reference/systemModuleTrailingComments.js new file mode 100644 index 00000000000..41b0bd299a0 --- /dev/null +++ b/tests/baselines/reference/systemModuleTrailingComments.js @@ -0,0 +1,18 @@ +//// [systemModuleTrailingComments.ts] +export const test = "TEST"; + +//some comment + +//// [systemModuleTrailingComments.js] +System.register([], function (exports_1, context_1) { + "use strict"; + var __moduleName = context_1 && context_1.id; + var test; + return { + setters: [], + execute: function () { + exports_1("test", test = "TEST"); + //some comment + } + }; +}); diff --git a/tests/baselines/reference/systemModuleTrailingComments.symbols b/tests/baselines/reference/systemModuleTrailingComments.symbols new file mode 100644 index 00000000000..4df59b45faa --- /dev/null +++ b/tests/baselines/reference/systemModuleTrailingComments.symbols @@ -0,0 +1,5 @@ +=== tests/cases/compiler/systemModuleTrailingComments.ts === +export const test = "TEST"; +>test : Symbol(test, Decl(systemModuleTrailingComments.ts, 0, 12)) + +//some comment diff --git a/tests/baselines/reference/systemModuleTrailingComments.types b/tests/baselines/reference/systemModuleTrailingComments.types new file mode 100644 index 00000000000..235b46e6e8f --- /dev/null +++ b/tests/baselines/reference/systemModuleTrailingComments.types @@ -0,0 +1,6 @@ +=== tests/cases/compiler/systemModuleTrailingComments.ts === +export const test = "TEST"; +>test : "TEST" +>"TEST" : "TEST" + +//some comment diff --git a/tests/cases/compiler/systemModuleTrailingComments.ts b/tests/cases/compiler/systemModuleTrailingComments.ts new file mode 100644 index 00000000000..32c29617832 --- /dev/null +++ b/tests/cases/compiler/systemModuleTrailingComments.ts @@ -0,0 +1,4 @@ +// @module: system +export const test = "TEST"; + +//some comment \ No newline at end of file