mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Copy comments from inferred types to generated nodes (#22730)
This commit is contained in:
@@ -3324,6 +3324,10 @@ namespace ts {
|
||||
const methodDeclaration = <MethodSignature>signatureToSignatureDeclarationHelper(signature, SyntaxKind.MethodSignature, context);
|
||||
methodDeclaration.name = propertyName;
|
||||
methodDeclaration.questionToken = optionalToken;
|
||||
if (propertySymbol.valueDeclaration) {
|
||||
// Copy comments to node for declaration emit
|
||||
setCommentRange(methodDeclaration, propertySymbol.valueDeclaration);
|
||||
}
|
||||
typeElements.push(methodDeclaration);
|
||||
}
|
||||
}
|
||||
@@ -3340,6 +3344,10 @@ namespace ts {
|
||||
optionalToken,
|
||||
propertyTypeNode,
|
||||
/*initializer*/ undefined);
|
||||
if (propertySymbol.valueDeclaration) {
|
||||
// Copy comments to node for declaration emit
|
||||
setCommentRange(propertySignature, propertySymbol.valueDeclaration);
|
||||
}
|
||||
typeElements.push(propertySignature);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
//// [declarationEmitRetainsJsdocyComments.ts]
|
||||
/**
|
||||
* comment1
|
||||
* @param p
|
||||
*/
|
||||
export const foo = (p: string) => {
|
||||
return {
|
||||
/**
|
||||
* comment2
|
||||
* @param s
|
||||
*/
|
||||
bar: (s: number) => {},
|
||||
/**
|
||||
* comment3
|
||||
* @param s
|
||||
*/
|
||||
bar2(s: number) {},
|
||||
}
|
||||
}
|
||||
|
||||
export class Foo {
|
||||
/**
|
||||
* comment4
|
||||
* @param s
|
||||
*/
|
||||
bar(s: number) {
|
||||
}
|
||||
}
|
||||
|
||||
export let {
|
||||
/**
|
||||
* comment5
|
||||
*/
|
||||
someMethod
|
||||
} = null as any;
|
||||
|
||||
declare global {
|
||||
interface ExtFunc {
|
||||
/**
|
||||
* comment6
|
||||
*/
|
||||
someMethod(collection: any[]): boolean;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//// [declarationEmitRetainsJsdocyComments.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
/**
|
||||
* comment1
|
||||
* @param p
|
||||
*/
|
||||
exports.foo = function (p) {
|
||||
return {
|
||||
/**
|
||||
* comment2
|
||||
* @param s
|
||||
*/
|
||||
bar: function (s) { },
|
||||
/**
|
||||
* comment3
|
||||
* @param s
|
||||
*/
|
||||
bar2: function (s) { }
|
||||
};
|
||||
};
|
||||
var Foo = /** @class */ (function () {
|
||||
function Foo() {
|
||||
}
|
||||
/**
|
||||
* comment4
|
||||
* @param s
|
||||
*/
|
||||
Foo.prototype.bar = function (s) {
|
||||
};
|
||||
return Foo;
|
||||
}());
|
||||
exports.Foo = Foo;
|
||||
/**
|
||||
* comment5
|
||||
*/
|
||||
exports.someMethod = null.someMethod;
|
||||
|
||||
|
||||
//// [declarationEmitRetainsJsdocyComments.d.ts]
|
||||
/**
|
||||
* comment1
|
||||
* @param p
|
||||
*/
|
||||
export declare const foo: (p: string) => {
|
||||
/**
|
||||
* comment2
|
||||
* @param s
|
||||
*/
|
||||
bar: (s: number) => void;
|
||||
/**
|
||||
* comment3
|
||||
* @param s
|
||||
*/
|
||||
bar2(s: number): void;
|
||||
};
|
||||
export declare class Foo {
|
||||
/**
|
||||
* comment4
|
||||
* @param s
|
||||
*/
|
||||
bar(s: number): void;
|
||||
}
|
||||
export declare let
|
||||
/**
|
||||
* comment5
|
||||
*/
|
||||
someMethod: any;
|
||||
declare global {
|
||||
interface ExtFunc {
|
||||
/**
|
||||
* comment6
|
||||
*/
|
||||
someMethod(collection: any[]): boolean;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
=== tests/cases/compiler/declarationEmitRetainsJsdocyComments.ts ===
|
||||
/**
|
||||
* comment1
|
||||
* @param p
|
||||
*/
|
||||
export const foo = (p: string) => {
|
||||
>foo : Symbol(foo, Decl(declarationEmitRetainsJsdocyComments.ts, 4, 12))
|
||||
>p : Symbol(p, Decl(declarationEmitRetainsJsdocyComments.ts, 4, 20))
|
||||
|
||||
return {
|
||||
/**
|
||||
* comment2
|
||||
* @param s
|
||||
*/
|
||||
bar: (s: number) => {},
|
||||
>bar : Symbol(bar, Decl(declarationEmitRetainsJsdocyComments.ts, 5, 12))
|
||||
>s : Symbol(s, Decl(declarationEmitRetainsJsdocyComments.ts, 10, 14))
|
||||
|
||||
/**
|
||||
* comment3
|
||||
* @param s
|
||||
*/
|
||||
bar2(s: number) {},
|
||||
>bar2 : Symbol(bar2, Decl(declarationEmitRetainsJsdocyComments.ts, 10, 31))
|
||||
>s : Symbol(s, Decl(declarationEmitRetainsJsdocyComments.ts, 15, 13))
|
||||
}
|
||||
}
|
||||
|
||||
export class Foo {
|
||||
>Foo : Symbol(Foo, Decl(declarationEmitRetainsJsdocyComments.ts, 17, 1))
|
||||
|
||||
/**
|
||||
* comment4
|
||||
* @param s
|
||||
*/
|
||||
bar(s: number) {
|
||||
>bar : Symbol(Foo.bar, Decl(declarationEmitRetainsJsdocyComments.ts, 19, 18))
|
||||
>s : Symbol(s, Decl(declarationEmitRetainsJsdocyComments.ts, 24, 8))
|
||||
}
|
||||
}
|
||||
|
||||
export let {
|
||||
/**
|
||||
* comment5
|
||||
*/
|
||||
someMethod
|
||||
>someMethod : Symbol(someMethod, Decl(declarationEmitRetainsJsdocyComments.ts, 28, 12))
|
||||
|
||||
} = null as any;
|
||||
|
||||
declare global {
|
||||
>global : Symbol(global, Decl(declarationEmitRetainsJsdocyComments.ts, 33, 16))
|
||||
|
||||
interface ExtFunc {
|
||||
>ExtFunc : Symbol(ExtFunc, Decl(declarationEmitRetainsJsdocyComments.ts, 35, 16))
|
||||
|
||||
/**
|
||||
* comment6
|
||||
*/
|
||||
someMethod(collection: any[]): boolean;
|
||||
>someMethod : Symbol(ExtFunc.someMethod, Decl(declarationEmitRetainsJsdocyComments.ts, 36, 23))
|
||||
>collection : Symbol(collection, Decl(declarationEmitRetainsJsdocyComments.ts, 40, 19))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
=== tests/cases/compiler/declarationEmitRetainsJsdocyComments.ts ===
|
||||
/**
|
||||
* comment1
|
||||
* @param p
|
||||
*/
|
||||
export const foo = (p: string) => {
|
||||
>foo : (p: string) => { bar: (s: number) => void; bar2(s: number): void; }
|
||||
>(p: string) => { return { /** * comment2 * @param s */ bar: (s: number) => {}, /** * comment3 * @param s */ bar2(s: number) {}, }} : (p: string) => { bar: (s: number) => void; bar2(s: number): void; }
|
||||
>p : string
|
||||
|
||||
return {
|
||||
>{ /** * comment2 * @param s */ bar: (s: number) => {}, /** * comment3 * @param s */ bar2(s: number) {}, } : { bar: (s: number) => void; bar2(s: number): void; }
|
||||
|
||||
/**
|
||||
* comment2
|
||||
* @param s
|
||||
*/
|
||||
bar: (s: number) => {},
|
||||
>bar : (s: number) => void
|
||||
>(s: number) => {} : (s: number) => void
|
||||
>s : number
|
||||
|
||||
/**
|
||||
* comment3
|
||||
* @param s
|
||||
*/
|
||||
bar2(s: number) {},
|
||||
>bar2 : (s: number) => void
|
||||
>s : number
|
||||
}
|
||||
}
|
||||
|
||||
export class Foo {
|
||||
>Foo : Foo
|
||||
|
||||
/**
|
||||
* comment4
|
||||
* @param s
|
||||
*/
|
||||
bar(s: number) {
|
||||
>bar : (s: number) => void
|
||||
>s : number
|
||||
}
|
||||
}
|
||||
|
||||
export let {
|
||||
/**
|
||||
* comment5
|
||||
*/
|
||||
someMethod
|
||||
>someMethod : any
|
||||
|
||||
} = null as any;
|
||||
>null as any : any
|
||||
>null : null
|
||||
|
||||
declare global {
|
||||
>global : any
|
||||
|
||||
interface ExtFunc {
|
||||
>ExtFunc : ExtFunc
|
||||
|
||||
/**
|
||||
* comment6
|
||||
*/
|
||||
someMethod(collection: any[]): boolean;
|
||||
>someMethod : (collection: any[]) => boolean
|
||||
>collection : any[]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
// @declaration: true
|
||||
/**
|
||||
* comment1
|
||||
* @param p
|
||||
*/
|
||||
export const foo = (p: string) => {
|
||||
return {
|
||||
/**
|
||||
* comment2
|
||||
* @param s
|
||||
*/
|
||||
bar: (s: number) => {},
|
||||
/**
|
||||
* comment3
|
||||
* @param s
|
||||
*/
|
||||
bar2(s: number) {},
|
||||
}
|
||||
}
|
||||
|
||||
export class Foo {
|
||||
/**
|
||||
* comment4
|
||||
* @param s
|
||||
*/
|
||||
bar(s: number) {
|
||||
}
|
||||
}
|
||||
|
||||
export let {
|
||||
/**
|
||||
* comment5
|
||||
*/
|
||||
someMethod
|
||||
} = null as any;
|
||||
|
||||
declare global {
|
||||
interface ExtFunc {
|
||||
/**
|
||||
* comment6
|
||||
*/
|
||||
someMethod(collection: any[]): boolean;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user