From 1489ad2393564f7f9153826bd01335feb3adfcef Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Thu, 2 May 2024 20:05:36 +0200 Subject: [PATCH] Fix ir.ts handling of missing attributes (#130) We can't use a ? unless we fix things on the Python side because `undefined` turns into an entirely missing entry. If we want to turn it into `None` we need to either put a `null` in javascript or set `None` as the default value in `ir.py`. I removed a lot of the `?`'s because we don't use them, but qualifiedName and sourcefilename do sometimes seem to go missing right now. Maybe we can fix that later. --- sphinx_js/ir.py | 4 ++-- sphinx_js/js/ir.ts | 12 ++++++------ sphinx_js/js/renderType.ts | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/sphinx_js/ir.py b/sphinx_js/ir.py index 6ee60fbf..8f0a70e0 100644 --- a/sphinx_js/ir.py +++ b/sphinx_js/ir.py @@ -52,8 +52,8 @@ class TypeXRefExternal: name: str package: str # TODO: use snake case for these like for everything else - sourcefilename: str - qualifiedName: str + sourcefilename: str | None + qualifiedName: str | None type: Literal["external"] = "external" diff --git a/sphinx_js/js/ir.ts b/sphinx_js/js/ir.ts index 061f7b07..bb4f29c1 100644 --- a/sphinx_js/js/ir.ts +++ b/sphinx_js/js/ir.ts @@ -22,8 +22,8 @@ export type TypeXRefInternal = { export type TypeXRefExternal = { name: string; package: string; - sourcefilename: string | undefined; - qualifiedName: string | undefined; + sourcefilename: string | null; + qualifiedName: string | null; type: "external"; }; @@ -75,7 +75,7 @@ export type Param = { is_variadic: boolean; has_default: boolean; default: string | NoDefault; - type?: Type; + type: Type; }; export type Return = { @@ -85,7 +85,7 @@ export type Return = { export type Module = { filename: string; - deppath?: string; + deppath: string; path: Pathname; line: number; attributes: TopLevel[]; @@ -97,7 +97,7 @@ export type TopLevel = { name: string; path: Pathname; filename: string; - deppath?: string; + deppath: string; description: Description; modifier_tags: string[]; block_tags: { [key: string]: Description[] }; @@ -106,7 +106,7 @@ export type TopLevel = { examples: Description[]; see_alsos: string[]; properties: Attribute[]; - exported_from?: Pathname; + exported_from: Pathname | null; documentation_root: boolean; }; diff --git a/sphinx_js/js/renderType.ts b/sphinx_js/js/renderType.ts index 6baf6a6b..907bc8e8 100644 --- a/sphinx_js/js/renderType.ts +++ b/sphinx_js/js/renderType.ts @@ -167,8 +167,8 @@ class TypeRenderer implements TypeVisitor { const res: TypeXRefExternal = { name: type.name, package: type.package, - qualifiedName: fileInfo?.qualifiedName, - sourcefilename: fileInfo?.sourceFileName, + qualifiedName: fileInfo?.qualifiedName || null, + sourcefilename: fileInfo?.sourceFileName || null, type: "external", }; return this.addTypeParams(type, [res]);