Skip to content

Commit

Permalink
Revert "feat: Documentation.toJson() can handle nested submodules (#1190
Browse files Browse the repository at this point in the history
)"

This reverts commit 9036833.
  • Loading branch information
comcalvi authored Nov 15, 2023
1 parent a9a96f8 commit 478c144
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6,753 deletions.
29 changes: 11 additions & 18 deletions src/docgen/view/documentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,29 +312,22 @@ export class Documentation {
}

/**
* Lookup a submodule by a submodule name. To look up a nested submodule, encode it as a
* dot-separated path, e.g., 'top-level-module.nested-module.another-nested-one'.
* Lookup a submodule by a submodule name.
*/
private findSubmodule(assembly: reflect.Assembly, submodule: string): reflect.Submodule {
type ReflectSubmodules = typeof assembly.submodules;
return recurse(submodule.split('.'), assembly.submodules);
const submodules = assembly.submodules.filter(
(s) => s.name === submodule,
);

function recurse(names: string[], submodules: ReflectSubmodules): reflect.Submodule {
const [head, ...tail] = names;
const found = submodules.filter(
(s) => s.name === head,
);

if (found.length === 0) {
throw new Error(`Submodule ${submodule} not found in assembly ${assembly.name}@${assembly.version}`);
}

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

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

return submodules[0];
}

private async createAssembly(
Expand Down
Loading

0 comments on commit 478c144

Please sign in to comment.