Skip to content

Commit

Permalink
Handle self referential function types without crashing
Browse files Browse the repository at this point in the history
It still doesn't work well but at least it doesn't crash the whole program.
  • Loading branch information
hoodmane committed Sep 24, 2023
1 parent 19cec98 commit f712c80
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
15 changes: 14 additions & 1 deletion sphinx_js/typedoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1062,6 +1066,14 @@ def _render_name_root(self, converter: Converter) -> Iterator[str | ir.TypeXRef]
yield "<TODO: not implemented>"


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


Expand All @@ -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")]
Expand Down
6 changes: 6 additions & 0 deletions tests/test_build_ts/source/class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}

0 comments on commit f712c80

Please sign in to comment.