From 3969b89b234cc642ccbc40f8fbebe3b29c74a80d Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 21 Dec 2015 13:40:59 -0800 Subject: [PATCH] Fixups for #6163. --- src/compiler/emitter.ts | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 88d9d20c4c0..996dac118ef 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4280,25 +4280,29 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi // TODO (yuisu) : we should not have special cases to condition emitting comments // but have one place to fix check for these conditions. - if (node.kind !== SyntaxKind.MethodDeclaration && - node.kind !== SyntaxKind.MethodSignature && - node.parent && - node.parent.kind !== SyntaxKind.PropertyAssignment && - node.parent.kind !== SyntaxKind.CallExpression && - node.parent.kind !== SyntaxKind.ArrayLiteralExpression) { - // 1. Methods will emit the comments as part of emitting method declaration - + const { kind, parent } = node; + if (kind !== SyntaxKind.MethodDeclaration && + kind !== SyntaxKind.MethodSignature && + parent && + parent.kind !== SyntaxKind.PropertyAssignment && + parent.kind !== SyntaxKind.CallExpression && + parent.kind !== SyntaxKind.ArrayLiteralExpression) { + // 1. Methods will emit comments at their assignment declaration sites. + // // 2. If the function is a property of object literal, emitting leading-comments - // is done by emitNodeWithoutSourceMap which then call this function. - // In particular, we would like to avoid emit comments twice in following case: - // For example: + // is done by emitNodeWithoutSourceMap which then call this function. + // In particular, we would like to avoid emit comments twice in following case: + // // var obj = { // id: // /*comment*/ () => void // } - + // // 3. If the function is an argument in call expression, emitting of comments will be - // taken care of in emit list of arguments inside of emitCallexpression + // taken care of in emit list of arguments inside of 'emitCallExpression'. + // + // 4. If the function is in an array literal, 'emitLinePreservingList' will take care + // of leading comments. emitLeadingComments(node); } @@ -4325,12 +4329,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } emitSignatureAndBody(node); - if (modulekind !== ModuleKind.ES6 && node.kind === SyntaxKind.FunctionDeclaration && node.parent === currentSourceFile && node.name) { + if (modulekind !== ModuleKind.ES6 && kind === SyntaxKind.FunctionDeclaration && parent === currentSourceFile && node.name) { emitExportMemberAssignments((node).name); } emitEnd(node); - if (node.kind !== SyntaxKind.MethodDeclaration && node.kind !== SyntaxKind.MethodSignature) { + if (kind !== SyntaxKind.MethodDeclaration && kind !== SyntaxKind.MethodSignature) { emitTrailingComments(node); } }