Skip to content

Commit

Permalink
Add support for @hideconstructor
Browse files Browse the repository at this point in the history
Resolves #2577
  • Loading branch information
Gerrit0 committed May 24, 2024
1 parent 4f23063 commit c19db05
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
- New option, `--customFooterHtml` to add custom HTML to the generated page footer, #2559.
- TypeDoc will now copy modifier tags to children if specified in the `--cascadedModifierTags` option, #2056.
- TypeDoc will now warn if mutually exclusive modifier tags are specified for a comment (e.g. both `@alpha` and `@beta`), #2056.
- Added support for JSDoc `@hideconstructor` tag.
This tag should only be used to work around TypeScript#58653, prefer the more general `@hidden`/`@ignore` tag to hide members normally, #2577.
- TypeDoc will now warn if a block tag is used which is not defined by the `--blockTags` option.
- Added three new sort strategies `documents-first`, `documents-last`, and `alphabetical-ignoring-documents` to order markdown documents.
- Added new `--alwaysCreateEntryPointModule` option. When set, TypeDoc will always create a `Module` for entry points, even if only one is provided.
Expand Down
24 changes: 24 additions & 0 deletions src/lib/converter/plugins/CommentPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,13 @@ export class CommentPlugin extends ConverterComponent {

mergeSeeTags(reflection.comment);
movePropertyTags(reflection.comment, reflection);

// Unlike other modifiers, this one has to wait until resolution to be removed
// as it needs to remain present so that it can be checked when `@hidden` tags are
// being processed.
if (reflection.kindOf(ReflectionKind.Class)) {
reflection.comment.removeModifier("@hideconstructor");
}
}

if (reflection instanceof DeclarationReflection && reflection.comment) {
Expand Down Expand Up @@ -540,6 +547,23 @@ export class CommentPlugin extends ConverterComponent {
return true;
}

if (
reflection.kindOf(
ReflectionKind.ConstructorSignature |
ReflectionKind.Constructor,
)
) {
if (comment?.hasModifier("@hideconstructor")) return true;
const cls = reflection.parent?.kindOf(ReflectionKind.Class)
? reflection.parent
: reflection.parent?.parent?.kindOf(ReflectionKind.Class)
? reflection.parent.parent
: undefined;
if (cls?.comment?.hasModifier("@hideconstructor")) {
return true;
}
}

if (!comment) {
// We haven't moved comments from the parent for signatures without a direct
// comment, so don't exclude those due to not being documented.
Expand Down
1 change: 1 addition & 0 deletions src/lib/utils/options/tsdoc-defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,5 @@ export const modifierTags = [
"@overload",
"@showCategories",
"@showGroups",
"@hideconstructor",
] as const;
8 changes: 8 additions & 0 deletions src/test/behavior.c2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,14 @@ describe("Behavior Tests", () => {
);
});

it("Handles @hideconstructor", () => {
const project = convert("hideconstructor");

ok(!project.getChildByName("StaticOnly.constructor"));
ok(!!project.getChildByName("StaticOnly.notHidden"));
ok(!project.getChildByName("IgnoredCtor.constructor"));
});

it("Handles simple @inheritDoc cases", () => {
const project = convert("inheritDocBasic");
const target = query(project, "InterfaceTarget");
Expand Down
4 changes: 2 additions & 2 deletions src/test/converter2/behavior/externalSymbols.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Token, ParseResult } from "markdown-it";
import { Token, ParseLinkTitleResult } from "markdown-it";

/**
* Testing custom external link resolution
Expand All @@ -7,4 +7,4 @@ import { Token, ParseResult } from "markdown-it";
export type P = Promise<string>;

export declare const T: Token;
export declare const Pr: ParseResult;
export declare const Pr: ParseLinkTitleResult;
14 changes: 14 additions & 0 deletions src/test/converter2/behavior/hideconstructor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// https://github.com/TypeStrong/typedoc/issues/2577

/** @hideconstructor */
export class StaticOnly {
static foo() {}

/** @hideconstructor */
notHidden = true;
}

export class IgnoredCtor {
/** @hideconstructor */
constructor() {}
}
4 changes: 4 additions & 0 deletions tsdoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@
{
"tagName": "@hideGroups",
"syntaxKind": "modifier"
},
{
"tagName": "@hideconstructor",
"syntaxKind": "modifier"
}
]
}

0 comments on commit c19db05

Please sign in to comment.