ts_helpers.ts

TypeScript compiler API helpers for extracting metadata from source code.

All functions are prefixed with ts_ for clarity.

Declarations
#

15 declarations

view source

ModuleExportsAnalysis
#

ts_helpers.ts view source

ModuleExportsAnalysis

Result of analyzing a module's exports.

module_comment

Module-level documentation comment.

type string

declarations

All exported declarations with nodocs flags - consumer filters based on policy.

type Array<DeclarationAnalysis>

re_exports

Same-name re-exports (for building also_exported_from in post-processing).

type Array<ReExportInfo>

star_exports

Star exports (export * from './module') - module paths that are fully re-exported.

type Array<string>

ts_analyze_declaration
#

ts_helpers.ts view source

(symbol: Symbol, source_file: SourceFile, checker: TypeChecker, ctx: AnalysisContext): DeclarationAnalysis

Analyze a TypeScript symbol and extract rich metadata.

This is a high-level function that combines TSDoc parsing with TypeScript type analysis to produce complete declaration metadata. Suitable for use in documentation generators, IDE integrations, and other tooling.

symbol

The TypeScript symbol to analyze

type Symbol

source_file

The source file containing the symbol

type SourceFile

checker

The TypeScript type checker

type TypeChecker

ctx

Optional analysis context for collecting diagnostics

returns

DeclarationAnalysis

Complete declaration metadata including docs, types, and parameters, plus nodocs flag

ts_analyze_module
#

ts_helpers.ts view source

(source_file_info: SourceFileInfo, ts_source_file: SourceFile, module_path: string, checker: TypeChecker, options: ModuleSourceOptions, ctx: AnalysisContext): ModuleAnalysis

Analyze a TypeScript file and extract module metadata.

Wraps ts_analyze_module_exports and adds dependency information from the source file info if available.

This is a high-level function suitable for building documentation or library metadata. For lower-level analysis, use ts_analyze_module_exports directly.

source_file_info

The source file info (from Gro filer, file system, or other source)

ts_source_file

TypeScript source file from the program

type SourceFile

module_path

The module path (relative to source root)

type string

checker

TypeScript type checker

type TypeChecker

options

Module source options for path extraction

ctx

Analysis context for collecting diagnostics

returns

ModuleAnalysis

Module metadata and re-export information

ts_analyze_module_exports
#

ts_helpers.ts view source

(source_file: SourceFile, checker: TypeChecker, options: ModuleSourceOptions, ctx: AnalysisContext): ModuleExportsAnalysis

Analyze all exports from a TypeScript source file.

Extracts the module-level comment and all exported declarations with complete metadata. Handles re-exports by: - Same-name re-exports: tracked in re_exports for also_exported_from building - Renamed re-exports: included as new declarations with alias_of metadata - Star exports (export * from): tracked in star_exports for namespace-level info

This is a mid-level function (above ts_extract_*, below library_gen) suitable for building documentation, API explorers, or analysis tools. For standard SvelteKit library layouts, use module_create_source_options(process.cwd()).

source_file

The TypeScript source file to analyze

type SourceFile

checker

The TypeScript type checker

type TypeChecker

options

Module source options for path extraction in re-exports

ctx

Analysis context for collecting diagnostics

returns

ModuleExportsAnalysis

Module comment, declarations, re-exports, and star exports

ts_create_program
#

ts_helpers.ts view source

(options?: TsProgramOptions | undefined, log?: Logger | undefined): TsProgram

Create TypeScript program for analysis.

options?

Configuration options for program creation

type TsProgramOptions | undefined
optional

log?

Optional logger for info messages

type Logger | undefined
optional

returns

TsProgram

The program and type checker

throws

  • Error - if tsconfig.json is not found

ts_extract_class_info
#

ts_helpers.ts view source

(node: Node, _symbol: Symbol, checker: TypeChecker, declaration: { [x: string]: unknown; name: string; kind: "function" | "type" | "json" | "variable" | "class" | "constructor" | "component" | "css"; ... 19 more ...; alias_of?: { ...; } | undefined; }, ctx: AnalysisContext): void

Extract class information with rich member metadata.

node

type Node

_symbol

type Symbol

checker

type TypeChecker

declaration

type { [x: string]: unknown; name: string; kind: "function" | "type" | "json" | "variable" | "class" | "constructor" | "component" | "css"; doc_comment?: string | undefined; type_signature?: string | undefined; ... 17 more ...; alias_of?: { ...; } | undefined; }

ctx

returns

void

ts_extract_function_info
#

ts_helpers.ts view source

