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 support for @deprecated tag #63

Merged
merged 2 commits into from
Sep 25, 2023
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/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,13 +381,16 @@ class AutoFunctionRenderer(JsRenderer):
_renderer_type = "function"

def _template_vars(self, name: str, obj: Function) -> dict[str, Any]: # type: ignore[override]
deprecated = obj.deprecated
if not isinstance(deprecated, bool):
deprecated = self.render_description(deprecated)
return dict(
name=name,
params=self._formal_params(obj),
fields=self._fields(obj),
description=self.render_description(obj.description),
examples=obj.examples,
deprecated=obj.deprecated,
deprecated=deprecated,
is_optional=obj.is_optional,
is_static=obj.is_static,
see_also=obj.see_alsos,
Expand Down
19 changes: 14 additions & 5 deletions sphinx_js/typedoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,15 @@ def __init__(self, *args: Any, **kwargs: Any):
def get_description(self) -> Sequence[ir.DescriptionItem]:
return description_to_ir(self.summary)

def get_returns(self) -> Sequence[ir.DescriptionItem]:
return description_to_ir(next(iter(self.tags["returns"]), []))
def get_tag_list(self, tag: str) -> list[Sequence[ir.DescriptionItem]]:
return [description_to_ir(t) for t in self.tags[tag]]

def get_tag_one(self, tag: str) -> Sequence[ir.DescriptionItem]:
l = self.tags[tag]
if not l:
return []
assert len(l) == 1
return description_to_ir(l[0])


class Flags(BaseModel):
Expand Down Expand Up @@ -368,7 +375,7 @@ class TopLevelPropertiesDict(TypedDict):
deppath: str | None
description: Sequence[ir.DescriptionItem]
line: int | None
deprecated: bool
deprecated: Sequence[ir.DescriptionItem] | bool
examples: list[str]
see_alsos: list[str]
properties: list[ir.Attribute]
Expand All @@ -385,6 +392,8 @@ def short_name(self) -> str:
return self.name

def _top_level_properties(self) -> TopLevelPropertiesDict:
deprecated: Sequence[ir.DescriptionItem] | bool
deprecated = self.comment.get_tag_one("deprecated") or False
return dict(
name=self.short_name(),
path=ir.Pathname(self.path),
Expand All @@ -393,7 +402,7 @@ def _top_level_properties(self) -> TopLevelPropertiesDict:
description=self.comment.get_description(),
line=self.sources[0].line if self.sources else None,
# These properties aren't supported by TypeDoc:
deprecated=False,
deprecated=deprecated,
examples=[],
see_alsos=[],
properties=[],
Expand Down Expand Up @@ -775,7 +784,7 @@ def return_type(self, converter: Converter) -> list[ir.Return]:
return [
ir.Return(
type=self.type.render_name(converter),
description=self.comment.get_returns(),
description=self.comment.get_tag_one("returns"),
)
]

Expand Down
8 changes: 7 additions & 1 deletion tests/test_build_ts/source/class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,10 @@ export function thunk(b : typeof blah) {
* A problematic self referential function
* @param b troublemaker
*/
export function quik(b: typeof quik) {}
export function selfReferential(b: typeof selfReferential) {}


/**
* @deprecated since v20!
*/
export function deprecatedFunction() {}
1 change: 1 addition & 0 deletions tests/test_build_ts/source/docs/deprecated.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.. js:autofunction:: deprecatedFunction
16 changes: 16 additions & 0 deletions tests/test_build_ts/test_build_ts.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from textwrap import dedent

from bs4 import BeautifulSoup
from conftest import TYPEDOC_VERSION

Expand Down Expand Up @@ -104,6 +106,20 @@ def test_optional_members(self):
" OptionalThings.foop?()\n",
)

def test_deprecated(self):
self._file_contents_eq(
"deprecated",
dedent(
"""\
deprecatedFunction()

Note:

Deprecated: since v20!
"""
),
)


class HtmlBuilderTests(SphinxBuildTestCase):
"""Tests which require an HTML build of our Sphinx tree, for checking
Expand Down
Loading