From d5bb930c880e5a6fa0e2903fc4dec6edfc865333 Mon Sep 17 00:00:00 2001 From: Gerrit Birkeland Date: Fri, 14 May 2021 21:52:05 -0600 Subject: [PATCH] fix: Inherit comments from parent methods Resolves #1580 --- src/lib/converter/plugins/ImplementsPlugin.ts | 1 + src/lib/converter/plugins/TypePlugin.ts | 6 +++--- src/test/converter2.test.ts | 11 +++++++++++ src/test/converter2/issues/gh1580.ts | 18 ++++++++++++++++++ 4 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 src/test/converter2/issues/gh1580.ts diff --git a/src/lib/converter/plugins/ImplementsPlugin.ts b/src/lib/converter/plugins/ImplementsPlugin.ts index b26095f89..e325e39e7 100644 --- a/src/lib/converter/plugins/ImplementsPlugin.ts +++ b/src/lib/converter/plugins/ImplementsPlugin.ts @@ -171,6 +171,7 @@ export class ImplementsPlugin extends ConverterComponent { parentSig, context.project ); + copyComment(childSig, parentSig); } child[key] = new ReferenceType( diff --git a/src/lib/converter/plugins/TypePlugin.ts b/src/lib/converter/plugins/TypePlugin.ts index a0e0bf112..82dd2f446 100644 --- a/src/lib/converter/plugins/TypePlugin.ts +++ b/src/lib/converter/plugins/TypePlugin.ts @@ -98,11 +98,11 @@ export class TypePlugin extends ConverterComponent { private onResolveEnd(context: Context) { this.reflections.forEach((reflection) => { if (reflection.implementedBy) { - reflection.implementedBy.sort((a: any, b: any) => { - if (a["name"] === b["name"]) { + reflection.implementedBy.sort((a, b) => { + if (a.name === b.name) { return 0; } - return a["name"] > b["name"] ? 1 : -1; + return a.name > b.name ? 1 : -1; }); } diff --git a/src/test/converter2.test.ts b/src/test/converter2.test.ts index 71ec8724c..786463574 100644 --- a/src/test/converter2.test.ts +++ b/src/test/converter2.test.ts @@ -194,6 +194,17 @@ const issueTests: Record void> = { "Symbol re-exported from ignored file is ignored." ); }, + + gh1580(project) { + ok( + query(project, "B.prop").hasComment(), + "Overwritten property with no comment should be inherited" + ); + ok( + query(project, "B.run").signatures?.[0]?.hasComment(), + "Overwritten method with no comment should be inherited" + ); + }, }; describe("Converter2", () => { diff --git a/src/test/converter2/issues/gh1580.ts b/src/test/converter2/issues/gh1580.ts new file mode 100644 index 000000000..3e49d0d3d --- /dev/null +++ b/src/test/converter2/issues/gh1580.ts @@ -0,0 +1,18 @@ +export class A { + /** Prop docs */ + prop!: string; + + /** Run docs */ + run(): void { + console.log("A"); + } +} + +export class B extends A { + prop!: "B"; + + run(): void { + super.run(); + console.log("B"); + } +}