source.ts

Source file shapes (SourceFileInfo, AnalyzerType), extension predicates, and svelte2tsx virtual-path and generated-name helpers. No configuration dependency; the building blocks under source-config.ts.

see also

view source

Declarations
#

15 declarations

AnalyzerType
#

source.ts view source

also exported from index.ts

AnalyzerType

type "typescript" | "svelte" | "css" | "json"

import type {AnalyzerType} from 'svelte-docinfo/source.js';

Analyzer type for source files.

  • 'typescript' — TypeScript/JS files analyzed via TypeScript compiler API
  • 'svelte' — Svelte components analyzed via svelte2tsx + TypeScript compiler API
  • 'css' — CSS files included as modules with no declarations
  • 'json' — JSON files included as modules with no declarations

getComponentName
#

source.ts view source

(modulePath: string): string import {getComponentName} from 'svelte-docinfo/source.js';

Extract component name from a Svelte module path.

modulePath

type string

returns

string

examples

getComponentName('Alert.svelte') // => 'Alert' getComponentName('components/Button.svelte') // => 'Button'

getDefaultAnalyzer
#

source.ts view source

also exported from index.ts

(path: string): AnalyzerType | null import {getDefaultAnalyzer} from 'svelte-docinfo/source.js';

Default analyzer resolver based on file extension.

  • .svelte → 'svelte'
  • .ts, .mts, .tsx (not .d.ts/.d.mts), .js, .mjs, .jsx → 'typescript'
  • .css → 'css'
  • .json → 'json'
  • Other extensions → null (skip)

path

type string

returns

AnalyzerType | null

isCss
#

source.ts view source

(path: string): boolean import {isCss} from 'svelte-docinfo/source.js';

Check if a path is a CSS file.

path

type string

returns

boolean

isJson
#

source.ts view source

(path: string): boolean import {isJson} from 'svelte-docinfo/source.js';

Check if a path is a JSON file.

path

type string

returns

boolean

isSvelte
#

source.ts view source

(path: string): boolean import {isSvelte} from 'svelte-docinfo/source.js';

Check if a path is a Svelte component file.

path

type string

returns

boolean

isSvelte2tsxGeneratedExport
#

source.ts view source

(name: string): boolean import {isSvelte2tsxGeneratedExport} from 'svelte-docinfo/source.js';

Whether an export name from a svelte2tsx virtual is generated machinery rather than an author declaration: the default slot (svelte2tsx's own component export — the component declaration is synthesized separately) plus every isSvelte2tsxInternal shape. The one rule shared by the Svelte export filter (analyzeSvelteModule), the alias-registry pre-pass skip, and warnAliasLost's virtual guard — only meaningful for names read off a virtual's export table (a plain TS module's default export is real).

name

type string

returns

boolean

isSvelte2tsxInternal
#

source.ts view source

(name: string): boolean import {isSvelte2tsxInternal} from 'svelte-docinfo/source.js';

Whether a symbol name is an internal svelte2tsx identifier — a generated name that never documents as a declaration: $$ComponentProps, $$render, __sveltets_Render, and the synthesized component class/type alias <ComponentName>__SvelteComponent_. Building block for isSvelte2tsxGeneratedExport, which adds the default slot.

Beyond export filtering, the TypeJson builder treats an alias with one of these names declared in a Svelte virtual or svelte2tsx's shims as no alias at all (linkableAliasSymbol in typescript-extract-type-json.ts), so $$ComponentProps and __sveltets_2_PropsWithChildren never reach a tree and don't mask a project alias over them. Flat type strings are the checker's rendering and still carry these names (Component<$$ComponentProps, {}, "">, __sveltets_2_IsomorphicComponent<…>), as do terminal text nodes nested in them and the generic-component interface $$IsomorphicComponent.

name

type string

returns

boolean

isSvelteVirtualPath
#

source.ts view source

(path: string): boolean import {isSvelteVirtualPath} from 'svelte-docinfo/source.js';

Whether a path names a svelte2tsx virtual file (carries SVELTE_VIRTUAL_SUFFIX).

path

type string

returns

boolean

isTypescript
#

source.ts view source

(path: string): boolean import {isTypescript} from 'svelte-docinfo/source.js';

Check if a path is a TypeScript or JS file: .ts, .mts, .tsx, .js, .mjs, or .jsx.

