Skip to content

Commit

Permalink
Fix handling of cascadedModifierTags
Browse files Browse the repository at this point in the history
Resolves #2802
  • Loading branch information
Gerrit0 committed Dec 6, 2024
1 parent f421460 commit 9dcbd5d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/lib/converter/plugins/CommentPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();

Expand Down
11 changes: 11 additions & 0 deletions src/test/converter2/issues/gh2802.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Docs
* @alpha
*/
export type AlphaOk = number | string;

/**
* Docs2
* @alpha
*/
export type AlphaNoGo = (arg: number | string) => void;
15 changes: 15 additions & 0 deletions src/test/issues.c2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit 9dcbd5d

Please sign in to comment.