From f712c80f63a4336f71cd94166114e69835df5e55 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Sat, 23 Sep 2023 20:01:53 -0700 Subject: [PATCH] Handle self referential function types without crashing It still doesn't work well but at least it doesn't crash the whole program. --- sphinx_js/typedoc.py | 15 ++++++++++++++- tests/test_build_ts/source/class.ts | 6 ++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/sphinx_js/typedoc.py b/sphinx_js/typedoc.py index 1a1b658d..e134107f 100644 --- a/sphinx_js/typedoc.py +++ b/sphinx_js/typedoc.py @@ -869,7 +869,11 @@ def inner(param: Param) -> Iterator[str | ir.TypeXRef]: yield from riffle((inner(param) for param in self.parameters), ", ") yield "): " - ret = self.return_type(converter)[0].type + return_type = self.return_type(converter) + if return_type: + ret = return_type[0].type + else: + ret = "void" assert ret if isinstance(ret, str): yield ret @@ -1062,6 +1066,14 @@ def _render_name_root(self, converter: Converter) -> Iterator[str | ir.TypeXRef] yield "" +class UnknownType(TypeBase): + type: Literal["unknown"] + name: str + + def _render_name_root(self, converter: Converter) -> Iterator[str | ir.TypeXRef]: + yield self.name + + AnyNode = Node | Project | Signature @@ -1075,6 +1087,7 @@ def _render_name_root(self, converter: Converter) -> Iterator[str | ir.TypeXRef] | ReferenceType | ReflectionType | TupleType + | UnknownType ) TypeD = Annotated[Type, Field(discriminator="type")] diff --git a/tests/test_build_ts/source/class.ts b/tests/test_build_ts/source/class.ts index 0a7962ce..966ec882 100644 --- a/tests/test_build_ts/source/class.ts +++ b/tests/test_build_ts/source/class.ts @@ -66,3 +66,9 @@ export function blah(a: OptionalThings) : ConstructorlessClass { export function thunk(b : typeof blah) { } + +/** + * A problematic self referential function + * @param b troublemaker + */ +export function quik(b: typeof quik) {}