Skip to content

Commit 9289146

Browse files
committed
Add support for @hideconstructor
Resolves #2557
1 parent 4f23063 commit 9289146

File tree

7 files changed

+55
-2
lines changed

7 files changed

+55
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
- New option, `--customFooterHtml` to add custom HTML to the generated page footer, #2559.
4646
- TypeDoc will now copy modifier tags to children if specified in the `--cascadedModifierTags` option, #2056.
4747
- TypeDoc will now warn if mutually exclusive modifier tags are specified for a comment (e.g. both `@alpha` and `@beta`), #2056.
48+
- Added support for JSDoc `@hideconstructor` tag.
49+
This tag should only be used to work around TypeScript#58653, prefer the more general `@hidden`/`@ignore` tag to hide members normally, #2577.
4850
- TypeDoc will now warn if a block tag is used which is not defined by the `--blockTags` option.
4951
- Added three new sort strategies `documents-first`, `documents-last`, and `alphabetical-ignoring-documents` to order markdown documents.
5052
- Added new `--alwaysCreateEntryPointModule` option. When set, TypeDoc will always create a `Module` for entry points, even if only one is provided.

src/lib/converter/plugins/CommentPlugin.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,13 @@ export class CommentPlugin extends ConverterComponent {
393393

394394
mergeSeeTags(reflection.comment);
395395
movePropertyTags(reflection.comment, reflection);
396+
397+
// Unlike other modifiers, this one has to wait until resolution to be removed
398+
// as it needs to remain present so that it can be checked when `@hidden` tags are
399+
// being processed.
400+
if (reflection.kindOf(ReflectionKind.Class)) {
401+
reflection.comment.removeModifier("@hideconstructor");
402+
}
396403
}
397404

398405
if (reflection instanceof DeclarationReflection && reflection.comment) {
@@ -540,6 +547,23 @@ export class CommentPlugin extends ConverterComponent {
540547
return true;
541548
}
542549

550+
if (
551+
reflection.kindOf(
552+
ReflectionKind.ConstructorSignature |
553+
ReflectionKind.Constructor,
554+
)
555+
) {
556+
if (comment?.hasModifier("@hideconstructor")) return true;
557+
const cls = reflection.parent?.kindOf(ReflectionKind.Class)
558+
? reflection.parent
559+
: reflection.parent?.parent?.kindOf(ReflectionKind.Class)
560+
? reflection.parent.parent
561+
: undefined;
562+
if (cls?.comment?.hasModifier("@hideconstructor")) {
563+
return true;
564+
}
565+
}
566+
543567
if (!comment) {
544568
// We haven't moved comments from the parent for signatures without a direct
545569
// comment, so don't exclude those due to not being documented.

src/lib/utils/options/tsdoc-defaults.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,5 @@ export const modifierTags = [
7070
"@overload",
7171
"@showCategories",
7272
"@showGroups",
73+
"@hideconstructor",
7374
] as const;

src/test/behavior.c2.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,14 @@ describe("Behavior Tests", () => {
580580
);
581581
});
582582

583+
it("Handles @hideconstructor", () => {
584+
const project = convert("hideconstructor");
585+
586+
ok(!project.getChildByName("StaticOnly.constructor"));
587+
ok(!!project.getChildByName("StaticOnly.notHidden"));
588+
ok(!project.getChildByName("IgnoredCtor.constructor"));
589+
});
590+
583591
it("Handles simple @inheritDoc cases", () => {
584592
const project = convert("inheritDocBasic");
585593
const target = query(project, "InterfaceTarget");
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Token, ParseResult } from "markdown-it";
1+
import { Token, ParseLinkTitleResult } from "markdown-it";
22

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

99
export declare const T: Token;
10-
export declare const Pr: ParseResult;
10+
export declare const Pr: ParseLinkTitleResult;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// https://github.com/TypeStrong/typedoc/issues/2577
2+
3+
/** @hideconstructor */
4+
export class StaticOnly {
5+
static foo() {}
6+
7+
/** @hideconstructor */
8+
notHidden = true;
9+
}
10+
11+
export class IgnoredCtor {
12+
/** @hideconstructor */
13+
constructor() {}
14+
}

tsdoc.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@
142142
{
143143
"tagName": "@hideGroups",
144144
"syntaxKind": "modifier"
145+
},
146+
{
147+
"tagName": "@hideconstructor",
148+
"syntaxKind": "modifier"
145149
}
146150
]
147151
}

0 commit comments

Comments
 (0)