From 9d2f0b37c0b67741398b0f812a720bbc1cdf1343 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Thu, 7 Apr 2016 12:27:44 -0700 Subject: [PATCH 1/2] Emits class name with comments. --- src/compiler/transformers/es6.ts | 2 +- .../variableDeclaratorResolvedDuringContextualTyping.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/compiler/transformers/es6.ts b/src/compiler/transformers/es6.ts index d8bbdd4c326..7c4081c54bf 100644 --- a/src/compiler/transformers/es6.ts +++ b/src/compiler/transformers/es6.ts @@ -549,7 +549,7 @@ namespace ts { /*modifiers*/ undefined, createVariableDeclarationList([ createVariableDeclaration( - getDeclarationName(node), + node.name || getGeneratedNameForNode(node), transformClassLikeDeclarationToExpression(node) ) ]), diff --git a/tests/baselines/reference/variableDeclaratorResolvedDuringContextualTyping.js b/tests/baselines/reference/variableDeclaratorResolvedDuringContextualTyping.js index 692c4e3aebe..ed6111ec3c5 100644 --- a/tests/baselines/reference/variableDeclaratorResolvedDuringContextualTyping.js +++ b/tests/baselines/reference/variableDeclaratorResolvedDuringContextualTyping.js @@ -132,11 +132,11 @@ var WinJS; var Errors; (function (Errors) { var ConnectionError /* extends Error */ = (function () { - function ConnectionError /* extends Error */(request) { + function ConnectionError(request) { } - return ConnectionError /* extends Error */; + return ConnectionError; }()); - Errors.ConnectionError /* extends Error */ = ConnectionError /* extends Error */; + Errors.ConnectionError = ConnectionError; })(Errors || (Errors = {})); var FileService = (function () { function FileService() { From cbc2452409630a9b23152513f7478f16bb35567f Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Thu, 7 Apr 2016 14:25:24 -0700 Subject: [PATCH 2/2] Changed getDeclarationName to allow comments if requested --- src/compiler/transformers/es6.ts | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/compiler/transformers/es6.ts b/src/compiler/transformers/es6.ts index 7c4081c54bf..60dce220593 100644 --- a/src/compiler/transformers/es6.ts +++ b/src/compiler/transformers/es6.ts @@ -549,7 +549,7 @@ namespace ts { /*modifiers*/ undefined, createVariableDeclarationList([ createVariableDeclaration( - node.name || getGeneratedNameForNode(node), + getDeclarationName(node, /*allowComments*/ true), transformClassLikeDeclarationToExpression(node) ) ]), @@ -2688,8 +2688,25 @@ namespace ts { return node; } - function getDeclarationName(node: ClassExpression | ClassDeclaration | FunctionDeclaration) { - return node.name ? getSynthesizedClone(node.name) : getGeneratedNameForNode(node); + /** + * Gets the name of a declaration, without source map or comments. + * + * @param node The declaration. + * @param allowComments Allow comments for the name. + */ + function getDeclarationName(node: DeclarationStatement | ClassExpression, allowComments?: boolean) { + if (node.name) { + const name = getMutableClone(node.name); + let flags = NodeEmitFlags.NoSourceMap; + if (!allowComments) { + flags |= NodeEmitFlags.NoComments; + } + + setNodeEmitFlags(name, flags | getNodeEmitFlags(name)); + return name; + } + + return getGeneratedNameForNode(node); } function getClassMemberPrefix(node: ClassExpression | ClassDeclaration, member: ClassElement) {