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 a subset of standard TSDoc tags:
@param, @returns, @throws, @example, @deprecated, @see, @since, @default, @nodocs.
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.
Only @returns is supported (not @return).
The @see tag supports multiple formats: plain URLs (https://...), {@link} syntax, and module names.
Relative/absolute path support in @see is TBD.
Behavioral notes
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