mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 03:23:08 -06:00
fix(59397): JsDoc is missing/duplicated in declarations for overloads declared in classes declared in functions (#59675)
This commit is contained in:
parent
6a90111d05
commit
db8eacd7e2
@ -7369,7 +7369,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
const signatures = getSignaturesOfType(filterType(propertyType, t => !(t.flags & TypeFlags.Undefined)), SignatureKind.Call);
|
||||
for (const signature of signatures) {
|
||||
const methodDeclaration = signatureToSignatureDeclarationHelper(signature, SyntaxKind.MethodSignature, context, { name: propertyName, questionToken: optionalToken }) as MethodSignature;
|
||||
typeElements.push(preserveCommentsOn(methodDeclaration));
|
||||
typeElements.push(preserveCommentsOn(methodDeclaration, signature.declaration || propertySymbol.valueDeclaration));
|
||||
}
|
||||
if (signatures.length || !optionalToken) {
|
||||
return;
|
||||
@ -7401,9 +7401,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
propertyTypeNode,
|
||||
);
|
||||
|
||||
typeElements.push(preserveCommentsOn(propertySignature));
|
||||
typeElements.push(preserveCommentsOn(propertySignature, propertySymbol.valueDeclaration));
|
||||
|
||||
function preserveCommentsOn<T extends Node>(node: T) {
|
||||
function preserveCommentsOn<T extends Node>(node: T, range: Node | undefined) {
|
||||
const jsdocPropertyTag = propertySymbol.declarations?.find((d): d is JSDocPropertyTag => d.kind === SyntaxKind.JSDocPropertyTag);
|
||||
if (jsdocPropertyTag) {
|
||||
const commentText = getTextOfJSDocComment(jsdocPropertyTag.comment);
|
||||
@ -7411,9 +7411,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
setSyntheticLeadingComments(node, [{ kind: SyntaxKind.MultiLineCommentTrivia, text: "*\n * " + commentText.replace(/\n/g, "\n * ") + "\n ", pos: -1, end: -1, hasTrailingNewLine: true }]);
|
||||
}
|
||||
}
|
||||
else if (propertySymbol.valueDeclaration) {
|
||||
else if (range) {
|
||||
// Copy comments to node for declaration emit
|
||||
setCommentRange(context, node, propertySymbol.valueDeclaration);
|
||||
setCommentRange(context, node, range);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
45
tests/baselines/reference/signatureOverloadsWithComments.js
Normal file
45
tests/baselines/reference/signatureOverloadsWithComments.js
Normal file
@ -0,0 +1,45 @@
|
||||
//// [tests/cases/compiler/signatureOverloadsWithComments.ts] ////
|
||||
|
||||
//// [signatureOverloadsWithComments.ts]
|
||||
/**
|
||||
* Docs
|
||||
*/
|
||||
function Foo() {
|
||||
return class Bar {
|
||||
/**
|
||||
* comment 1
|
||||
*/
|
||||
foo(bar: string): void;
|
||||
/**
|
||||
* @deprecated This signature is deprecated
|
||||
*
|
||||
* comment 2
|
||||
*/
|
||||
foo(): string;
|
||||
foo(bar?: string): string | void {
|
||||
return 'hi'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//// [signatureOverloadsWithComments.d.ts]
|
||||
/**
|
||||
* Docs
|
||||
*/
|
||||
declare function Foo(): {
|
||||
new (): {
|
||||
/**
|
||||
* comment 1
|
||||
*/
|
||||
foo(bar: string): void;
|
||||
/**
|
||||
* @deprecated This signature is deprecated
|
||||
*
|
||||
* comment 2
|
||||
*/
|
||||
foo(): string;
|
||||
};
|
||||
};
|
||||
@ -0,0 +1,36 @@
|
||||
//// [tests/cases/compiler/signatureOverloadsWithComments.ts] ////
|
||||
|
||||
=== signatureOverloadsWithComments.ts ===
|
||||
/**
|
||||
* Docs
|
||||
*/
|
||||
function Foo() {
|
||||
>Foo : Symbol(Foo, Decl(signatureOverloadsWithComments.ts, 0, 0))
|
||||
|
||||
return class Bar {
|
||||
>Bar : Symbol(Bar, Decl(signatureOverloadsWithComments.ts, 4, 10))
|
||||
|
||||
/**
|
||||
* comment 1
|
||||
*/
|
||||
foo(bar: string): void;
|
||||
>foo : Symbol(Bar.foo, Decl(signatureOverloadsWithComments.ts, 4, 22), Decl(signatureOverloadsWithComments.ts, 8, 31), Decl(signatureOverloadsWithComments.ts, 14, 22))
|
||||
>bar : Symbol(bar, Decl(signatureOverloadsWithComments.ts, 8, 12))
|
||||
|
||||
/**
|
||||
* @deprecated This signature is deprecated
|
||||
*
|
||||
* comment 2
|
||||
*/
|
||||
foo(): string;
|
||||
>foo : Symbol(Bar.foo, Decl(signatureOverloadsWithComments.ts, 4, 22), Decl(signatureOverloadsWithComments.ts, 8, 31), Decl(signatureOverloadsWithComments.ts, 14, 22))
|
||||
|
||||
foo(bar?: string): string | void {
|
||||
>foo : Symbol(Bar.foo, Decl(signatureOverloadsWithComments.ts, 4, 22), Decl(signatureOverloadsWithComments.ts, 8, 31), Decl(signatureOverloadsWithComments.ts, 14, 22))
|
||||
>bar : Symbol(bar, Decl(signatureOverloadsWithComments.ts, 15, 12))
|
||||
|
||||
return 'hi'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,47 @@
|
||||
//// [tests/cases/compiler/signatureOverloadsWithComments.ts] ////
|
||||
|
||||
=== signatureOverloadsWithComments.ts ===
|
||||
/**
|
||||
* Docs
|
||||
*/
|
||||
function Foo() {
|
||||
>Foo : () => typeof Bar
|
||||
> : ^^^^^^^^^^^^^^^^
|
||||
|
||||
return class Bar {
|
||||
>class Bar { /** * comment 1 */ foo(bar: string): void; /** * @deprecated This signature is deprecated * * comment 2 */ foo(): string; foo(bar?: string): string | void { return 'hi' } } : typeof Bar
|
||||
> : ^^^^^^^^^^
|
||||
>Bar : typeof Bar
|
||||
> : ^^^^^^^^^^
|
||||
|
||||
/**
|
||||
* comment 1
|
||||
*/
|
||||
foo(bar: string): void;
|
||||
>foo : { (bar: string): void; (): string; }
|
||||
> : ^^^ ^^ ^^^ ^^^^^^ ^^^
|
||||
>bar : string
|
||||
> : ^^^^^^
|
||||
|
||||
/**
|
||||
* @deprecated This signature is deprecated
|
||||
*
|
||||
* comment 2
|
||||
*/
|
||||
foo(): string;
|
||||
>foo : { (bar: string): void; (): string; }
|
||||
> : ^^^ ^^ ^^^ ^^^^^^ ^^^
|
||||
|
||||
foo(bar?: string): string | void {
|
||||
>foo : { (bar: string): void; (): string; }
|
||||
> : ^^^ ^^ ^^^ ^^^^^^ ^^^
|
||||
>bar : string
|
||||
> : ^^^^^^
|
||||
|
||||
return 'hi'
|
||||
>'hi' : "hi"
|
||||
> : ^^^^
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
23
tests/cases/compiler/signatureOverloadsWithComments.ts
Normal file
23
tests/cases/compiler/signatureOverloadsWithComments.ts
Normal file
@ -0,0 +1,23 @@
|
||||
// @declaration: true
|
||||
// @emitDeclarationOnly: true
|
||||
|
||||
/**
|
||||
* Docs
|
||||
*/
|
||||
function Foo() {
|
||||
return class Bar {
|
||||
/**
|
||||
* comment 1
|
||||
*/
|
||||
foo(bar: string): void;
|
||||
/**
|
||||
* @deprecated This signature is deprecated
|
||||
*
|
||||
* comment 2
|
||||
*/
|
||||
foo(): string;
|
||||
foo(bar?: string): string | void {
|
||||
return 'hi'
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user