Emit comments on system export default expressions on the surrounding export call epxression instead (#17970)

This commit is contained in:
Wesley Wigham 2017-09-06 21:59:06 -07:00 committed by GitHub
parent ed61d2d803
commit 72884b8f27
6 changed files with 45 additions and 2 deletions

View file

@ -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);
}

View file

@ -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);
}
//

View file

@ -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
}
};
});

View file

@ -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

View file

@ -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

View file

@ -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