mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 21:53:42 -06:00
Emit the new line before leading declaration comments in the declaration file if source code had it
This commit is contained in:
parent
bb638db18d
commit
45e8ff8467
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user