diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 3a1a6d639a1..4ff0886db49 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -178,6 +178,14 @@ module ts { }); } + function emitNewLineBeforeLeadingComments(node: Node, leadingComments: Comment[], writer: EmitTextWriter) { + // If the leading comments start on different line than the start of node, write new line + if (leadingComments && leadingComments.length && node.pos !== leadingComments[0].pos && + currentSourceFile.getLineAndCharacterFromPosition(node.pos).line !== currentSourceFile.getLineAndCharacterFromPosition(leadingComments[0].pos).line) { + writer.writeLine(); + } + } + function writeCommentRange(comment: Comment, writer: EmitTextWriter) { writer.writeLiteral(currentSourceFile.text.substring(comment.pos, comment.end)); } @@ -1932,11 +1940,7 @@ module ts { function emitLeadingDeclarationComments(node: Declaration) { var leadingComments = getLeadingComments(currentSourceFile.text, node.pos); - // If the leading comments start on different line than the start of node, write new line - if (leadingComments && leadingComments.length && node.pos !== leadingComments[0].pos && - currentSourceFile.getLineAndCharacterFromPosition(node.pos).line !== currentSourceFile.getLineAndCharacterFromPosition(leadingComments[0].pos).line) { - writer.writeLine(); - } + emitNewLineBeforeLeadingComments(node, leadingComments, writer); emitComments(leadingComments, writer, writeComment); } @@ -2063,6 +2067,7 @@ module ts { function writeJsDocComments(declaration: Declaration) { if (declaration) { var jsDocComments = getJsDocComments(declaration, currentSourceFile); + emitNewLineBeforeLeadingComments(declaration, jsDocComments, writer); emitComments(jsDocComments, writer, writeCommentRange); } } diff --git a/tests/baselines/reference/commentsFunction.js b/tests/baselines/reference/commentsFunction.js index b54bc4b9217..e82b5709376 100644 --- a/tests/baselines/reference/commentsFunction.js +++ b/tests/baselines/reference/commentsFunction.js @@ -75,7 +75,8 @@ lambdaFoo = function (a, b) { return a * b; }; /** This comment should appear for foo*/ declare function foo(): void; /** This is comment for function signature*/ -declare function fooWithParameters(/** this is comment about a*/ a: string, /** this is comment for b*/ +declare function fooWithParameters(/** this is comment about a*/ a: string, + /** this is comment for b*/ b: number): void; /** fooFunc * comment diff --git a/tests/baselines/reference/declFileCallSignatures.js b/tests/baselines/reference/declFileCallSignatures.js index 6b2be9bae03..2d4519b2090 100644 --- a/tests/baselines/reference/declFileCallSignatures.js +++ b/tests/baselines/reference/declFileCallSignatures.js @@ -76,7 +76,8 @@ export interface ICallSignature { } export interface ICallSignatureWithParameters { /** This is comment for function signature*/ - (/** this is comment about a*/ a: string, /** this is comment for b*/ + (/** this is comment about a*/ a: string, + /** this is comment for b*/ b: number): void; } export interface ICallSignatureWithRestParameters { @@ -100,7 +101,8 @@ interface IGlobalCallSignature { } interface IGlobalCallSignatureWithParameters { /** This is comment for function signature*/ - (/** this is comment about a*/ a: string, /** this is comment for b*/ + (/** this is comment about a*/ a: string, + /** this is comment for b*/ b: number): void; } interface IGlobalCallSignatureWithRestParameters { diff --git a/tests/baselines/reference/declFileConstructSignatures.js b/tests/baselines/reference/declFileConstructSignatures.js index 4a0643389f4..ae756e32eed 100644 --- a/tests/baselines/reference/declFileConstructSignatures.js +++ b/tests/baselines/reference/declFileConstructSignatures.js @@ -76,7 +76,8 @@ export interface IConstructSignature { } export interface IConstructSignatureWithParameters { /** This is comment for function signature*/ - new (/** this is comment about a*/ a: string, /** this is comment for b*/ + new (/** this is comment about a*/ a: string, + /** this is comment for b*/ b: number): any; } export interface IConstructSignatureWithRestParameters { @@ -100,7 +101,8 @@ interface IGlobalConstructSignature { } interface IGlobalConstructSignatureWithParameters { /** This is comment for function signature*/ - new (/** this is comment about a*/ a: string, /** this is comment for b*/ + new (/** this is comment about a*/ a: string, + /** this is comment for b*/ b: number): any; } interface IGlobalConstructSignatureWithRestParameters { diff --git a/tests/baselines/reference/declFileConstructors.js b/tests/baselines/reference/declFileConstructors.js index be28cdeb6a6..f6c059710b1 100644 --- a/tests/baselines/reference/declFileConstructors.js +++ b/tests/baselines/reference/declFileConstructors.js @@ -226,7 +226,8 @@ export declare class SimpleConstructor { } export declare class ConstructorWithParameters { /** This is comment for function signature*/ - constructor(/** this is comment about a*/ a: string, /** this is comment for b*/ + constructor(/** this is comment about a*/ a: string, + /** this is comment for b*/ b: number); } export declare class ConstructorWithRestParamters { @@ -259,7 +260,8 @@ declare class GlobalSimpleConstructor { } declare class GlobalConstructorWithParameters { /** This is comment for function signature*/ - constructor(/** this is comment about a*/ a: string, /** this is comment for b*/ + constructor(/** this is comment about a*/ a: string, + /** this is comment for b*/ b: number); } declare class GlobalConstructorWithRestParamters { diff --git a/tests/baselines/reference/declFileFunctions.js b/tests/baselines/reference/declFileFunctions.js index fe6d55455a8..c1bb726c9ff 100644 --- a/tests/baselines/reference/declFileFunctions.js +++ b/tests/baselines/reference/declFileFunctions.js @@ -128,7 +128,8 @@ function globalfooWithOverloads(a) { /** This comment should appear for foo*/ export declare function foo(): void; /** This is comment for function signature*/ -export declare function fooWithParameters(/** this is comment about a*/ a: string, /** this is comment for b*/ +export declare function fooWithParameters(/** this is comment about a*/ a: string, + /** this is comment for b*/ b: number): void; export declare function fooWithRestParameters(a: string, ...rests: string[]): string; export declare function fooWithOverloads(a: string): string; @@ -137,7 +138,8 @@ export declare function fooWithOverloads(a: number): number; /** This comment should appear for foo*/ declare function globalfoo(): void; /** This is comment for function signature*/ -declare function globalfooWithParameters(/** this is comment about a*/ a: string, /** this is comment for b*/ +declare function globalfooWithParameters(/** this is comment about a*/ a: string, + /** this is comment for b*/ b: number): void; declare function globalfooWithRestParameters(a: string, ...rests: string[]): string; declare function globalfooWithOverloads(a: string): string; diff --git a/tests/baselines/reference/declFileMethods.js b/tests/baselines/reference/declFileMethods.js index 82fa6d14749..57853fedd13 100644 --- a/tests/baselines/reference/declFileMethods.js +++ b/tests/baselines/reference/declFileMethods.js @@ -362,7 +362,8 @@ export declare class c1 { /** This comment should appear for foo*/ foo(): void; /** This is comment for function signature*/ - fooWithParameters(/** this is comment about a*/ a: string, /** this is comment for b*/ + fooWithParameters(/** this is comment about a*/ a: string, + /** this is comment for b*/ b: number): void; fooWithRestParameters(a: string, ...rests: string[]): string; fooWithOverloads(a: string): string; @@ -370,7 +371,8 @@ export declare class c1 { /** This comment should appear for privateFoo*/ private privateFoo(); /** This is comment for function signature*/ - private privateFooWithParameters(/** this is comment about a*/ a, /** this is comment for b*/ + private privateFooWithParameters(/** this is comment about a*/ a, + /** this is comment for b*/ b); private privateFooWithRestParameters(a, ...rests); private privateFooWithOverloads(a); @@ -378,7 +380,8 @@ export declare class c1 { /** This comment should appear for static foo*/ static staticFoo(): void; /** This is comment for function signature*/ - static staticFooWithParameters(/** this is comment about a*/ a: string, /** this is comment for b*/ + static staticFooWithParameters(/** this is comment about a*/ a: string, + /** this is comment for b*/ b: number): void; static staticFooWithRestParameters(a: string, ...rests: string[]): string; static staticFooWithOverloads(a: string): string; @@ -386,7 +389,8 @@ export declare class c1 { /** This comment should appear for privateStaticFoo*/ private static privateStaticFoo(); /** This is comment for function signature*/ - private static privateStaticFooWithParameters(/** this is comment about a*/ a, /** this is comment for b*/ + private static privateStaticFooWithParameters(/** this is comment about a*/ a, + /** this is comment for b*/ b); private static privateStaticFooWithRestParameters(a, ...rests); private static privateStaticFooWithOverloads(a); @@ -396,7 +400,8 @@ export interface I1 { /** This comment should appear for foo*/ foo(): string; /** This is comment for function signature*/ - fooWithParameters(/** this is comment about a*/ a: string, /** this is comment for b*/ + fooWithParameters(/** this is comment about a*/ a: string, + /** this is comment for b*/ b: number): void; fooWithRestParameters(a: string, ...rests: string[]): string; fooWithOverloads(a: string): string; @@ -407,7 +412,8 @@ declare class c2 { /** This comment should appear for foo*/ foo(): void; /** This is comment for function signature*/ - fooWithParameters(/** this is comment about a*/ a: string, /** this is comment for b*/ + fooWithParameters(/** this is comment about a*/ a: string, + /** this is comment for b*/ b: number): void; fooWithRestParameters(a: string, ...rests: string[]): string; fooWithOverloads(a: string): string; @@ -415,7 +421,8 @@ declare class c2 { /** This comment should appear for privateFoo*/ private privateFoo(); /** This is comment for function signature*/ - private privateFooWithParameters(/** this is comment about a*/ a, /** this is comment for b*/ + private privateFooWithParameters(/** this is comment about a*/ a, + /** this is comment for b*/ b); private privateFooWithRestParameters(a, ...rests); private privateFooWithOverloads(a); @@ -423,7 +430,8 @@ declare class c2 { /** This comment should appear for static foo*/ static staticFoo(): void; /** This is comment for function signature*/ - static staticFooWithParameters(/** this is comment about a*/ a: string, /** this is comment for b*/ + static staticFooWithParameters(/** this is comment about a*/ a: string, + /** this is comment for b*/ b: number): void; static staticFooWithRestParameters(a: string, ...rests: string[]): string; static staticFooWithOverloads(a: string): string; @@ -431,7 +439,8 @@ declare class c2 { /** This comment should appear for privateStaticFoo*/ private static privateStaticFoo(); /** This is comment for function signature*/ - private static privateStaticFooWithParameters(/** this is comment about a*/ a, /** this is comment for b*/ + private static privateStaticFooWithParameters(/** this is comment about a*/ a, + /** this is comment for b*/ b); private static privateStaticFooWithRestParameters(a, ...rests); private static privateStaticFooWithOverloads(a); @@ -441,7 +450,8 @@ interface I2 { /** This comment should appear for foo*/ foo(): string; /** This is comment for function signature*/ - fooWithParameters(/** this is comment about a*/ a: string, /** this is comment for b*/ + fooWithParameters(/** this is comment about a*/ a: string, + /** this is comment for b*/ b: number): void; fooWithRestParameters(a: string, ...rests: string[]): string; fooWithOverloads(a: string): string;