Skip to content

Commit

Permalink
feat: Documentation.toJson() can handle nested submodules
Browse files Browse the repository at this point in the history
  • Loading branch information
otaviomacedo committed Nov 2, 2023
1 parent e278bc5 commit fb07563
Show file tree
Hide file tree
Showing 5 changed files with 7,936 additions and 979 deletions.
26 changes: 16 additions & 10 deletions src/docgen/view/documentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,19 +315,25 @@ export class Documentation {
* Lookup a submodule by a submodule name.
*/
private findSubmodule(assembly: reflect.Assembly, submodule: string): reflect.Submodule {
const submodules = assembly.submodules.filter(
(s) => s.name === submodule,
);
type ReflectSubmodules = typeof assembly.submodules;
return recurse(submodule.split('.'), assembly.submodules);

if (submodules.length === 0) {
throw new Error(`Submodule ${submodule} not found in assembly ${assembly.name}@${assembly.version}`);
}
function recurse(names: string[], submodules: ReflectSubmodules): reflect.Submodule {
const [head, ...tail] = names;
const found = submodules.filter(
(s) => s.name === head,
);

if (submodules.length > 1) {
throw new Error(`Found multiple submodules with name: ${submodule} in assembly ${assembly.name}@${assembly.version}`);
}
if (found.length === 0) {
throw new Error(`Submodule ${submodule} not found in assembly ${assembly.name}@${assembly.version}`);
}

return submodules[0];
if (found.length > 1) {
throw new Error(`Found multiple submodules with name: ${submodule} in assembly ${assembly.name}@${assembly.version}`);
}

return tail.length === 0 ? found[0] : recurse(tail, found[0].submodules);
}
}

private async createAssembly(
Expand Down
Loading

0 comments on commit fb07563

Please sign in to comment.