Skip to content

Commit 2ac86d7

Browse files
authored
Merge pull request #10767 from Microsoft/fix10739_commentEnumDeclaration
Fix 10739: Only emit comment once for export enum declaration
2 parents 50d243e + 9d63c5a commit 2ac86d7

File tree

5 files changed

+57
-8
lines changed

5 files changed

+57
-8
lines changed

src/compiler/transformers/module/module.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -804,17 +804,17 @@ namespace ts {
804804
* Adds a trailing VariableStatement for an enum or module declaration.
805805
*/
806806
function addVarForExportedEnumOrNamespaceDeclaration(statements: Statement[], node: EnumDeclaration | ModuleDeclaration) {
807-
statements.push(
808-
createVariableStatement(
809-
/*modifiers*/ undefined,
810-
[createVariableDeclaration(
811-
getDeclarationName(node),
807+
const transformedStatement = createVariableStatement(
808+
/*modifiers*/ undefined,
809+
[createVariableDeclaration(
810+
getDeclarationName(node),
812811
/*type*/ undefined,
813-
createPropertyAccess(createIdentifier("exports"), getDeclarationName(node))
814-
)],
812+
createPropertyAccess(createIdentifier("exports"), getDeclarationName(node))
813+
)],
815814
/*location*/ node
816-
)
817815
);
816+
setNodeEmitFlags(transformedStatement, NodeEmitFlags.NoComments);
817+
statements.push(transformedStatement);
818818
}
819819

820820
function getDeclarationName(node: DeclarationStatement) {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//// [commentOnExportEnumDeclaration.ts]
2+
/**
3+
* comment
4+
*/
5+
export enum Color {
6+
r, g, b
7+
}
8+
9+
//// [commentOnExportEnumDeclaration.js]
10+
"use strict";
11+
/**
12+
* comment
13+
*/
14+
(function (Color) {
15+
Color[Color["r"] = 0] = "r";
16+
Color[Color["g"] = 1] = "g";
17+
Color[Color["b"] = 2] = "b";
18+
})(exports.Color || (exports.Color = {}));
19+
var Color = exports.Color;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
=== tests/cases/compiler/commentOnExportEnumDeclaration.ts ===
2+
/**
3+
* comment
4+
*/
5+
export enum Color {
6+
>Color : Symbol(Color, Decl(commentOnExportEnumDeclaration.ts, 0, 0))
7+
8+
r, g, b
9+
>r : Symbol(Color.r, Decl(commentOnExportEnumDeclaration.ts, 3, 19))
10+
>g : Symbol(Color.g, Decl(commentOnExportEnumDeclaration.ts, 4, 6))
11+
>b : Symbol(Color.b, Decl(commentOnExportEnumDeclaration.ts, 4, 9))
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
=== tests/cases/compiler/commentOnExportEnumDeclaration.ts ===
2+
/**
3+
* comment
4+
*/
5+
export enum Color {
6+
>Color : Color
7+
8+
r, g, b
9+
>r : Color
10+
>g : Color
11+
>b : Color
12+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* comment
3+
*/
4+
export enum Color {
5+
r, g, b
6+
}

0 commit comments

Comments
 (0)