zenadoc 0.0.2-preview.1
Extracts a Zena package's public API as JSON
zenadoc#
Extracts a Zena package's public API from source and serializes it as JSON: every module the package exports, the declarations in each, their members, signatures, resolved type links, and doc comments.
Usage#
Command Line#
zena doc ./my-package -o api.json # a package with zena-package.json
zena doc ./src # any directory, to stdout
zena doc main.zena # a single file
Library API#
import { documentPackage, DocumentOptions } from 'zenadoc';
import { loadPackage } from 'zenadoc/package';
import { packageToJson } from 'zenadoc/json';
let pkg = await loadPackage('./my-package');
let result = await documentPackage(pkg, new DocumentOptions());
let json = packageToJson(result.docs);
Libraries#
zenadoc/zenadoc/document— compiles and documents a package (documentPackage,DocumentOptions,DocumentResult)zenadoc/package— discovers a package's exported modules fromzena-package.jsonor the filesystem (loadPackage,Package,ModuleSpec)zenadoc/model— API documentation model (DocPackage,DocModule,DocDeclaration,DocMember,TypeRef,TypeLink,DeclarationKind,MemberKind)zenadoc/json— serializes aDocPackageto JSON (packageToJson)zenadoc/extract— walks a parsedModuleAST into aDocModule(extractModule,ExtractOptions)zenadoc/reexports— follows re-exported declarations across modules (resolveReexports,WalkCache)zenadoc/inherit— copies inherited members from supertypes (inheritMembers)zenadoc/links— resolves type references to declaration targets via scope analysis (linkModule,ScopeIndex)zenadoc/publish— rewrites declaration links to their public hosting module (publishLinks)zenadoc/type-text— renders type annotations to text and records declaration spans (renderTypeAnnotation)zenadoc/ids— formats module and declaration anchor IDs (moduleId,anchorFor)
License#
MIT
1.1 KiB
Raw
/**
* Naming a file inside a package.
*
* Stdlib files already carry a `zena:` id. Every other package resolves
* to filesystem paths, and a path is not something a reader or a link
* can use, so a path under the package root is rewritten to the
* specifier an import would use, `<package>/<path>`.
*/
export final class Naming {
#prefix: String;
#root: String;
new(name: String, root: String) : #prefix = modulePrefix(name), #root = root;
idOf(canonical: String): String {
if (canonical.startsWith(this.#prefix)) {
return canonical;
}
let prefix = this.#root + '/';
if (canonical.startsWith(prefix)) {
return this.#prefix + canonical.sliceBytes(prefix.length, canonical.length);
}
return canonical;
}
}
/**
* The specifier that imports `module` of the package `name`:
* `zena:<module>` in the standard library, `<name>/<module>` in any other
* package (docs/design/import-names.md).
*/
export function moduleId(name: String, module: String): String {
return `${modulePrefix(name)}${module}`;
}
function modulePrefix(name: String): String {
return if (name == 'zena') 'zena:' else `${name}/`;
}
- compiler compiler.zena-lang.pkg.zena-lang.dev 0.0.2-preview.1
| Version | Published | Dependencies | Approved by |
|---|---|---|---|
| 0.0.2-preview.1 | 2026-11-19 |
|
|