Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add @hidetype tag to suppress the type of a property #134

Merged
merged 1 commit into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion sphinx_js/js/call_typedoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ const ExitCodes = {

async function bootstrapAppTypedoc0_25(args: string[]): Promise<Application> {
return await Application.bootstrapWithPlugins(
{ plugin: [fileURLToPath(import.meta.resolve("./typedocPlugin.ts"))] },
{
plugin: [fileURLToPath(import.meta.resolve("./typedocPlugin.ts"))],
},
[
new ArgumentsReader(0, args),
new TypeDocReader(),
Expand Down Expand Up @@ -53,6 +55,7 @@ async function main() {
console.log(app.toString());
return ExitCodes.Ok;
}
app.options.getValue("modifierTags").push("@hidetype");
const config = await loadConfig(app.options.getValue("sphinxJsConfig"));
const symbolToType = redirectPrivateTypes(app);

Expand Down
20 changes: 16 additions & 4 deletions sphinx_js/js/convertTopLevel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,12 @@ export class Converter {
if (!v.type) {
throw new Error(`Type of ${v.name} is undefined`);
}
const type = this.renderType(v.type);
let type: Type;
if (v.comment?.modifierTags.has("@hidetype")) {
type = [];
} else {
type = this.renderType(v.type);
}
const result: Attribute = {
...this.memberProps(v),
...this.topLevelProperties(v),
Expand Down Expand Up @@ -517,9 +522,17 @@ export class Converter {
// way to pick?
return [this.functionToIR(prop.type.declaration), []];
}
let type: Type;
if (prop.comment?.modifierTags.has("@hidetype")) {
// We should probably also be able to hide the type of a thing with a
// function type literal type...
type = [];
} else {
type = this.renderType(prop.type!);
}
// TODO: add a readonly indicator if it's readonly
const result: Attribute = {
type: this.renderType(prop.type!),
type,
...this.memberProps(prop),
...this.topLevelProperties(prop),
description: renderCommentSummary(prop.comment),
Expand Down Expand Up @@ -651,7 +664,7 @@ export class Converter {
deppath: filePath.join(""),
filename: "",
description: renderCommentSummary(refl.comment),
modifier_tags: [],
modifier_tags: Array.from(refl.comment?.modifierTags || []),
block_tags,
deprecated,
examples: block_tags["example"] || [],
Expand All @@ -660,7 +673,6 @@ export class Converter {
exported_from: filePath,
line: refl.sources?.[0].line || null,
documentation_root: false,
// modifier_tags: self.comment.modifierTags,
};
}

Expand Down
14 changes: 14 additions & 0 deletions tests/test_typedoc_analysis/source/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,17 @@ export type PrivateTypeAlias2 = { a: number; b: string };

// Should expand the private type alias
export let typeIsPrivateTypeAlias2: PrivateTypeAlias2;

/**
* Some comment
* @hidetype
*/
export let hiddenType: number;

export class HasHiddenTypeMember {
/**
* Some comment
* @hidetype
*/
hasHiddenType: number;
}
9 changes: 9 additions & 0 deletions tests/test_typedoc_analysis/test_typedoc_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,3 +635,12 @@ def test_private_type_alias1(self):
def test_private_type_alias2(self):
obj = self.analyzer.get_object(["typeIsPrivateTypeAlias2"])
assert join_type(obj.type) == "{ a: number; b: string; }"

def test_hidden_type_top_level(self):
obj = self.analyzer.get_object(["hiddenType"])
assert obj.modifier_tags == ["@hidetype"]
assert obj.type == []

def test_hidden_type_member(self):
obj = self.analyzer.get_object(["HasHiddenTypeMember"])
assert obj.members[0].type == []
Loading