Skip to content

Commit 72884b8

Browse files
authored
Emit comments on system export default expressions on the surrounding export call epxression instead (#17970)
1 parent ed61d2d commit 72884b8

File tree

6 files changed

+45
-2
lines changed

6 files changed

+45
-2
lines changed

src/compiler/emitter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2519,7 +2519,7 @@ namespace ts {
25192519
// 2
25202520
// /* end of element 2 */
25212521
// ];
2522-
if (previousSibling && delimiter && previousSibling.end !== parentNode.end) {
2522+
if (previousSibling && delimiter && previousSibling.end !== parentNode.end && !(getEmitFlags(previousSibling) & EmitFlags.NoTrailingComments)) {
25232523
emitLeadingCommentsOfPosition(previousSibling.end);
25242524
}
25252525

src/compiler/transformers/module/system.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,8 @@ namespace ts {
11321132
*/
11331133
function createExportExpression(name: Identifier | StringLiteral, value: Expression) {
11341134
const exportName = isIdentifier(name) ? createLiteral(name) : name;
1135-
return createCall(exportFunction, /*typeArguments*/ undefined, [exportName, value]);
1135+
setEmitFlags(value, getEmitFlags(value) | EmitFlags.NoComments);
1136+
return setCommentRange(createCall(exportFunction, /*typeArguments*/ undefined, [exportName, value]), value);
11361137
}
11371138

11381139
//
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//// [systemDefaultExportCommentValidity.ts]
2+
const Home = {}
3+
4+
export default Home
5+
// There is intentionally no semicolon on the prior line, this comment should not break emit
6+
7+
//// [systemDefaultExportCommentValidity.js]
8+
System.register([], function (exports_1, context_1) {
9+
"use strict";
10+
var __moduleName = context_1 && context_1.id;
11+
var Home;
12+
return {
13+
setters: [],
14+
execute: function () {
15+
Home = {};
16+
exports_1("default", Home);
17+
// There is intentionally no semicolon on the prior line, this comment should not break emit
18+
}
19+
};
20+
});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== tests/cases/compiler/systemDefaultExportCommentValidity.ts ===
2+
const Home = {}
3+
>Home : Symbol(Home, Decl(systemDefaultExportCommentValidity.ts, 0, 5))
4+
5+
export default Home
6+
>Home : Symbol(Home, Decl(systemDefaultExportCommentValidity.ts, 0, 5))
7+
8+
// There is intentionally no semicolon on the prior line, this comment should not break emit
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
=== tests/cases/compiler/systemDefaultExportCommentValidity.ts ===
2+
const Home = {}
3+
>Home : {}
4+
>{} : {}
5+
6+
export default Home
7+
>Home : {}
8+
9+
// There is intentionally no semicolon on the prior line, this comment should not break emit
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// @module: system
2+
const Home = {}
3+
4+
export default Home
5+
// There is intentionally no semicolon on the prior line, this comment should not break emit

0 commit comments

Comments
 (0)