From 9d63c5a35eb3bab10ea1545cfc293facac6049c9 Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Wed, 7 Sep 2016 18:02:45 -0700 Subject: [PATCH] Only emit comment once for export enum declaration --- src/compiler/transformers/module/module.ts | 16 ++++++++-------- .../commentOnExportEnumDeclaration.js | 19 +++++++++++++++++++ .../commentOnExportEnumDeclaration.symbols | 12 ++++++++++++ .../commentOnExportEnumDeclaration.types | 12 ++++++++++++ .../commentOnExportEnumDeclaration.ts | 6 ++++++ 5 files changed, 57 insertions(+), 8 deletions(-) create mode 100644 tests/baselines/reference/commentOnExportEnumDeclaration.js create mode 100644 tests/baselines/reference/commentOnExportEnumDeclaration.symbols create mode 100644 tests/baselines/reference/commentOnExportEnumDeclaration.types create mode 100644 tests/cases/compiler/commentOnExportEnumDeclaration.ts diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index 144420b7ae9..17a5a9f0d89 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -802,17 +802,17 @@ namespace ts { * Adds a trailing VariableStatement for an enum or module declaration. */ function addVarForExportedEnumOrNamespaceDeclaration(statements: Statement[], node: EnumDeclaration | ModuleDeclaration) { - statements.push( - createVariableStatement( - /*modifiers*/ undefined, - [createVariableDeclaration( - getDeclarationName(node), + const transformedStatement = createVariableStatement( + /*modifiers*/ undefined, + [createVariableDeclaration( + getDeclarationName(node), /*type*/ undefined, - createPropertyAccess(createIdentifier("exports"), getDeclarationName(node)) - )], + createPropertyAccess(createIdentifier("exports"), getDeclarationName(node)) + )], /*location*/ node - ) ); + setNodeEmitFlags(transformedStatement, NodeEmitFlags.NoComments); + statements.push(transformedStatement); } function getDeclarationName(node: DeclarationStatement) { diff --git a/tests/baselines/reference/commentOnExportEnumDeclaration.js b/tests/baselines/reference/commentOnExportEnumDeclaration.js new file mode 100644 index 00000000000..6ded51456d8 --- /dev/null +++ b/tests/baselines/reference/commentOnExportEnumDeclaration.js @@ -0,0 +1,19 @@ +//// [commentOnExportEnumDeclaration.ts] +/** + * comment + */ +export enum Color { + r, g, b +} + +//// [commentOnExportEnumDeclaration.js] +"use strict"; +/** + * comment + */ +(function (Color) { + Color[Color["r"] = 0] = "r"; + Color[Color["g"] = 1] = "g"; + Color[Color["b"] = 2] = "b"; +})(exports.Color || (exports.Color = {})); +var Color = exports.Color; diff --git a/tests/baselines/reference/commentOnExportEnumDeclaration.symbols b/tests/baselines/reference/commentOnExportEnumDeclaration.symbols new file mode 100644 index 00000000000..76cb7173703 --- /dev/null +++ b/tests/baselines/reference/commentOnExportEnumDeclaration.symbols @@ -0,0 +1,12 @@ +=== tests/cases/compiler/commentOnExportEnumDeclaration.ts === +/** + * comment + */ +export enum Color { +>Color : Symbol(Color, Decl(commentOnExportEnumDeclaration.ts, 0, 0)) + + r, g, b +>r : Symbol(Color.r, Decl(commentOnExportEnumDeclaration.ts, 3, 19)) +>g : Symbol(Color.g, Decl(commentOnExportEnumDeclaration.ts, 4, 6)) +>b : Symbol(Color.b, Decl(commentOnExportEnumDeclaration.ts, 4, 9)) +} diff --git a/tests/baselines/reference/commentOnExportEnumDeclaration.types b/tests/baselines/reference/commentOnExportEnumDeclaration.types new file mode 100644 index 00000000000..522e1175540 --- /dev/null +++ b/tests/baselines/reference/commentOnExportEnumDeclaration.types @@ -0,0 +1,12 @@ +=== tests/cases/compiler/commentOnExportEnumDeclaration.ts === +/** + * comment + */ +export enum Color { +>Color : Color + + r, g, b +>r : Color +>g : Color +>b : Color +} diff --git a/tests/cases/compiler/commentOnExportEnumDeclaration.ts b/tests/cases/compiler/commentOnExportEnumDeclaration.ts new file mode 100644 index 00000000000..d9a120492ff --- /dev/null +++ b/tests/cases/compiler/commentOnExportEnumDeclaration.ts @@ -0,0 +1,6 @@ +/** + * comment + */ +export enum Color { + r, g, b +} \ No newline at end of file