diff --git a/CHANGELOG.md b/CHANGELOG.md index dddd34f24..68597cf4c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ title: Changelog ## Unreleased +### Bug Fixes + +- Cascaded modifier tags will no longer be copied into type literals, #2802. + ## v0.27.3 (2024-12-04) ### Features diff --git a/src/lib/converter/plugins/CommentPlugin.ts b/src/lib/converter/plugins/CommentPlugin.ts index 9539fa4ac..d65fb9a7c 100644 --- a/src/lib/converter/plugins/CommentPlugin.ts +++ b/src/lib/converter/plugins/CommentPlugin.ts @@ -453,7 +453,7 @@ export class CommentPlugin extends ConverterComponent { // Any cascaded tags will show up twice, once on this and once on our signatures // This is completely redundant, so remove them from the wrapping function. - if (sigs.length) { + if (sigs.length && reflection.type?.type !== "reflection") { for (const mod of this.cascadedModifierTags) { reflection.comment.modifierTags.delete(mod); } @@ -527,7 +527,9 @@ export class CommentPlugin extends ConverterComponent { private cascadeModifiers(reflection: Reflection) { const parentComment = reflection.parent?.comment; - if (!parentComment) return; + if (!parentComment || reflection.kindOf(ReflectionKind.TypeLiteral)) { + return; + } const childMods = reflection.comment?.modifierTags ?? new Set(); diff --git a/src/test/converter2/issues/gh2802.ts b/src/test/converter2/issues/gh2802.ts new file mode 100644 index 000000000..ed231e872 --- /dev/null +++ b/src/test/converter2/issues/gh2802.ts @@ -0,0 +1,11 @@ +/** + * Docs + * @alpha + */ +export type AlphaOk = number | string; + +/** + * Docs2 + * @alpha + */ +export type AlphaNoGo = (arg: number | string) => void; diff --git a/src/test/issues.c2.test.ts b/src/test/issues.c2.test.ts index 22ada3863..591c12f82 100644 --- a/src/test/issues.c2.test.ts +++ b/src/test/issues.c2.test.ts @@ -1942,4 +1942,19 @@ describe("Issue Tests", () => { const type = query(project, "typeType"); equal(type.type?.toString(), "any"); }); + + it("#2802 preserves @alpha tags on signature types", () => { + const project = convert(); + const alpha1 = query(project, "AlphaOk"); + equal(Comment.combineDisplayParts(alpha1.comment?.summary), "Docs"); + ok(alpha1.comment?.hasModifier("@alpha")); + + const alpha2 = query(project, "AlphaNoGo"); + equal(Comment.combineDisplayParts(alpha2.comment?.summary), "Docs2"); + ok(alpha2.comment?.hasModifier("@alpha")); + + // Modifiers should not have been cascaded + equal(alpha2.type?.type, "reflection"); + equal(alpha2.type.declaration.comment, undefined); + }); });