sveld 0.35.2 → 0.36.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/README.md +33 -6
- package/lib/browser.d.ts +660 -39
- package/lib/browser.js +172 -172
- package/lib/chunk-0fqdg2xa.js +20 -0
- package/lib/chunk-2vwf7nck.js +1 -0
- package/lib/chunk-8myyzjb1.js +4 -0
- package/lib/{chunk-v4q9vw0y.js → chunk-as5hgj7e.js} +57 -57
- package/lib/{chunk-zva3xjwa.js → chunk-denfbw92.js} +1 -1
- package/lib/chunk-h1r040pg.js +6 -0
- package/lib/chunk-m538qnhp.js +230 -0
- package/lib/chunk-r4rrncmd.js +1 -0
- package/lib/{chunk-1p4ka68s.js → chunk-t9d5k3p7.js} +1 -1
- package/lib/{chunk-8xw75w8t.js → chunk-tmj7vnjr.js} +2 -2
- package/lib/chunk-xryt7ad2.js +3 -0
- package/lib/cli-entry.js +1 -1
- package/lib/index.d.ts +767 -10
- package/lib/index.js +1 -1
- package/package.json +1 -1
- package/lib/ComponentParser.d.ts +0 -560
- package/lib/ast-guards.d.ts +0 -16
- package/lib/brands.d.ts +0 -11
- package/lib/bundle.d.ts +0 -174
- package/lib/check.d.ts +0 -43
- package/lib/chunk-72hx9e9w.js +0 -20
- package/lib/chunk-7qz0hzgw.js +0 -217
- package/lib/chunk-cxrw7gzr.js +0 -2
- package/lib/chunk-jdnsv86e.js +0 -1
- package/lib/chunk-pmj8c3yv.js +0 -6
- package/lib/chunk-s9mzxa4y.js +0 -1
- package/lib/chunk-xkrgedm4.js +0 -4
- package/lib/cli-entry.d.ts +0 -12
- package/lib/cli.d.ts +0 -28
- package/lib/create-exports.d.ts +0 -32
- package/lib/dependency-graph.d.ts +0 -20
- package/lib/diagnostics.d.ts +0 -34
- package/lib/element-tag-map.d.ts +0 -146
- package/lib/example-check.d.ts +0 -24
- package/lib/get-svelte-entry.d.ts +0 -3
- package/lib/load-config.d.ts +0 -62
- package/lib/parse-cache.d.ts +0 -28
- package/lib/parse-entry-exports.d.ts +0 -30
- package/lib/parse-exports.d.ts +0 -25
- package/lib/parsed-component-metadata.d.ts +0 -13
- package/lib/parser/bindings.d.ts +0 -4
- package/lib/parser/context.d.ts +0 -72
- package/lib/parser/contexts.d.ts +0 -19
- package/lib/parser/diagnostics.d.ts +0 -8
- package/lib/parser/events.d.ts +0 -21
- package/lib/parser/generics.d.ts +0 -24
- package/lib/parser/jsdoc.d.ts +0 -55
- package/lib/parser/prop-shared.d.ts +0 -84
- package/lib/parser/props.d.ts +0 -71
- package/lib/parser/rest-props.d.ts +0 -4
- package/lib/parser/runes-detection.d.ts +0 -13
- package/lib/parser/runes-props.d.ts +0 -18
- package/lib/parser/scopes.d.ts +0 -56
- package/lib/parser/slots.d.ts +0 -24
- package/lib/parser/source-position.d.ts +0 -26
- package/lib/parser/type-resolution.d.ts +0 -17
- package/lib/parser/typescript-casts.d.ts +0 -1
- package/lib/parser/utils.d.ts +0 -1
- package/lib/parser/variable-jsdoc.d.ts +0 -12
- package/lib/parser-stack.d.ts +0 -20
- package/lib/path.d.ts +0 -2
- package/lib/plugin.d.ts +0 -85
- package/lib/resolve-alias.d.ts +0 -30
- package/lib/resolve-types.d.ts +0 -52
- package/lib/sveld.d.ts +0 -29
- package/lib/svelte-parse.d.ts +0 -4
- package/lib/svelte-version.d.ts +0 -1
- package/lib/validate.d.ts +0 -13
- package/lib/watch.d.ts +0 -34
- package/lib/writer/MarkdownWriterBase.d.ts +0 -26
- package/lib/writer/Writer.d.ts +0 -31
- package/lib/writer/WriterMarkdown.d.ts +0 -31
- package/lib/writer/built-in-writers.d.ts +0 -1
- package/lib/writer/document-model.d.ts +0 -34
- package/lib/writer/format-generated-ts.d.ts +0 -8
- package/lib/writer/markdown-format-utils.d.ts +0 -20
- package/lib/writer/markdown-render-utils.d.ts +0 -10
- package/lib/writer/registry.d.ts +0 -17
- package/lib/writer/writer-custom-elements-core.d.ts +0 -86
- package/lib/writer/writer-custom-elements.d.ts +0 -15
- package/lib/writer/writer-json.d.ts +0 -27
- package/lib/writer/writer-markdown-core.d.ts +0 -32
- package/lib/writer/writer-markdown.d.ts +0 -23
- package/lib/writer/writer-ts-definitions-core.d.ts +0 -30
- package/lib/writer/writer-ts-definitions.d.ts +0 -43
package/lib/browser.d.ts
CHANGED
|
@@ -1,39 +1,660 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
1
|
+
import type { Property } from "estree";
|
|
2
|
+
|
|
3
|
+
import type { Node } from "estree-walker";
|
|
4
|
+
|
|
5
|
+
declare const brand: unique symbol;
|
|
6
|
+
|
|
7
|
+
type Brand<TBase extends string, TBrand extends string> = TBase & {
|
|
8
|
+
readonly [brand]: TBrand;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type NormalizedPath = Brand<string, "NormalizedPath">;
|
|
12
|
+
|
|
13
|
+
export declare function asNormalizedPath(path: string): NormalizedPath;
|
|
14
|
+
|
|
15
|
+
interface JsDocPassthroughTag {
|
|
16
|
+
name: string;
|
|
17
|
+
body: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
type DeprecatedValue = string | true;
|
|
21
|
+
|
|
22
|
+
interface SourcePosition {
|
|
23
|
+
/** 1-based source line number */
|
|
24
|
+
line: number;
|
|
25
|
+
/** 0-based source column number */
|
|
26
|
+
column: number;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface SourceRange {
|
|
30
|
+
start: SourcePosition;
|
|
31
|
+
end: SourcePosition;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface ParsedComponentTypeScriptMetadata {
|
|
35
|
+
canonicalPropsType?: string;
|
|
36
|
+
canonicalPropNames: string[];
|
|
37
|
+
localTypeDeclarations: string[];
|
|
38
|
+
typeImportStatements: string[];
|
|
39
|
+
/**
|
|
40
|
+
* Whether `canonicalPropsType` mentions one of the component's own
|
|
41
|
+
* `<script generics="...">` parameters (e.g. `Props<T>`). The semantic
|
|
42
|
+
* resolver has no binding for `T`, so `resolveTypes` must leave this
|
|
43
|
+
* component's props as their AST-derived text rather than expand them.
|
|
44
|
+
*/
|
|
45
|
+
referencesComponentGenerics?: boolean;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
type SyntaxMode = "legacy" | "runes";
|
|
49
|
+
|
|
50
|
+
type ScriptLanguage = "js" | "ts";
|
|
51
|
+
|
|
52
|
+
type ComponentPropTypeSource = "typescript" | "jsdoc" | "default" | "inferred" | "unknown";
|
|
53
|
+
|
|
54
|
+
type ComponentPropDefaultValueKind = "literal" | "array" | "object" | "expression" | "function" | "unknown";
|
|
55
|
+
|
|
56
|
+
interface ComponentPropDefaultValue {
|
|
57
|
+
raw: string;
|
|
58
|
+
kind: ComponentPropDefaultValueKind;
|
|
59
|
+
value?: unknown;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
type ModernScriptAttribute = {
|
|
63
|
+
name?: string;
|
|
64
|
+
value?: Array<{
|
|
65
|
+
data?: string;
|
|
66
|
+
raw?: string;
|
|
67
|
+
}> | boolean;
|
|
68
|
+
start?: number;
|
|
69
|
+
end?: number;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
type ModernScriptNode = {
|
|
73
|
+
attributes?: ModernScriptAttribute[];
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
interface ComponentParserDiagnostics {
|
|
77
|
+
moduleName: string;
|
|
78
|
+
filePath: string;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
type ComponentPropBinding = "readonly" | "writable";
|
|
82
|
+
|
|
83
|
+
interface ComponentPropParam {
|
|
84
|
+
/** Parameter name. */
|
|
85
|
+
name: string;
|
|
86
|
+
/** Parameter type (e.g. `"string"`, `"CustomType"`). */
|
|
87
|
+
type: string;
|
|
88
|
+
/** From JSDoc `@param`. */
|
|
89
|
+
description?: string;
|
|
90
|
+
/** True when optional. */
|
|
91
|
+
optional?: boolean;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
interface ComponentProp {
|
|
95
|
+
/** Public prop name. */
|
|
96
|
+
name: string;
|
|
97
|
+
/** `"let"` (required), `"const"` (default), or `"function"`. */
|
|
98
|
+
kind: "let" | "const" | "function";
|
|
99
|
+
/** True when declared with `const`. */
|
|
100
|
+
constant: boolean;
|
|
101
|
+
/** TypeScript type text. */
|
|
102
|
+
type?: string;
|
|
103
|
+
/** Conservative provenance for the prop type. See the precedence rule on {@link ComponentProp}. */
|
|
104
|
+
typeSource?: ComponentPropTypeSource;
|
|
105
|
+
/** Local binding when it differs from the public name. */
|
|
106
|
+
localName?: string;
|
|
107
|
+
/** Default value as source text; unset when the prop has no initializer/default. */
|
|
108
|
+
value?: string;
|
|
109
|
+
/** Structured default value metadata for docs UIs; set alongside `value` from the same initializer. */
|
|
110
|
+
defaultValue?: ComponentPropDefaultValue;
|
|
111
|
+
/** From JSDoc, or a matching `@typedef`'s own description (legacy only; see {@link ComponentProp}). */
|
|
112
|
+
description?: string;
|
|
113
|
+
/** From JSDoc `@param` on function props. */
|
|
114
|
+
params?: ComponentPropParam[];
|
|
115
|
+
/** From JSDoc `@returns` on function props. */
|
|
116
|
+
returnType?: string;
|
|
117
|
+
/**
|
|
118
|
+
* True for arrow/function-expression initializers and bare `function`
|
|
119
|
+
* declarations in every mode; additionally true for a function-shaped
|
|
120
|
+
* type/JSDoc signature in runes only (see {@link ComponentProp}).
|
|
121
|
+
*/
|
|
122
|
+
isFunction: boolean;
|
|
123
|
+
/** True for `function` declarations. */
|
|
124
|
+
isFunctionDeclaration: boolean;
|
|
125
|
+
/** True when declared with `let` and no default. */
|
|
126
|
+
isRequired: boolean;
|
|
127
|
+
/**
|
|
128
|
+
* True when the prop is mutated locally (legacy, inferred from assignment/
|
|
129
|
+
* binding targets) or declared with `$bindable()` (runes).
|
|
130
|
+
*/
|
|
131
|
+
reactive: boolean;
|
|
132
|
+
/** Binding direction from `@bindable` JSDoc. */
|
|
133
|
+
binding?: ComponentPropBinding;
|
|
134
|
+
/** True when declared with Svelte 5 `$bindable()` (runes only). */
|
|
135
|
+
bindable?: true;
|
|
136
|
+
/** From `@deprecated` JSDoc. */
|
|
137
|
+
deprecated?: DeprecatedValue;
|
|
138
|
+
/** `@since` / `@example` tags in source order. */
|
|
139
|
+
tags?: JsDocPassthroughTag[];
|
|
140
|
+
/** Source range when available. */
|
|
141
|
+
source?: SourceRange;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
interface ComponentSlot {
|
|
145
|
+
/** Slot name (`null` for the default slot). */
|
|
146
|
+
name?: string | null;
|
|
147
|
+
/** True for the default slot. */
|
|
148
|
+
default: boolean;
|
|
149
|
+
/** Fallback content when the slot is empty. */
|
|
150
|
+
fallback?: string;
|
|
151
|
+
/** Slot props as TypeScript type text. */
|
|
152
|
+
slot_props?: string;
|
|
153
|
+
/** From JSDoc `@slot` or `@snippet`. */
|
|
154
|
+
description?: string;
|
|
155
|
+
/** From `@deprecated` JSDoc. */
|
|
156
|
+
deprecated?: DeprecatedValue;
|
|
157
|
+
/** Tags between the description and `@slot`/`@snippet` (e.g. `@example`), in source order. */
|
|
158
|
+
tags?: JsDocPassthroughTag[];
|
|
159
|
+
/** Source range when available. */
|
|
160
|
+
source?: SourceRange;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
interface DispatchedEvent {
|
|
164
|
+
/** Discriminator: `"dispatched"`. */
|
|
165
|
+
type: "dispatched";
|
|
166
|
+
/** Event name. */
|
|
167
|
+
name: string;
|
|
168
|
+
/** Detail type text. */
|
|
169
|
+
detail?: string;
|
|
170
|
+
/** From JSDoc `@event`. */
|
|
171
|
+
description?: string;
|
|
172
|
+
/** From `@deprecated` JSDoc. */
|
|
173
|
+
deprecated?: DeprecatedValue;
|
|
174
|
+
/** `@since` / `@example` tags in source order. */
|
|
175
|
+
tags?: JsDocPassthroughTag[];
|
|
176
|
+
/** Source range when available. */
|
|
177
|
+
source?: SourceRange;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
interface SerializedForwardedEvent {
|
|
181
|
+
/** Discriminator: `"forwarded"`. */
|
|
182
|
+
type: "forwarded";
|
|
183
|
+
/** Event name. */
|
|
184
|
+
name: string;
|
|
185
|
+
/** Element name as a string for JSON output. */
|
|
186
|
+
element: string;
|
|
187
|
+
/** From JSDoc `@event`. */
|
|
188
|
+
description?: string;
|
|
189
|
+
/** From `@deprecated` JSDoc. */
|
|
190
|
+
deprecated?: DeprecatedValue;
|
|
191
|
+
/** Detail type from `@event`. */
|
|
192
|
+
detail?: string;
|
|
193
|
+
/** `@since` / `@example` tags in source order. */
|
|
194
|
+
tags?: JsDocPassthroughTag[];
|
|
195
|
+
/** Source range when available. */
|
|
196
|
+
source?: SourceRange;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export type SerializedComponentEvent = SerializedForwardedEvent | DispatchedEvent;
|
|
200
|
+
|
|
201
|
+
interface TypeDef {
|
|
202
|
+
/** Type text (e.g. `"{ x: number; y: number }"`). */
|
|
203
|
+
type: string;
|
|
204
|
+
/** Type name. */
|
|
205
|
+
name: string;
|
|
206
|
+
/** From JSDoc. */
|
|
207
|
+
description?: string;
|
|
208
|
+
/** Full `type` alias declaration text. */
|
|
209
|
+
ts: string;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
type ComponentGenerics = [name: string, type: string] | null;
|
|
213
|
+
|
|
214
|
+
interface ComponentInlineElement {
|
|
215
|
+
/** Discriminator: `"InlineComponent"`. */
|
|
216
|
+
type: "InlineComponent";
|
|
217
|
+
/** Component name. */
|
|
218
|
+
name: string;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
interface ComponentElement {
|
|
222
|
+
type: "Element";
|
|
223
|
+
name: string;
|
|
224
|
+
/**
|
|
225
|
+
* Static tag for `svelte:element this="div"`. Undefined when `this` is dynamic.
|
|
226
|
+
*
|
|
227
|
+
* @example
|
|
228
|
+
* ```svelte
|
|
229
|
+
* <!-- Static tag -->
|
|
230
|
+
* <svelte:element this="div" bind:this={elementRef} />
|
|
231
|
+
* // thisValue: "div"
|
|
232
|
+
*
|
|
233
|
+
* <!-- Dynamic tag -->
|
|
234
|
+
* <svelte:element this={tagName} bind:this={elementRef} />
|
|
235
|
+
* // thisValue: undefined
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
thisValue?: string;
|
|
239
|
+
/** From `@restProps` JSDoc. */
|
|
240
|
+
description?: string;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
type RestProps = undefined | ComponentInlineElement | ComponentElement;
|
|
244
|
+
|
|
245
|
+
interface Extends {
|
|
246
|
+
/** Interface name (e.g. `"ButtonProps"`). */
|
|
247
|
+
interface: string;
|
|
248
|
+
/** Import path (e.g. `"./types"`). */
|
|
249
|
+
import: string;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
interface ComponentContextProp {
|
|
253
|
+
/** Property name. */
|
|
254
|
+
name: string;
|
|
255
|
+
/** Property type text. */
|
|
256
|
+
type: string;
|
|
257
|
+
/** From JSDoc. */
|
|
258
|
+
description?: string;
|
|
259
|
+
/** True when optional. */
|
|
260
|
+
optional: boolean;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
interface ComponentContext {
|
|
264
|
+
/** Context key from `setContext`. */
|
|
265
|
+
key: string;
|
|
266
|
+
/** Generated type name (e.g. `"ModalContext"`). */
|
|
267
|
+
typeName: string;
|
|
268
|
+
/** From JSDoc. */
|
|
269
|
+
description?: string;
|
|
270
|
+
/** Context object properties. */
|
|
271
|
+
properties: ComponentContextProp[];
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
interface ParsedComponent {
|
|
275
|
+
/** Source range of the parsed file. */
|
|
276
|
+
source?: SourceRange;
|
|
277
|
+
syntaxMode: SyntaxMode;
|
|
278
|
+
scriptLanguage?: ScriptLanguage;
|
|
279
|
+
/** Instance-level props (`export let`/`export function`, or runes `$props()`). See {@link ComponentProp} for the shared IR these are built from. */
|
|
280
|
+
props: ComponentProp[];
|
|
281
|
+
/** Exports from `<script context="module">`. Same {@link ComponentProp} shape as `props`, resolved through the same shared decisions. */
|
|
282
|
+
moduleExports: ComponentProp[];
|
|
283
|
+
slots: ComponentSlot[];
|
|
284
|
+
/** Serialized events for JSON/API output. */
|
|
285
|
+
events: SerializedComponentEvent[];
|
|
286
|
+
typedefs: TypeDef[];
|
|
287
|
+
generics: null | ComponentGenerics;
|
|
288
|
+
rest_props: RestProps;
|
|
289
|
+
extends?: Extends;
|
|
290
|
+
/** From `@component` HTML comment. */
|
|
291
|
+
componentComment?: string;
|
|
292
|
+
componentCommentSource?: SourceRange;
|
|
293
|
+
contexts?: ComponentContext[];
|
|
294
|
+
customElementTag?: string;
|
|
295
|
+
/**
|
|
296
|
+
* Type guesses from this parse (unknown props, `any` contexts, orphan `@event` tags).
|
|
297
|
+
*/
|
|
298
|
+
diagnostics?: SveldDiagnostic[];
|
|
299
|
+
/** Writer-only TypeScript metadata. Not serialized to JSON. */
|
|
300
|
+
[PARSED_COMPONENT_TYPE_SCRIPT_METADATA]?: ParsedComponentTypeScriptMetadata;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
export class ComponentParser {
|
|
304
|
+
/**
|
|
305
|
+
* All per-parse mutable state (props, slots, events, scopes, source, etc.).
|
|
306
|
+
* See {@link ParserContext} for field-by-field documentation. Replaced
|
|
307
|
+
* wholesale by `cleanup()` between parses.
|
|
308
|
+
*/
|
|
309
|
+
private ctx;
|
|
310
|
+
private static mapToArray;
|
|
311
|
+
private static getStaticAttributeValue;
|
|
312
|
+
resolveScriptLanguage(parsed: {
|
|
313
|
+
instance?: ModernScriptNode;
|
|
314
|
+
module?: ModernScriptNode;
|
|
315
|
+
}): ScriptLanguage | undefined;
|
|
316
|
+
/**
|
|
317
|
+
* Reads the `generics` attribute off the instance script (Svelte only allows
|
|
318
|
+
* it there, and only alongside `lang="ts"`). Returns the raw value for later
|
|
319
|
+
* precedence resolution against `@generics`/`@template` JSDoc tags, or
|
|
320
|
+
* `undefined` if absent. Records a `syntax-skipped` diagnostic and returns
|
|
321
|
+
* `undefined` if the attribute is present without `lang="ts"`, since sveld
|
|
322
|
+
* can't safely guess how to parse it as plain JavaScript.
|
|
323
|
+
*/
|
|
324
|
+
resolveScriptGenericsAttribute(parsed: {
|
|
325
|
+
instance?: ModernScriptNode;
|
|
326
|
+
}): {
|
|
327
|
+
value: string;
|
|
328
|
+
source?: SourceRange;
|
|
329
|
+
} | undefined;
|
|
330
|
+
private resolvePublicPropName;
|
|
331
|
+
trackPropLocalName(propName: string, localName?: string): void;
|
|
332
|
+
private getPropByLocalOrPublic;
|
|
333
|
+
getPropTypeByLocalOrPublic(name: string): string | undefined;
|
|
334
|
+
getExplicitPropType(name: string): string | undefined;
|
|
335
|
+
getPropertyName(node: Property["key"]): string | undefined;
|
|
336
|
+
isNumericConstant(memberExpr: unknown): boolean;
|
|
337
|
+
resolveLocalVarJSDoc(name: string): {
|
|
338
|
+
type?: string;
|
|
339
|
+
params?: ComponentPropParam[];
|
|
340
|
+
returnType?: string;
|
|
341
|
+
description?: string;
|
|
342
|
+
binding?: ComponentPropBinding;
|
|
343
|
+
deprecated?: DeprecatedValue;
|
|
344
|
+
tags?: JsDocPassthroughTag[];
|
|
345
|
+
} | undefined;
|
|
346
|
+
private addModuleExport;
|
|
347
|
+
/**
|
|
348
|
+
* @example
|
|
349
|
+
* ```ts
|
|
350
|
+
* aliasType("*"); // "any"
|
|
351
|
+
* aliasType(" string "); // "string"
|
|
352
|
+
* ```
|
|
353
|
+
*/
|
|
354
|
+
aliasType(type: string): string;
|
|
355
|
+
/**
|
|
356
|
+
* @example
|
|
357
|
+
* ```ts
|
|
358
|
+
* // Given:
|
|
359
|
+
* // /**
|
|
360
|
+
* // * @type {number}
|
|
361
|
+
* // * The count value
|
|
362
|
+
* // *\/
|
|
363
|
+
* // const count = 0;
|
|
364
|
+
*
|
|
365
|
+
* findVariableTypeAndDescription("count");
|
|
366
|
+
* // { type: "number", description: "The count value" }
|
|
367
|
+
* ```
|
|
368
|
+
*/
|
|
369
|
+
findVariableTypeAndDescription(varName: string): {
|
|
370
|
+
type: string;
|
|
371
|
+
description?: string;
|
|
372
|
+
} | null;
|
|
373
|
+
accumulateGeneric(name: string, constraint: string): void;
|
|
374
|
+
/**
|
|
375
|
+
* Resets parser state for reuse between parses.
|
|
376
|
+
*
|
|
377
|
+
* @example
|
|
378
|
+
* ```ts
|
|
379
|
+
* parser.parseSvelteComponent(source1, diagnostics1);
|
|
380
|
+
* parser.cleanup();
|
|
381
|
+
* parser.parseSvelteComponent(source2, diagnostics2);
|
|
382
|
+
* ```
|
|
383
|
+
*/
|
|
384
|
+
cleanup(): void;
|
|
385
|
+
private static readonly SCRIPT_BLOCK_REGEX;
|
|
386
|
+
private static readonly TS_DIRECTIVE_REGEX;
|
|
387
|
+
private static stripTypeScriptDirectivesFromScripts;
|
|
388
|
+
/**
|
|
389
|
+
* @example
|
|
390
|
+
* ```ts
|
|
391
|
+
* const parser = new ComponentParser();
|
|
392
|
+
* const result = parser.parseSvelteComponent(source, {
|
|
393
|
+
* moduleName: "Button",
|
|
394
|
+
* filePath: "./Button.svelte"
|
|
395
|
+
* });
|
|
396
|
+
* // { props, slots, events, typedefs, ... }
|
|
397
|
+
* ```
|
|
398
|
+
*/
|
|
399
|
+
parseSvelteComponent(source: string, diagnostics: ComponentParserDiagnostics): ParsedComponent;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
export type SveldDiagnosticKind = "prop-unknown-type" | "context-any-type" | "event-no-source" | "example-compile-error" | "syntax-skipped";
|
|
403
|
+
|
|
404
|
+
export interface SveldDiagnostic {
|
|
405
|
+
/** File this came from, e.g. `"./Button.svelte"`. */
|
|
406
|
+
component: string;
|
|
407
|
+
kind: SveldDiagnosticKind;
|
|
408
|
+
/** Prop, context field, or event name. */
|
|
409
|
+
name: string;
|
|
410
|
+
/** What went wrong and what type sveld used. */
|
|
411
|
+
message: string;
|
|
412
|
+
/** Where in the component source this diagnostic points, when the parser holds a stable position. */
|
|
413
|
+
source?: SourceRange;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
declare const PARSED_COMPONENT_TYPE_SCRIPT_METADATA: unique symbol;
|
|
417
|
+
|
|
418
|
+
export interface ComponentDocApi extends ParsedComponent {
|
|
419
|
+
filePath: NormalizedPath;
|
|
420
|
+
moduleName: string;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
export type ComponentDocs = Map<string, ComponentDocApi>;
|
|
424
|
+
|
|
425
|
+
interface EntryExport {
|
|
426
|
+
name: string;
|
|
427
|
+
kind: "const" | "let" | "var" | "function" | "class" | "type" | "interface" | "enum";
|
|
428
|
+
/** Type text from the source, when present. */
|
|
429
|
+
type?: string;
|
|
430
|
+
/** Initializer text for simple constants. */
|
|
431
|
+
value?: string;
|
|
432
|
+
description?: string;
|
|
433
|
+
/** Declaring module, relative to the entry file. */
|
|
434
|
+
source?: string;
|
|
435
|
+
isTypeOnly: boolean;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
type EntryExports = EntryExport[];
|
|
439
|
+
|
|
440
|
+
export interface CemType {
|
|
441
|
+
text: string;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
export interface CemClassField {
|
|
445
|
+
kind: "field";
|
|
446
|
+
name: string;
|
|
447
|
+
type?: CemType;
|
|
448
|
+
default?: string;
|
|
449
|
+
description?: string;
|
|
450
|
+
deprecated?: DeprecatedValue;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
export interface CemAttribute {
|
|
454
|
+
name: string;
|
|
455
|
+
fieldName: string;
|
|
456
|
+
type?: CemType;
|
|
457
|
+
default?: string;
|
|
458
|
+
description?: string;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
export interface CemEvent {
|
|
462
|
+
name: string;
|
|
463
|
+
type: CemType;
|
|
464
|
+
description?: string;
|
|
465
|
+
deprecated?: DeprecatedValue;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
export interface CemSlot {
|
|
469
|
+
name: string;
|
|
470
|
+
description?: string;
|
|
471
|
+
deprecated?: DeprecatedValue;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
export interface CemClassDeclaration {
|
|
475
|
+
kind: "class";
|
|
476
|
+
name: string;
|
|
477
|
+
description?: string;
|
|
478
|
+
members: CemClassField[];
|
|
479
|
+
attributes: CemAttribute[];
|
|
480
|
+
events: CemEvent[];
|
|
481
|
+
slots: CemSlot[];
|
|
482
|
+
/** Only present when the source component sets `<svelte:options customElement="..." />`. */
|
|
483
|
+
tagName?: string;
|
|
484
|
+
/** Only present when the source component sets `<svelte:options customElement="..." />`. */
|
|
485
|
+
customElement?: true;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
export interface CemJavaScriptExport {
|
|
489
|
+
kind: "js";
|
|
490
|
+
name: string;
|
|
491
|
+
declaration: {
|
|
492
|
+
name: string;
|
|
493
|
+
module: string;
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
export interface CemCustomElementExport {
|
|
498
|
+
kind: "custom-element-definition";
|
|
499
|
+
name: string;
|
|
500
|
+
declaration: {
|
|
501
|
+
name: string;
|
|
502
|
+
module: string;
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
export type CemExport = CemJavaScriptExport | CemCustomElementExport;
|
|
507
|
+
|
|
508
|
+
export interface CemModule {
|
|
509
|
+
kind: "javascript-module";
|
|
510
|
+
path: string;
|
|
511
|
+
declarations: CemClassDeclaration[];
|
|
512
|
+
exports: CemExport[];
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
export interface CustomElementsManifest {
|
|
516
|
+
schemaVersion: "1.0.0";
|
|
517
|
+
modules: CemModule[];
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
export interface BuildCustomElementsManifestOptions {
|
|
521
|
+
/** Resolves each component's manifest `path`. Defaults to the component's `filePath` as-is. */
|
|
522
|
+
resolveModulePath?: (component: ComponentDocApi) => string;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
export declare function buildCustomElementsManifest(components: ComponentDocs, options?: BuildCustomElementsManifestOptions): CustomElementsManifest;
|
|
526
|
+
|
|
527
|
+
type OnAppend = (type: AppendType, document: WriterMarkdown) => void;
|
|
528
|
+
|
|
529
|
+
interface MarkdownOptions {
|
|
530
|
+
onAppend?: OnAppend;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
declare class WriterMarkdown extends Writer {
|
|
534
|
+
onAppend?: OnAppend;
|
|
535
|
+
private markdownBase;
|
|
536
|
+
constructor(options: MarkdownOptions);
|
|
537
|
+
get source(): string;
|
|
538
|
+
get hasToC(): boolean;
|
|
539
|
+
get toc(): TocLine[];
|
|
540
|
+
appendLineBreaks(): this;
|
|
541
|
+
append(type: AppendType, raw?: string): this;
|
|
542
|
+
tableOfContents(): this;
|
|
543
|
+
end(): string;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
export type AppendType = "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "quote" | "p" | "divider" | "raw";
|
|
547
|
+
|
|
548
|
+
export interface TocLine {
|
|
549
|
+
/** Leading space count; 0 for the top-level (`h2`) entries the TOC currently lists. */
|
|
550
|
+
indent: number;
|
|
551
|
+
raw: string;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
export interface MarkdownWriterBase {
|
|
555
|
+
sourceParts: string[];
|
|
556
|
+
hasToC: boolean;
|
|
557
|
+
toc: TocLine[];
|
|
558
|
+
appendLineBreaks(): this;
|
|
559
|
+
append(type: AppendType, raw?: string): this;
|
|
560
|
+
tableOfContents(): this;
|
|
561
|
+
end(): string;
|
|
562
|
+
get source(): string;
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
declare class MarkdownWriterBaseImpl implements MarkdownWriterBase {
|
|
566
|
+
sourceParts: string[];
|
|
567
|
+
hasToC: boolean;
|
|
568
|
+
toc: TocLine[];
|
|
569
|
+
get source(): string;
|
|
570
|
+
appendLineBreaks(): this;
|
|
571
|
+
append(type: AppendType, raw?: string): this;
|
|
572
|
+
tableOfContents(): this;
|
|
573
|
+
end(): string;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
interface WriterOptions {
|
|
577
|
+
/** Report the resolved path to stdout instead of writing. Set by `sveld --dry-run`. */
|
|
578
|
+
dryRun?: boolean;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
declare class Writer {
|
|
582
|
+
private readonly dryRun;
|
|
583
|
+
constructor(options?: WriterOptions);
|
|
584
|
+
/**
|
|
585
|
+
* Skips the write when `filePath` already contains `raw`, so repeated runs
|
|
586
|
+
* over unchanged sources don't touch the file (or its mtime). In dry-run
|
|
587
|
+
* mode, prints `would write "<path>"` to stdout and touches nothing.
|
|
588
|
+
*
|
|
589
|
+
* @returns `true` if the file was written, `false` if it was already up to date.
|
|
590
|
+
*
|
|
591
|
+
* @example
|
|
592
|
+
* ```ts
|
|
593
|
+
* const writer = new Writer();
|
|
594
|
+
* await writer.write("./dist/index.d.ts", "export type Props = {};");
|
|
595
|
+
* ```
|
|
596
|
+
*/
|
|
597
|
+
write(filePath: string, raw: string): Promise<boolean>;
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
export declare function formatTsProps(props?: string): string;
|
|
601
|
+
|
|
602
|
+
export declare function getTypeDefs(def: Pick<ComponentDocApi, "typedefs">): string;
|
|
603
|
+
|
|
604
|
+
export declare function getContextDefs(def: Pick<ComponentDocApi, "contexts" | "generics">): string;
|
|
605
|
+
|
|
606
|
+
export interface WriteTsDefinitionOptions {
|
|
607
|
+
/**
|
|
608
|
+
* `"class"` (default) extends the deprecated `SvelteComponentTyped`.
|
|
609
|
+
* `"component"` emits `declare const X: Component<Props, Exports, Bindings>`
|
|
610
|
+
* instead, for Svelte 5+ consumers. Generic components get a per-component
|
|
611
|
+
* interface with a generic call signature instead of `Component<...>`
|
|
612
|
+
* directly, since a `declare const` can't itself carry a generic type
|
|
613
|
+
* parameter (see `genGenericComponentDeclaration`).
|
|
614
|
+
*/
|
|
615
|
+
format?: "class" | "component";
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
export declare function writeTsDefinition(component: ComponentDocApi, options?: WriteTsDefinitionOptions): string;
|
|
619
|
+
|
|
620
|
+
export declare const COMPONENT_API_SCHEMA_VERSION = 1;
|
|
621
|
+
|
|
622
|
+
export interface ComponentApiDocument {
|
|
623
|
+
schemaVersion: 1;
|
|
624
|
+
generator: {
|
|
625
|
+
name: string;
|
|
626
|
+
version: string;
|
|
627
|
+
svelteVersion: string;
|
|
628
|
+
};
|
|
629
|
+
total: number;
|
|
630
|
+
components: ComponentDocApi[];
|
|
631
|
+
/** Only when `documentExports` is on. */
|
|
632
|
+
totalExports?: number;
|
|
633
|
+
exports?: EntryExports;
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
export interface BuildComponentApiDocumentOptions {
|
|
637
|
+
/** Entry-barrel exports when `documentExports` is on. */
|
|
638
|
+
entryExports?: EntryExports;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
export declare function buildComponentApiDocument(components: ComponentDocs, options?: BuildComponentApiDocumentOptions): ComponentApiDocument;
|
|
642
|
+
|
|
643
|
+
interface MarkdownDocument {
|
|
644
|
+
append(type: AppendType, raw?: string): MarkdownDocument;
|
|
645
|
+
tableOfContents(): MarkdownDocument;
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
export declare function renderComponentsToMarkdown(document: MarkdownDocument, components: ComponentDocs, entryExports?: EntryExports): void;
|
|
649
|
+
|
|
650
|
+
export declare class BrowserWriterMarkdown extends MarkdownWriterBaseImpl {
|
|
651
|
+
onAppend?: OnAppend;
|
|
652
|
+
constructor(options: MarkdownOptions);
|
|
653
|
+
append(type: AppendType, raw?: string): this;
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
export interface WriteMarkdownCoreOptions {
|
|
657
|
+
onAppend?: (type: AppendType, document: BrowserWriterMarkdown, components: ComponentDocs) => void;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
export declare function writeMarkdownCore(components: ComponentDocs, options?: WriteMarkdownCoreOptions): string;
|