TSDoc/JSDoc parsing helpers using the TypeScript compiler API.
Provides parseComment for extracting JSDoc/TSDoc from TypeScript nodes.
Primarily designed for build-time code generation but can be used at runtime.
Design
Pure extraction approach: extracts documentation as-is with minimal transformation,
preserving source intent. Works around TypeScript compiler API quirks where needed.
Supports both regular TypeScript and Svelte components (via svelte2tsx output).
Tag support
Supports the common JSDoc/TSDoc doc tags as used across the TypeScript ecosystem:
@param, @returns, @throws, @example, @deprecated, @internal, @see,
@since, @default, @nodocs.
Where the two standards spell a tag differently, both spellings are accepted:
@return (JSDoc synonym) parses like @returns, and @defaultValue (the TSDoc
spelling, plus JSDoc's lowercase @defaultvalue synonym) parses like @default.
@internal is a marker, not an exclusion: it means "not stable public API"
and lands as internalMessage (with any trailing prose; empty string for a
bare tag) while the declaration stays documented. Use @nodocs to exclude
a declaration from output entirely.
The @nodocs tag excludes exports from documentation and flat namespace validation.
The declaration is still exported and usable, just not documented.
Also supports @mutates (non-standard) for documenting mutations to parameters or external state.
Uses same format as @param: @mutates key - description of mutation. The key is
unvalidated — typically a parameter name, but compound paths (this.foo, obj.field)
and external state references are accepted as-is.
The @see tag supports multiple formats: plain URLs (https://...), {@link} syntax, and module names.
Relative/absolute path support in @see is TBD.
Behavioral notes
JSDoc blocks tagged @module are excluded from parseComment entirely (text
and tags) — module comments attach to the file's first statement in the AST
and are owned by extractModuleComment instead.
JSDocPropertyLikeTag nodes (@property/@param declaring a symbol in a
typedef or callback) parse to their own tag description — the only doc such
a declaration can carry.
Due to TS Compiler API limitations:
- TS API includes dash separator in
@param tag text; we strip the leading - as it's syntax, not content @throws tags have {Type} stripped by TS API; fallback regex extracts first word as error type- TS API strips URL protocols from
@see tag text; we use getText() to preserve original format including {@link} syntax
@see declaration-build.ts for DeclarationJsonBuild
@see typescript-exports.ts and svelte.ts as primary consumers