From 72884b8f27abb8bfe8d8ec0f4368d09f1a4c80bf Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 6 Sep 2017 21:59:06 -0700 Subject: [PATCH] Emit comments on system export default expressions on the surrounding export call epxression instead (#17970) --- src/compiler/emitter.ts | 2 +- src/compiler/transformers/module/system.ts | 3 ++- .../systemDefaultExportCommentValidity.js | 20 +++++++++++++++++++ ...systemDefaultExportCommentValidity.symbols | 8 ++++++++ .../systemDefaultExportCommentValidity.types | 9 +++++++++ .../systemDefaultExportCommentValidity.ts | 5 +++++ 6 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 tests/baselines/reference/systemDefaultExportCommentValidity.js create mode 100644 tests/baselines/reference/systemDefaultExportCommentValidity.symbols create mode 100644 tests/baselines/reference/systemDefaultExportCommentValidity.types create mode 100644 tests/cases/compiler/systemDefaultExportCommentValidity.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 5444c61835..166e475198 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2519,7 +2519,7 @@ namespace ts { // 2 // /* end of element 2 */ // ]; - if (previousSibling && delimiter && previousSibling.end !== parentNode.end) { + if (previousSibling && delimiter && previousSibling.end !== parentNode.end && !(getEmitFlags(previousSibling) & EmitFlags.NoTrailingComments)) { emitLeadingCommentsOfPosition(previousSibling.end); } diff --git a/src/compiler/transformers/module/system.ts b/src/compiler/transformers/module/system.ts index e1c239736d..8c47ec82f7 100644 --- a/src/compiler/transformers/module/system.ts +++ b/src/compiler/transformers/module/system.ts @@ -1132,7 +1132,8 @@ namespace ts { */ function createExportExpression(name: Identifier | StringLiteral, value: Expression) { const exportName = isIdentifier(name) ? createLiteral(name) : name; - return createCall(exportFunction, /*typeArguments*/ undefined, [exportName, value]); + setEmitFlags(value, getEmitFlags(value) | EmitFlags.NoComments); + return setCommentRange(createCall(exportFunction, /*typeArguments*/ undefined, [exportName, value]), value); } // diff --git a/tests/baselines/reference/systemDefaultExportCommentValidity.js b/tests/baselines/reference/systemDefaultExportCommentValidity.js new file mode 100644 index 0000000000..a56110b0de --- /dev/null +++ b/tests/baselines/reference/systemDefaultExportCommentValidity.js @@ -0,0 +1,20 @@ +//// [systemDefaultExportCommentValidity.ts] +const Home = {} + +export default Home +// There is intentionally no semicolon on the prior line, this comment should not break emit + +//// [systemDefaultExportCommentValidity.js] +System.register([], function (exports_1, context_1) { + "use strict"; + var __moduleName = context_1 && context_1.id; + var Home; + return { + setters: [], + execute: function () { + Home = {}; + exports_1("default", Home); + // There is intentionally no semicolon on the prior line, this comment should not break emit + } + }; +}); diff --git a/tests/baselines/reference/systemDefaultExportCommentValidity.symbols b/tests/baselines/reference/systemDefaultExportCommentValidity.symbols new file mode 100644 index 0000000000..39abe3a668 --- /dev/null +++ b/tests/baselines/reference/systemDefaultExportCommentValidity.symbols @@ -0,0 +1,8 @@ +=== tests/cases/compiler/systemDefaultExportCommentValidity.ts === +const Home = {} +>Home : Symbol(Home, Decl(systemDefaultExportCommentValidity.ts, 0, 5)) + +export default Home +>Home : Symbol(Home, Decl(systemDefaultExportCommentValidity.ts, 0, 5)) + +// There is intentionally no semicolon on the prior line, this comment should not break emit diff --git a/tests/baselines/reference/systemDefaultExportCommentValidity.types b/tests/baselines/reference/systemDefaultExportCommentValidity.types new file mode 100644 index 0000000000..d8b89394ed --- /dev/null +++ b/tests/baselines/reference/systemDefaultExportCommentValidity.types @@ -0,0 +1,9 @@ +=== tests/cases/compiler/systemDefaultExportCommentValidity.ts === +const Home = {} +>Home : {} +>{} : {} + +export default Home +>Home : {} + +// There is intentionally no semicolon on the prior line, this comment should not break emit diff --git a/tests/cases/compiler/systemDefaultExportCommentValidity.ts b/tests/cases/compiler/systemDefaultExportCommentValidity.ts new file mode 100644 index 0000000000..df1d028397 --- /dev/null +++ b/tests/cases/compiler/systemDefaultExportCommentValidity.ts @@ -0,0 +1,5 @@ +// @module: system +const Home = {} + +export default Home +// There is intentionally no semicolon on the prior line, this comment should not break emit \ No newline at end of file