(node: Node, symbol: Symbol, checker: TypeChecker, declaration: { [x: string]: unknown; name: string; kind: "function" | "type" | "json" | "variable" | "class" | "constructor" | "component" | "css"; ... 19 more ...; alias_of?: { ...; } | undefined; }, tsdoc: TsdocParsedComment | undefined, ctx: AnalysisContext): void

Extract function/method information including parameters with descriptions and default values.

node

type Node

symbol

type Symbol

checker

type TypeChecker

declaration

type { [x: string]: unknown; name: string; kind: "function" | "type" | "json" | "variable" | "class" | "constructor" | "component" | "css"; doc_comment?: string | undefined; type_signature?: string | undefined; ... 17 more ...; alias_of?: { ...; } | undefined; }

tsdoc

type TsdocParsedComment | undefined

ctx

returns

void

ts_extract_module_comment
#

ts_helpers.ts view source

(source_file: SourceFile): string | undefined

Extract module-level comment.

Requires @module tag to identify module comments. The tag line is stripped from the output. Supports optional module renaming: @module custom-name.

source_file

type SourceFile

returns

string | undefined

see also

ts_extract_signature_parameters
#

ts_helpers.ts view source

(sig: Signature, checker: TypeChecker, tsdoc_params: Map<string, string> | undefined): { name: string; type: string; optional?: boolean | undefined; description?: string | undefined; default_value?: string | undefined; }[]

Extract parameters from a TypeScript signature with TSDoc descriptions and default values.

Shared helper for extracting parameter information from both standalone functions and class methods/constructors.

sig

The TypeScript signature to extract parameters from

type Signature

checker

TypeScript type checker for type resolution

type TypeChecker

tsdoc_params

Map of parameter names to TSDoc descriptions (from tsdoc.params)

type Map<string, string> | undefined

returns

{ name: string; type: string; optional?: boolean | undefined; description?: string | undefined; default_value?: string | undefined; }[]

Array of parameter info objects

ts_extract_type_info
#

ts_helpers.ts view source

(node: Node, _symbol: Symbol, checker: TypeChecker, declaration: { [x: string]: unknown; name: string; kind: "function" | "type" | "json" | "variable" | "class" | "constructor" | "component" | "css"; ... 19 more ...; alias_of?: { ...; } | undefined; }, ctx: AnalysisContext): void

Extract type/interface information with rich property metadata.

node

type Node

_symbol

type Symbol

checker

type TypeChecker

declaration

type { [x: string]: unknown; name: string; kind: "function" | "type" | "json" | "variable" | "class" | "constructor" | "component" | "css"; doc_comment?: string | undefined; type_signature?: string | undefined; ... 17 more ...; alias_of?: { ...; } | undefined; }

ctx

returns

void

ts_extract_variable_info
#

ts_helpers.ts view source

(node: Node, symbol: Symbol, checker: TypeChecker, declaration: { [x: string]: unknown; name: string; kind: "function" | "type" | "json" | "variable" | "class" | "constructor" | "component" | "css"; ... 19 more ...; alias_of?: { ...; } | undefined; }, ctx: AnalysisContext): void

Extract variable information.

node

type Node

symbol

type Symbol

checker

type TypeChecker

declaration

type { [x: string]: unknown; name: string; kind: "function" | "type" | "json" | "variable" | "class" | "constructor" | "component" | "css"; doc_comment?: string | undefined; type_signature?: string | undefined; ... 17 more ...; alias_of?: { ...; } | undefined; }

ctx

returns

void

ts_infer_declaration_kind
#

ts_helpers.ts view source

(symbol: Symbol, node: Node): "function" | "type" | "json" | "variable" | "class" | "constructor" | "component" | "css"

Infer declaration kind from symbol and node.

Maps TypeScript constructs to DeclarationKind: - Classes → 'class' - Functions (declarations, expressions, arrows) → 'function' - Interfaces, type aliases → 'type' - Enums (regular and const) → 'type' - Variables → 'variable' (unless function-valued → 'function')

symbol

type Symbol

node

type Node

returns

"function" | "type" | "json" | "variable" | "class" | "constructor" | "component" | "css"

TsModifier
#

ts_helpers.ts view source

TsModifier

TypeScript modifier keywords extracted from declarations.

These are the access modifiers and other keywords that can appear on class members, interface properties, etc.

TsProgram
#

ts_helpers.ts view source

TsProgram

Result of creating a TypeScript program.

program

type ts.Program

checker

type ts.TypeChecker

TsProgramOptions
#

ts_helpers.ts view source

TsProgramOptions

Options for creating a TypeScript program.

root

Project root directory.

type string

tsconfig

Path to tsconfig.json (relative to root).

type string

compiler_options

Override compiler options.

type ts.CompilerOptions

Depends on
#

Imported by
#