@jsdocs-io/extractor
Version:
The API extractor for npm packages powering jsdocs.io
27 lines (26 loc) • 1 kB
JavaScript
import { SyntaxKind } from "ts-morph";
import { formatSignature } from "./format-signature.js";
import { id } from "./id.js";
import { sourceFilePath } from "./source-file-path.js";
export async function extractFileModule(containerName, exportName, declaration, declarations) {
return {
kind: "namespace",
id: id(containerName, "+namespace", exportName),
name: exportName,
docs: fileModuleDocs(declaration),
file: sourceFilePath(declaration),
line: declaration.getStartLineNumber(),
signature: await fileModuleSignature(declaration),
declarations,
};
}
function fileModuleDocs(declaration) {
const firstDoc = declaration.getFirstDescendantByKind(SyntaxKind.JSDoc)?.getText();
if (!firstDoc)
return [];
return [firstDoc];
}
async function fileModuleSignature(declaration) {
const filename = declaration.getSourceFile().getBaseName();
return await formatSignature("namespace", `module "${filename}" {}`);
}