From 6bf73a691acad103ec9151826cbdc034187f7baa Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Thu, 14 Aug 2014 09:12:20 -0700 Subject: [PATCH] Declaration comments for call, constructo and index signatures in .d.ts --- src/compiler/emitter.ts | 5 +++++ tests/baselines/reference/commentsInterface.js | 3 +++ tests/baselines/reference/commentsOverloads.js | 8 ++++++++ tests/baselines/reference/commentsemitComments.js | 3 +++ tests/baselines/reference/declFileCallSignatures.js | 6 ++++++ tests/baselines/reference/declFileConstructSignatures.js | 6 ++++++ 6 files changed, 31 insertions(+) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index b1d89d4a75f..690c5508ae7 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2543,11 +2543,16 @@ module ts { } function emitConstructSignatureDeclaration(node: SignatureDeclaration) { + emitJsDocComments(node); write("new "); emitSignatureDeclaration(node); } function emitSignatureDeclaration(node: SignatureDeclaration) { + if (node.kind === SyntaxKind.CallSignature || node.kind === SyntaxKind.IndexSignature) { + // Only index and call signatures are emitted directly, so emit their js doc comments, rest will do that in their own functions + emitJsDocComments(node); + } emitTypeParameters(node.typeParameters); if (node.kind === SyntaxKind.IndexSignature) { write("["); diff --git a/tests/baselines/reference/commentsInterface.js b/tests/baselines/reference/commentsInterface.js index 979115d6b22..f3f1f06785c 100644 --- a/tests/baselines/reference/commentsInterface.js +++ b/tests/baselines/reference/commentsInterface.js @@ -117,11 +117,14 @@ interface i2 { x: number; /** this is foo*/ foo: (b: number) => string; + /** this is indexer*/ [i: string]: any; + /**new method*/ new (i: i1): any; nc_x: number; nc_foo: (b: number) => string; [i: number]: number; + /** this is call signature*/ (a: number, b: number): number; /** this is fnfoo*/ fnfoo(b: number): string; diff --git a/tests/baselines/reference/commentsOverloads.js b/tests/baselines/reference/commentsOverloads.js index 6ea4265a89a..518e268d1e9 100644 --- a/tests/baselines/reference/commentsOverloads.js +++ b/tests/baselines/reference/commentsOverloads.js @@ -274,7 +274,9 @@ declare function f4(a: number): number; /** this is signature 4 - with string parameter*/ declare function f4(b: string): number; interface i1 { + /**this signature 1*/ (a: number): number; + /**this is signature 2*/ (b: string): number; /** foo 1*/ foo(a: number): number; @@ -294,19 +296,25 @@ interface i1 { /** foo4 any */ foo4(c: any): any; new (a: string): any; + /** new 1*/ new (b: number): any; } declare var i1_i: i1; interface i2 { new (a: string): any; + /** new 2*/ new (b: number): any; (a: number): number; + /**this is signature 2*/ (b: string): number; } declare var i2_i: i2; interface i3 { + /** new 1*/ new (a: string): any; + /** new 2*/ new (b: number): any; + /**this is signature 1*/ (a: number): number; (b: string): number; } diff --git a/tests/baselines/reference/commentsemitComments.js b/tests/baselines/reference/commentsemitComments.js index 15ae7472ae7..745e64a4f1a 100644 --- a/tests/baselines/reference/commentsemitComments.js +++ b/tests/baselines/reference/commentsemitComments.js @@ -172,8 +172,11 @@ declare class c { declare var i: c; /** interface comments*/ interface i1 { + /** caller comments*/ (a: number): number; + /** new comments*/ new (b: string): any; + /**indexer property*/ [a: number]: string; /** function property;*/ myFoo(a: number): string; diff --git a/tests/baselines/reference/declFileCallSignatures.js b/tests/baselines/reference/declFileCallSignatures.js index bcf0f12cab8..3fe5f52bc9e 100644 --- a/tests/baselines/reference/declFileCallSignatures.js +++ b/tests/baselines/reference/declFileCallSignatures.js @@ -71,9 +71,11 @@ interface IGlobalCallSignatureWithOwnTypeParametes { //// [declFileCallSignatures_0.d.ts] export interface ICallSignature { + /** This comment should appear for foo*/ (): string; } export interface ICallSignatureWithParameters { + /** This is comment for function signature*/ (a: string, b: number): void; } export interface ICallSignatureWithRestParameters { @@ -84,6 +86,7 @@ export interface ICallSignatureWithOverloads { (a: number): number; } export interface ICallSignatureWithTypeParameters { + /** This comment should appear for foo*/ (a: T): string; } export interface ICallSignatureWithOwnTypeParametes { @@ -91,9 +94,11 @@ export interface ICallSignatureWithOwnTypeParametes { } //// [declFileCallSignatures_1.d.ts] interface IGlobalCallSignature { + /** This comment should appear for foo*/ (): string; } interface IGlobalCallSignatureWithParameters { + /** This is comment for function signature*/ (a: string, b: number): void; } interface IGlobalCallSignatureWithRestParameters { @@ -104,6 +109,7 @@ interface IGlobalCallSignatureWithOverloads { (a: number): number; } interface IGlobalCallSignatureWithTypeParameters { + /** This comment should appear for foo*/ (a: T): string; } interface IGlobalCallSignatureWithOwnTypeParametes { diff --git a/tests/baselines/reference/declFileConstructSignatures.js b/tests/baselines/reference/declFileConstructSignatures.js index d59e937d47b..aaf9e45c6e2 100644 --- a/tests/baselines/reference/declFileConstructSignatures.js +++ b/tests/baselines/reference/declFileConstructSignatures.js @@ -71,9 +71,11 @@ interface IGlobalConstructSignatureWithOwnTypeParametes { //// [declFileConstructSignatures_0.d.ts] export interface IConstructSignature { + /** This comment should appear for foo*/ new (): string; } export interface IConstructSignatureWithParameters { + /** This is comment for function signature*/ new (a: string, b: number): any; } export interface IConstructSignatureWithRestParameters { @@ -84,6 +86,7 @@ export interface IConstructSignatureWithOverloads { new (a: number): number; } export interface IConstructSignatureWithTypeParameters { + /** This comment should appear for foo*/ new (a: T): T; } export interface IConstructSignatureWithOwnTypeParametes { @@ -91,9 +94,11 @@ export interface IConstructSignatureWithOwnTypeParametes { } //// [declFileConstructSignatures_1.d.ts] interface IGlobalConstructSignature { + /** This comment should appear for foo*/ new (): string; } interface IGlobalConstructSignatureWithParameters { + /** This is comment for function signature*/ new (a: string, b: number): any; } interface IGlobalConstructSignatureWithRestParameters { @@ -104,6 +109,7 @@ interface IGlobalConstructSignatureWithOverloads { new (a: number): number; } interface IGlobalConstructSignatureWithTypeParameters { + /** This comment should appear for foo*/ new (a: T): T; } interface IGlobalConstructSignatureWithOwnTypeParametes {