svelte-docinfo 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +349 -0
- package/dist/analyze-core.d.ts +1386 -0
- package/dist/analyze-core.d.ts.map +1 -0
- package/dist/analyze-core.js +324 -0
- package/dist/analyze.d.ts +137 -0
- package/dist/analyze.d.ts.map +1 -0
- package/dist/analyze.js +148 -0
- package/dist/cli.d.ts +102 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +206 -0
- package/dist/concurrency.d.ts +38 -0
- package/dist/concurrency.d.ts.map +1 -0
- package/dist/concurrency.js +57 -0
- package/dist/declaration-build.d.ts +164 -0
- package/dist/declaration-build.d.ts.map +1 -0
- package/dist/declaration-build.js +15 -0
- package/dist/declaration-helpers.d.ts +169 -0
- package/dist/declaration-helpers.d.ts.map +1 -0
- package/dist/declaration-helpers.js +239 -0
- package/dist/dep-resolver.d.ts +166 -0
- package/dist/dep-resolver.d.ts.map +1 -0
- package/dist/dep-resolver.js +144 -0
- package/dist/diagnostics.d.ts +650 -0
- package/dist/diagnostics.d.ts.map +1 -0
- package/dist/diagnostics.js +377 -0
- package/dist/discovery.d.ts +115 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/discovery.js +126 -0
- package/dist/exports.d.ts +105 -0
- package/dist/exports.d.ts.map +1 -0
- package/dist/exports.js +274 -0
- package/dist/files.d.ts +77 -0
- package/dist/files.d.ts.map +1 -0
- package/dist/files.js +95 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -0
- package/dist/log.d.ts +32 -0
- package/dist/log.d.ts.map +1 -0
- package/dist/log.js +11 -0
- package/dist/logo.d.ts +8 -0
- package/dist/logo.d.ts.map +1 -0
- package/dist/logo.js +9 -0
- package/dist/main.d.ts +11 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +18 -0
- package/dist/paths.d.ts +35 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +34 -0
- package/dist/postprocess.d.ts +145 -0
- package/dist/postprocess.d.ts.map +1 -0
- package/dist/postprocess.js +305 -0
- package/dist/session.d.ts +248 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +496 -0
- package/dist/source-config.d.ts +330 -0
- package/dist/source-config.d.ts.map +1 -0
- package/dist/source-config.js +356 -0
- package/dist/source.d.ts +126 -0
- package/dist/source.d.ts.map +1 -0
- package/dist/source.js +68 -0
- package/dist/svelte.d.ts +179 -0
- package/dist/svelte.d.ts.map +1 -0
- package/dist/svelte.js +898 -0
- package/dist/tsdoc.d.ts +145 -0
- package/dist/tsdoc.d.ts.map +1 -0
- package/dist/tsdoc.js +262 -0
- package/dist/types.d.ts +3381 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +588 -0
- package/dist/typescript-exports.d.ts +91 -0
- package/dist/typescript-exports.d.ts.map +1 -0
- package/dist/typescript-exports.js +656 -0
- package/dist/typescript-extract-class.d.ts +29 -0
- package/dist/typescript-extract-class.d.ts.map +1 -0
- package/dist/typescript-extract-class.js +251 -0
- package/dist/typescript-extract-function.d.ts +47 -0
- package/dist/typescript-extract-function.d.ts.map +1 -0
- package/dist/typescript-extract-function.js +108 -0
- package/dist/typescript-extract-shared.d.ts +166 -0
- package/dist/typescript-extract-shared.d.ts.map +1 -0
- package/dist/typescript-extract-shared.js +528 -0
- package/dist/typescript-extract-type-properties.d.ts +34 -0
- package/dist/typescript-extract-type-properties.d.ts.map +1 -0
- package/dist/typescript-extract-type-properties.js +241 -0
- package/dist/typescript-extract-type.d.ts +48 -0
- package/dist/typescript-extract-type.d.ts.map +1 -0
- package/dist/typescript-extract-type.js +238 -0
- package/dist/typescript-program.d.ts +211 -0
- package/dist/typescript-program.d.ts.map +1 -0
- package/dist/typescript-program.js +290 -0
- package/dist/vite.d.ts +116 -0
- package/dist/vite.d.ts.map +1 -0
- package/dist/vite.js +418 -0
- package/package.json +131 -0
- package/virtual-svelte-docinfo.d.ts +49 -0
package/dist/source.d.ts
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Source file type predicates and path helpers.
|
|
3
|
+
*
|
|
4
|
+
* Pure functions for detecting file types by extension and extracting
|
|
5
|
+
* component names from paths. No configuration dependency — these are
|
|
6
|
+
* the building blocks used by `source-config.ts`.
|
|
7
|
+
*
|
|
8
|
+
* @see `source-config.ts` for configuration-aware functions (`isSource`, `extractPath`, etc.)
|
|
9
|
+
* @see `analyze.ts` for consumers (`analyze`, `analyzeFromFiles`)
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Analyzer type for source files.
|
|
15
|
+
*
|
|
16
|
+
* - `'typescript'` — TypeScript/JS files analyzed via TypeScript compiler API
|
|
17
|
+
* - `'svelte'` — Svelte components analyzed via svelte2tsx + TypeScript compiler API
|
|
18
|
+
* - `'css'` — CSS files included as modules with no declarations
|
|
19
|
+
* - `'json'` — JSON files included as modules with no declarations
|
|
20
|
+
*/
|
|
21
|
+
export type AnalyzerType = 'typescript' | 'svelte' | 'css' | 'json';
|
|
22
|
+
/**
|
|
23
|
+
* File information for source analysis.
|
|
24
|
+
*
|
|
25
|
+
* Provides file content to analysis functions from any source:
|
|
26
|
+
* file system, build pipeline, or in-memory.
|
|
27
|
+
*
|
|
28
|
+
* Note: `content` is required to keep analysis functions pure (no hidden I/O).
|
|
29
|
+
* Callers are responsible for reading file content before analysis.
|
|
30
|
+
*/
|
|
31
|
+
export interface SourceFileInfo {
|
|
32
|
+
/** Absolute path to the file. */
|
|
33
|
+
id: string;
|
|
34
|
+
/** File content (required - analysis functions don't read from disk). */
|
|
35
|
+
content: string;
|
|
36
|
+
/**
|
|
37
|
+
* Pre-resolved absolute file paths of modules this file imports.
|
|
38
|
+
*
|
|
39
|
+
* **Opt-in optimization** — when supplied, the session treats this as the
|
|
40
|
+
* authoritative dependency set for the file and skips its own lex+resolve
|
|
41
|
+
* pass for this entry. Build-tool integrations (e.g., Gro's filer) that
|
|
42
|
+
* already maintain a dependency graph can hand it over directly instead of
|
|
43
|
+
* paying the lex+resolve cost twice.
|
|
44
|
+
*
|
|
45
|
+
* **Omit (undefined) → default behavior** — the session lexes import
|
|
46
|
+
* specifiers from `content` and resolves them via its `ImportResolver`.
|
|
47
|
+
* This is the right choice when the caller doesn't already have a graph.
|
|
48
|
+
*
|
|
49
|
+
* Only include resolved local imports — node_modules paths are filtered
|
|
50
|
+
* out at storage time by the configured `isSource` predicate either way.
|
|
51
|
+
*
|
|
52
|
+
* **Trust contract** — the session treats this array as authoritative and
|
|
53
|
+
* does not cross-check against the file's `content`. Edges declared here
|
|
54
|
+
* are accepted as-is, even if the source code doesn't actually import them;
|
|
55
|
+
* edges that *are* in `content` but missing from this array are silently
|
|
56
|
+
* omitted. The lex+resolve fallback path has no such hole — its edges are
|
|
57
|
+
* always grounded in syntactic imports. Build-tool integrations that
|
|
58
|
+
* supply this field own the correctness of the graph they hand over.
|
|
59
|
+
*
|
|
60
|
+
* Type-only imports (`import type {...}`) are the most common asymmetry
|
|
61
|
+
* versus the lex+resolve path: the default lex (`es-module-lexer`) keeps
|
|
62
|
+
* them; pre-resolved callers backed by a Gro-style filer typically drop
|
|
63
|
+
* them. Both are intentional within their respective contracts.
|
|
64
|
+
*
|
|
65
|
+
* Cache semantics: the session compares this array element-wise (shallow
|
|
66
|
+
* equality) against the snapshot stored from the prior call — a fresh
|
|
67
|
+
* array with identical contents cache-hits, while any length, element, or
|
|
68
|
+
* order difference invalidates. Callers that produce fresh arrays per
|
|
69
|
+
* call (e.g., Gro's `[...filer.dependencies.keys()]`) reuse the cache
|
|
70
|
+
* cleanly across persistent-session calls.
|
|
71
|
+
*
|
|
72
|
+
* Order is significant. Reordering without a content change is treated
|
|
73
|
+
* as a real change — sort upstream if you want order-insensitive caching.
|
|
74
|
+
* Map-iteration-order callers (e.g., a Gro filer emitting
|
|
75
|
+
* `[...filer.dependencies.keys()]`) are naturally stable across calls for
|
|
76
|
+
* the same content, so no defensive sort is needed there.
|
|
77
|
+
*/
|
|
78
|
+
dependencies?: ReadonlyArray<string>;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Default analyzer resolver based on file extension.
|
|
82
|
+
*
|
|
83
|
+
* - `.svelte` → `'svelte'`
|
|
84
|
+
* - `.ts`, `.js` → `'typescript'`
|
|
85
|
+
* - `.css` → `'css'`
|
|
86
|
+
* - `.json` → `'json'`
|
|
87
|
+
* - Other extensions → `null` (skip)
|
|
88
|
+
*/
|
|
89
|
+
export declare const getDefaultAnalyzer: (path: string) => AnalyzerType | null;
|
|
90
|
+
/**
|
|
91
|
+
* Extract component name from a Svelte module path.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* getComponentName('Alert.svelte') // => 'Alert'
|
|
96
|
+
* getComponentName('components/Button.svelte') // => 'Button'
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
export declare const getComponentName: (modulePath: string) => string;
|
|
100
|
+
/**
|
|
101
|
+
* Check if a path is a TypeScript or JS file.
|
|
102
|
+
*
|
|
103
|
+
* Includes both `.ts` and `.js` files since JS files are valid in TS projects.
|
|
104
|
+
* Excludes `.d.ts` declaration files — use a custom `getAnalyzerType` to include them.
|
|
105
|
+
*/
|
|
106
|
+
export declare const isTypescript: (path: string) => boolean;
|
|
107
|
+
/** Check if a path is a Svelte component file. */
|
|
108
|
+
export declare const isSvelte: (path: string) => boolean;
|
|
109
|
+
/** Check if a path is a CSS file. */
|
|
110
|
+
export declare const isCss: (path: string) => boolean;
|
|
111
|
+
/** Check if a path is a JSON file. */
|
|
112
|
+
export declare const isJson: (path: string) => boolean;
|
|
113
|
+
/**
|
|
114
|
+
* Suffix appended to `.svelte` file paths to create virtual TypeScript file paths.
|
|
115
|
+
*
|
|
116
|
+
* Used by svelte2tsx integration: `Component.svelte` → `Component.svelte.__svelte2tsx__.ts`.
|
|
117
|
+
*/
|
|
118
|
+
export declare const SVELTE_VIRTUAL_SUFFIX = ".__svelte2tsx__.ts";
|
|
119
|
+
/**
|
|
120
|
+
* Strip the svelte2tsx virtual file suffix from a path, if present.
|
|
121
|
+
*
|
|
122
|
+
* Maps `Component.svelte.__svelte2tsx__.ts` back to `Component.svelte`.
|
|
123
|
+
* Returns the path unchanged if the suffix is not present.
|
|
124
|
+
*/
|
|
125
|
+
export declare const stripVirtualSuffix: (path: string) => string;
|
|
126
|
+
//# sourceMappingURL=source.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/source.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH;;;;;;;GAOG;AACH,MAAM,MAAM,YAAY,GAAG,YAAY,GAAG,QAAQ,GAAG,KAAK,GAAG,MAAM,CAAC;AAEpE;;;;;;;;GAQG;AACH,MAAM,WAAW,cAAc;IAC9B,iCAAiC;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,yEAAyE;IACzE,OAAO,EAAE,MAAM,CAAC;IAChB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAyCG;IACH,YAAY,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;CACrC;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,GAAI,MAAM,MAAM,KAAG,YAAY,GAAG,IAMhE,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,GAAI,YAAY,MAAM,KAAG,MACG,CAAC;AAE1D;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GAAI,MAAM,MAAM,KAAG,OAC8B,CAAC;AAE3E,kDAAkD;AAClD,eAAO,MAAM,QAAQ,GAAI,MAAM,MAAM,KAAG,OAAmC,CAAC;AAE5E,qCAAqC;AACrC,eAAO,MAAM,KAAK,GAAI,MAAM,MAAM,KAAG,OAAgC,CAAC;AAEtE,sCAAsC;AACtC,eAAO,MAAM,MAAM,GAAI,MAAM,MAAM,KAAG,OAAiC,CAAC;AAExE;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,uBAAuB,CAAC;AAE1D;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,GAAI,MAAM,MAAM,KAAG,MACyC,CAAC"}
|
package/dist/source.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Source file type predicates and path helpers.
|
|
3
|
+
*
|
|
4
|
+
* Pure functions for detecting file types by extension and extracting
|
|
5
|
+
* component names from paths. No configuration dependency — these are
|
|
6
|
+
* the building blocks used by `source-config.ts`.
|
|
7
|
+
*
|
|
8
|
+
* @see `source-config.ts` for configuration-aware functions (`isSource`, `extractPath`, etc.)
|
|
9
|
+
* @see `analyze.ts` for consumers (`analyze`, `analyzeFromFiles`)
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Default analyzer resolver based on file extension.
|
|
15
|
+
*
|
|
16
|
+
* - `.svelte` → `'svelte'`
|
|
17
|
+
* - `.ts`, `.js` → `'typescript'`
|
|
18
|
+
* - `.css` → `'css'`
|
|
19
|
+
* - `.json` → `'json'`
|
|
20
|
+
* - Other extensions → `null` (skip)
|
|
21
|
+
*/
|
|
22
|
+
export const getDefaultAnalyzer = (path) => {
|
|
23
|
+
if (isSvelte(path))
|
|
24
|
+
return 'svelte';
|
|
25
|
+
if (isTypescript(path))
|
|
26
|
+
return 'typescript';
|
|
27
|
+
if (isCss(path))
|
|
28
|
+
return 'css';
|
|
29
|
+
if (isJson(path))
|
|
30
|
+
return 'json';
|
|
31
|
+
return null;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Extract component name from a Svelte module path.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* getComponentName('Alert.svelte') // => 'Alert'
|
|
39
|
+
* getComponentName('components/Button.svelte') // => 'Button'
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export const getComponentName = (modulePath) => modulePath.replace(/^.*\//, '').replace(/\.svelte$/, '');
|
|
43
|
+
/**
|
|
44
|
+
* Check if a path is a TypeScript or JS file.
|
|
45
|
+
*
|
|
46
|
+
* Includes both `.ts` and `.js` files since JS files are valid in TS projects.
|
|
47
|
+
* Excludes `.d.ts` declaration files — use a custom `getAnalyzerType` to include them.
|
|
48
|
+
*/
|
|
49
|
+
export const isTypescript = (path) => (path.endsWith('.ts') && !path.endsWith('.d.ts')) || path.endsWith('.js');
|
|
50
|
+
/** Check if a path is a Svelte component file. */
|
|
51
|
+
export const isSvelte = (path) => path.endsWith('.svelte');
|
|
52
|
+
/** Check if a path is a CSS file. */
|
|
53
|
+
export const isCss = (path) => path.endsWith('.css');
|
|
54
|
+
/** Check if a path is a JSON file. */
|
|
55
|
+
export const isJson = (path) => path.endsWith('.json');
|
|
56
|
+
/**
|
|
57
|
+
* Suffix appended to `.svelte` file paths to create virtual TypeScript file paths.
|
|
58
|
+
*
|
|
59
|
+
* Used by svelte2tsx integration: `Component.svelte` → `Component.svelte.__svelte2tsx__.ts`.
|
|
60
|
+
*/
|
|
61
|
+
export const SVELTE_VIRTUAL_SUFFIX = '.__svelte2tsx__.ts';
|
|
62
|
+
/**
|
|
63
|
+
* Strip the svelte2tsx virtual file suffix from a path, if present.
|
|
64
|
+
*
|
|
65
|
+
* Maps `Component.svelte.__svelte2tsx__.ts` back to `Component.svelte`.
|
|
66
|
+
* Returns the path unchanged if the suffix is not present.
|
|
67
|
+
*/
|
|
68
|
+
export const stripVirtualSuffix = (path) => path.endsWith(SVELTE_VIRTUAL_SUFFIX) ? path.slice(0, -SVELTE_VIRTUAL_SUFFIX.length) : path;
|
package/dist/svelte.d.ts
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Svelte component analysis helpers.
|
|
3
|
+
*
|
|
4
|
+
* Extracts metadata from Svelte components using svelte2tsx transformations:
|
|
5
|
+
*
|
|
6
|
+
* - Component props with types and JSDoc
|
|
7
|
+
* - Component-level documentation
|
|
8
|
+
* - Type information
|
|
9
|
+
*
|
|
10
|
+
* Workflow: Transform Svelte to TypeScript via svelte2tsx, parse the transformed
|
|
11
|
+
* TypeScript with the TS Compiler API, extract component-level JSDoc from original source.
|
|
12
|
+
*
|
|
13
|
+
* **Svelte 5 only**: The svelte2tsx output format changed significantly between versions.
|
|
14
|
+
* This module requires Svelte 5+ and will throw a clear error if an older version is detected.
|
|
15
|
+
* There is no Svelte 4 compatibility layer.
|
|
16
|
+
*
|
|
17
|
+
* @see `typescript-exports.ts` for `analyzeExports`, `extractModuleComment`
|
|
18
|
+
* @see `typescript-extract-shared.ts` for `parseGenericParam`, `filterIntersectionProperties`
|
|
19
|
+
* @see `typescript-program.ts` for `IsExternalFile`, `createIsExternalFile`
|
|
20
|
+
* @see `tsdoc.ts` for `parseComment`, `applyToDeclaration`
|
|
21
|
+
* @see `source.ts` for `SourceFileInfo`, `getComponentName`
|
|
22
|
+
*
|
|
23
|
+
* @module
|
|
24
|
+
*/
|
|
25
|
+
import { TraceMap } from '@jridgewell/trace-mapping';
|
|
26
|
+
import ts from 'typescript';
|
|
27
|
+
import type { ParameterJsonInput } from './types.js';
|
|
28
|
+
import type { ModuleAnalysis } from './declaration-build.js';
|
|
29
|
+
import { type SourceFileInfo } from './source.js';
|
|
30
|
+
import { type ModuleSourceOptions } from './source-config.js';
|
|
31
|
+
import { type Diagnostic } from './diagnostics.js';
|
|
32
|
+
/** Resolved source map type (avoids repeating the verbose `InstanceType<...>` inline). */
|
|
33
|
+
type SourceMap = InstanceType<typeof TraceMap>;
|
|
34
|
+
/**
|
|
35
|
+
* Pre-transformed Svelte virtual file data.
|
|
36
|
+
*
|
|
37
|
+
* Produced by `transformSvelteSource` and consumed by `analyzeSvelteModule`
|
|
38
|
+
* to provide checker-backed analysis of Svelte components.
|
|
39
|
+
*/
|
|
40
|
+
export interface SvelteVirtualFile {
|
|
41
|
+
/** Path used for the virtual file in the TypeScript program. */
|
|
42
|
+
virtualPath: string;
|
|
43
|
+
/** svelte2tsx transformed TypeScript content. */
|
|
44
|
+
content: string;
|
|
45
|
+
/** Source map for position mapping back to the original `.svelte` file. */
|
|
46
|
+
sourceMap: SourceMap | null;
|
|
47
|
+
/** Script language. `undefined` means TypeScript (default), `'js'` for JavaScript-only components. */
|
|
48
|
+
lang: 'js' | undefined;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Result of `transformSvelteSource` — a virtual file (when transform succeeded)
|
|
52
|
+
* plus any ingest-time diagnostics produced during the transform.
|
|
53
|
+
*
|
|
54
|
+
* `virtual` is `undefined` when svelte2tsx threw; in that case `diagnostics`
|
|
55
|
+
* contains a `transform_failed` entry. When the transform succeeded but source
|
|
56
|
+
* map construction failed, `virtual` is populated and `diagnostics` contains a
|
|
57
|
+
* `source_map_failed` entry. The session's owned-entry stores both — the
|
|
58
|
+
* virtual (or `transformFailed: true` flag) and the ingest diagnostics.
|
|
59
|
+
*/
|
|
60
|
+
export interface TransformResult {
|
|
61
|
+
virtual: SvelteVirtualFile | undefined;
|
|
62
|
+
diagnostics: Array<Diagnostic>;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Pre-transform a Svelte source file via svelte2tsx.
|
|
66
|
+
*
|
|
67
|
+
* Produces a `SvelteVirtualFile` containing the transformed TypeScript content
|
|
68
|
+
* and source map. The virtual file can be included in a TypeScript program
|
|
69
|
+
* (via `createAnalysisProgram({ virtualFiles })`) so that the checker can
|
|
70
|
+
* resolve imported types, `<script module>` exports, and re-exports.
|
|
71
|
+
*
|
|
72
|
+
* Errors at ingest are returned via `diagnostics` rather than thrown:
|
|
73
|
+
* - svelte2tsx throws → `transform_failed`, `virtual: undefined`
|
|
74
|
+
* - source map construction fails → `source_map_failed`, virtual populated
|
|
75
|
+
*
|
|
76
|
+
* Diagnostic file paths are the original `.svelte` source ID; downstream
|
|
77
|
+
* normalization rewrites them to project-root-relative form.
|
|
78
|
+
*
|
|
79
|
+
* @param sourceFile - the Svelte source file with content loaded
|
|
80
|
+
* @returns virtual file data (or `undefined` on transform failure) plus ingest diagnostics
|
|
81
|
+
* @throws Error if Svelte version is below 5 (checked once on first call)
|
|
82
|
+
*/
|
|
83
|
+
export declare const transformSvelteSource: (sourceFile: SourceFileInfo) => TransformResult;
|
|
84
|
+
/**
|
|
85
|
+
* Extract the content of the main `<script>` tag from Svelte source.
|
|
86
|
+
*
|
|
87
|
+
* Matches `<script>` with any attributes (e.g., `lang`, `generics`) but excludes
|
|
88
|
+
* module scripts (`<script module>`, `<script context="module">`).
|
|
89
|
+
*
|
|
90
|
+
* @returns the script tag content, or undefined if no matching script tag is found
|
|
91
|
+
*/
|
|
92
|
+
export declare const extractScriptContent: (svelteSource: string) => string | undefined;
|
|
93
|
+
/**
|
|
94
|
+
* Extract `@module` comment from HTML comments in Svelte source.
|
|
95
|
+
*
|
|
96
|
+
* Scans all `<!-- ... -->` comments for one containing `@module` at the
|
|
97
|
+
* start of a line. This allows `@component` and `@module` to coexist as
|
|
98
|
+
* separate HTML comments. Works for template-only components.
|
|
99
|
+
*
|
|
100
|
+
* @param svelteSource - the full Svelte source code
|
|
101
|
+
* @returns the cleaned module comment text, or undefined if no `@module` HTML comment found
|
|
102
|
+
*/
|
|
103
|
+
export declare const extractHtmlModuleComment: (svelteSource: string) => string | undefined;
|
|
104
|
+
/**
|
|
105
|
+
* Extract module-level comment from Svelte script content.
|
|
106
|
+
*
|
|
107
|
+
* Parses the script content as TypeScript and delegates to `extractModuleComment`
|
|
108
|
+
* for the shared `@module` tag detection logic.
|
|
109
|
+
*
|
|
110
|
+
* @param scriptContent - the content of the `<script>` tag
|
|
111
|
+
* @returns the cleaned module comment text, or undefined if none found
|
|
112
|
+
*/
|
|
113
|
+
export declare const extractSvelteModuleComment: (scriptContent: string) => string | undefined;
|
|
114
|
+
/**
|
|
115
|
+
* Check if a type string represents a `Snippet` type.
|
|
116
|
+
*
|
|
117
|
+
* Uses the already-resolved type string (from `checker.typeToString`) for reliable
|
|
118
|
+
* detection. `Snippet` is an interface (not a type alias), so `aliasSymbol` is
|
|
119
|
+
* not available — type string matching is the reliable detection path.
|
|
120
|
+
*/
|
|
121
|
+
export declare const isSnippetTypeString: (typeString: string) => boolean;
|
|
122
|
+
/**
|
|
123
|
+
* Extract structured parameters from a `Snippet<[...]>` type.
|
|
124
|
+
*
|
|
125
|
+
* `Snippet` is an interface, so type arguments are on `TypeReference` (accessed
|
|
126
|
+
* via `checker.getTypeArguments`), not on `aliasTypeArguments` (which is only
|
|
127
|
+
* for type aliases).
|
|
128
|
+
*
|
|
129
|
+
* Returns full `ParameterJson` input objects (with `optional` and `rest` always set)
|
|
130
|
+
* for runtime consistency with `extractSignatureParameters` in `typescript-extract-shared.ts`.
|
|
131
|
+
*
|
|
132
|
+
* @returns array of parameter info for the snippet's tuple type arguments,
|
|
133
|
+
* or `[]` for bare `Snippet` / `Snippet<[]>`
|
|
134
|
+
*/
|
|
135
|
+
export declare const extractSnippetParameters: (snippetType: ts.Type, checker: ts.TypeChecker) => Array<ParameterJsonInput>;
|
|
136
|
+
/**
|
|
137
|
+
* Check if a return type string matches svelte2tsx's snippet return type pattern.
|
|
138
|
+
*
|
|
139
|
+
* svelte2tsx transforms exported snippets into arrow functions with
|
|
140
|
+
* `ReturnType<import('svelte').Snippet>` as the return type annotation.
|
|
141
|
+
* The resolved return type includes `unique symbol` (from Svelte's non-exported
|
|
142
|
+
* `SnippetReturn` unique symbol) intersected with the branded render message.
|
|
143
|
+
* We match on both parts to avoid false positives — the branded message alone
|
|
144
|
+
* could theoretically be crafted by user code, but the `unique symbol` intersection
|
|
145
|
+
* cannot since `SnippetReturn` is not exported from svelte.
|
|
146
|
+
*/
|
|
147
|
+
export declare const isSnippetReturnType: (returnType: string) => boolean;
|
|
148
|
+
/**
|
|
149
|
+
* Synthesize a `Snippet<[...]>` type string from structured parameters.
|
|
150
|
+
*
|
|
151
|
+
* Used for `kind: 'snippet'` declarations where the raw svelte2tsx type
|
|
152
|
+
* is implementation noise. Produces type strings consistent with how
|
|
153
|
+
* the checker formats Snippet types on props.
|
|
154
|
+
*/
|
|
155
|
+
export declare const synthesizeSnippetTypeSignature: (parameters: Array<ParameterJsonInput>) => string;
|
|
156
|
+
/**
|
|
157
|
+
* Analyze a Svelte module using checker-backed analysis.
|
|
158
|
+
*
|
|
159
|
+
* Requires the svelte2tsx virtual output to be included in the TypeScript program
|
|
160
|
+
* (via `createAnalysisProgram({ virtualFiles })`). Provides full type resolution for:
|
|
161
|
+
* - Imported prop types (`let {x}: ImportedProps = $props()`)
|
|
162
|
+
* - `<script module>` exports (constants, types, re-exports)
|
|
163
|
+
* - Star exports and re-exports from Svelte files
|
|
164
|
+
*
|
|
165
|
+
* @param sourceFile - the original Svelte source file
|
|
166
|
+
* @param modulePath - module path relative to source root
|
|
167
|
+
* @param checker - TypeScript type checker (from the program containing virtual files)
|
|
168
|
+
* @param options - module source options for path extraction
|
|
169
|
+
* @param diagnostics - diagnostics collector for non-fatal issues
|
|
170
|
+
* @param program - TypeScript program containing the virtual file
|
|
171
|
+
* @param virtualFile - pre-transformed virtual file data
|
|
172
|
+
* @returns module analysis with declarations, re-exports, and star exports;
|
|
173
|
+
* `undefined` if the virtual file is not found in the program
|
|
174
|
+
*/
|
|
175
|
+
export declare const analyzeSvelteModule: (sourceFile: SourceFileInfo & {
|
|
176
|
+
dependents?: ReadonlyArray<string>;
|
|
177
|
+
}, modulePath: string, checker: ts.TypeChecker, options: ModuleSourceOptions, diagnostics: Array<Diagnostic>, program: ts.Program, virtualFile: SvelteVirtualFile) => ModuleAnalysis | undefined;
|
|
178
|
+
export {};
|
|
179
|
+
//# sourceMappingURL=svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"svelte.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/svelte.ts"],"names":[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