svelte_helpers.ts

Svelte component analysis helpers.

Extracts metadata from Svelte components using svelte2tsx transformations:

- Component props with types and JSDoc - Component-level documentation - Type information

Workflow: Transform Svelte to TypeScript via svelte2tsx, parse the transformed TypeScript with the TS Compiler API, extract component-level JSDoc from original source.

Svelte 5 only: The svelte2tsx output format changed significantly between versions. This module requires Svelte 5+ and will throw a clear error if an older version is detected. There is no Svelte 4 compatibility layer.

All functions are prefixed with svelte_ for clarity.

Declarations
#

6 declarations

view source

svelte_analyze_component
#

svelte_helpers.ts view source

(ts_code: string, source_file: SourceFile, checker: TypeChecker, component_name: string, file_path: string, source_map: TraceMap | null, ctx: AnalysisContext): { ...; }

Analyze a Svelte component from its svelte2tsx transformation.

ts_code

type string

source_file

type SourceFile

checker

type TypeChecker

component_name

type string

file_path

type string

source_map

type TraceMap | null

ctx

returns

{ [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; }

svelte_analyze_file
#

svelte_helpers.ts view source

(source_file: SourceFileInfo, module_path: string, checker: TypeChecker, ctx: AnalysisContext): SvelteFileAnalysis

Analyze a Svelte component file.

This is a high-level function that handles the complete workflow: 1. Transform Svelte source to TypeScript via svelte2tsx 2. Extract component metadata (props, documentation) 3. Extract module-level documentation

Suitable for use in documentation generators, build tools, and analysis.

source_file

Source file info with path and content

module_path

Module path relative to source root (e.g., 'Alert.svelte')

type string

checker

TypeScript type checker for type resolution

type TypeChecker

ctx

Analysis context for collecting diagnostics

returns

SvelteFileAnalysis

Component declaration and optional module-level comment

svelte_analyze_module
#

svelte_helpers.ts view source

(source_file: SourceFileInfo, module_path: string, checker: TypeChecker, options: ModuleSourceOptions, ctx: AnalysisContext): ModuleAnalysis

Analyze a Svelte component file and extract module metadata.

Wraps svelte_analyze_file 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 svelte_analyze_file directly.

Returns raw analysis data matching ModuleAnalysis structure. Consumer decides filtering policy (Svelte components are never nodocs).

source_file

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

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 analysis matching ModuleAnalysis structure

svelte_extract_module_comment
#

svelte_helpers.ts view source

(script_content: string): string | undefined

Extract module-level comment from Svelte script content.

Requires @module tag to identify module comments. The tag line is stripped from the output.

script_content

- The content of the <script> tag.

type string

returns

string | undefined

The cleaned module comment text, or undefined if none found.

svelte_extract_script_content
#

svelte_helpers.ts view source

(svelte_source: string): string | undefined

Extract the content of the main <script> tag from Svelte source.

Matches <script> or <script lang="ts"> but not <script module>. Returns undefined if no matching script tag is found.

svelte_source

type string

returns

string | undefined

SvelteFileAnalysis
#

svelte_helpers.ts view source

SvelteFileAnalysis

Result of analyzing a Svelte file.

declaration

The component declaration metadata.

type DeclarationJson

module_comment

Module-level documentation comment, if present.

type string

Depends on
#

Imported by
#