Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: revert Documentation.toJson() can handle nested submodules #1206

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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