JS files count since JS is valid in TS projects; the analysis program reads them with allowJs forced on (see createAnalysisLanguageService). CommonJS extensions (.cjs, .cts) are left out, since CommonJS exports aren't modeled (commonjs_unsupported). Excludes .d.ts and .d.mts declaration files — use a custom getAnalyzerType to include them.

path

type string

returns

boolean

scrubVirtualSuffixes
#

source.ts view source

(text: string): string import {scrubVirtualSuffixes} from 'svelte-docinfo/source.js';

Remove every occurrence of the virtual suffix from free-form text.

The text twin of stripVirtualSuffix: that one strips a path's trailing suffix, this one scrubs a prose string (a diagnostic message) that may embed virtual paths anywhere. Both readings of the suffix live here so a suffix change has one home.

text

type string

returns

string

SourceFileInfo
#

source.ts view source

also exported from index.ts

SourceFileInfo import type {SourceFileInfo} from 'svelte-docinfo/source.js';

File information for source analysis.

Provides file content to analysis functions from any source: file system, build pipeline, or in-memory.

Note: content is required so callers control what the checker sees for the files they supply. Files they don't (context-closure files, node_modules, other unowned imports) are read from disk.

id

Absolute path to the file. Native paths are fine at the boundary — ids are posixified at ingest (see paths.ts).

type string

content

File content (required — the checker sees this, not the disk, for ingested files).

type string

dependencies?

Pre-resolved absolute file paths of modules this file imports.

Opt-in optimization — when supplied, the session treats this as the authoritative dependency set for the file and skips its own lex+resolve pass for this entry. Build-tool integrations that already maintain a dependency graph can hand it over directly instead of paying the lex+resolve cost twice.

Omit (undefined) → default behavior — the session lexes import specifiers from content and resolves them via its ImportResolver. This is the right choice when the caller doesn't already have a graph.

Only include resolved local imports — node_modules paths are filtered out at storage time by the configured isSource predicate either way.

Trust contract — the session treats this array as authoritative and does not cross-check against the file's content. Edges declared here are accepted as-is, even if the source code doesn't actually import them; edges that *are* in content but missing from this array are silently omitted. The lex+resolve fallback path has no such hole — its edges are always grounded in syntactic imports. Build-tool integrations that supply this field own the correctness of the graph they hand over.

Type-only imports (import type {...}) are the most common asymmetry versus the lex+resolve path: the default lex (lexImports) keeps type-only imports and re-exports; pre-resolved callers backed by a build tool's import graph often drop them. Both are intentional within their respective contracts.

Cache semantics: the session compares this array element-wise (shallow equality) against the snapshot stored from the prior call — a fresh array with identical contents cache-hits, while any length, element, or order difference invalidates. Callers that produce fresh arrays per call (e.g., [...dependencies.keys()] from a graph's Map) reuse the cache cleanly across persistent-session calls.

Order is significant. Reordering without a content change is treated as a real change — sort upstream if you want order-insensitive caching. Map-iteration-order callers (e.g., a module graph emitting [...dependencies.keys()]) are naturally stable across calls for the same content, so no defensive sort is needed there.

type readonly string[]

stripVirtualSuffix
#

source.ts view source

(path: string): string import {stripVirtualSuffix} from 'svelte-docinfo/source.js';

Strip the svelte2tsx virtual file suffix from a path, if present.

Maps Component.svelte.__svelte2tsx__.ts back to Component.svelte. Returns the path unchanged if the suffix is not present.

path

type string

returns

string

SVELTE_COMPONENT_ALIAS_SUFFIX
#

source.ts view source

"__SvelteComponent_" import {SVELTE_COMPONENT_ALIAS_SUFFIX} from 'svelte-docinfo/source.js';

Suffix svelte2tsx appends to the synthesized component const/type alias (<Name>__SvelteComponent_). One of the generated-identifier shapes isSvelte2tsxInternal filters.

SVELTE_VIRTUAL_SUFFIX
#

source.ts view source

".__svelte2tsx__.ts" import {SVELTE_VIRTUAL_SUFFIX} from 'svelte-docinfo/source.js';

Suffix appended to .svelte file paths to create virtual TypeScript file paths.

Used by svelte2tsx integration: Component.svelte → Component.svelte.__svelte2tsx__.ts.

Imported by
#