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.
Files changed (88) hide show
  1. package/README.md +33 -6
  2. package/lib/browser.d.ts +660 -39
  3. package/lib/browser.js +172 -172
  4. package/lib/chunk-0fqdg2xa.js +20 -0
  5. package/lib/chunk-2vwf7nck.js +1 -0
  6. package/lib/chunk-8myyzjb1.js +4 -0
  7. package/lib/{chunk-v4q9vw0y.js → chunk-as5hgj7e.js} +57 -57
  8. package/lib/{chunk-zva3xjwa.js → chunk-denfbw92.js} +1 -1
  9. package/lib/chunk-h1r040pg.js +6 -0
  10. package/lib/chunk-m538qnhp.js +230 -0
  11. package/lib/chunk-r4rrncmd.js +1 -0
  12. package/lib/{chunk-1p4ka68s.js → chunk-t9d5k3p7.js} +1 -1
  13. package/lib/{chunk-8xw75w8t.js → chunk-tmj7vnjr.js} +2 -2
  14. package/lib/chunk-xryt7ad2.js +3 -0
  15. package/lib/cli-entry.js +1 -1
  16. package/lib/index.d.ts +767 -10
  17. package/lib/index.js +1 -1
  18. package/package.json +1 -1
  19. package/lib/ComponentParser.d.ts +0 -560
  20. package/lib/ast-guards.d.ts +0 -16
  21. package/lib/brands.d.ts +0 -11
  22. package/lib/bundle.d.ts +0 -174
  23. package/lib/check.d.ts +0 -43
  24. package/lib/chunk-72hx9e9w.js +0 -20
  25. package/lib/chunk-7qz0hzgw.js +0 -217
  26. package/lib/chunk-cxrw7gzr.js +0 -2
  27. package/lib/chunk-jdnsv86e.js +0 -1
  28. package/lib/chunk-pmj8c3yv.js +0 -6
  29. package/lib/chunk-s9mzxa4y.js +0 -1
  30. package/lib/chunk-xkrgedm4.js +0 -4
  31. package/lib/cli-entry.d.ts +0 -12
  32. package/lib/cli.d.ts +0 -28
  33. package/lib/create-exports.d.ts +0 -32
  34. package/lib/dependency-graph.d.ts +0 -20
  35. package/lib/diagnostics.d.ts +0 -34
  36. package/lib/element-tag-map.d.ts +0 -146
  37. package/lib/example-check.d.ts +0 -24
  38. package/lib/get-svelte-entry.d.ts +0 -3
  39. package/lib/load-config.d.ts +0 -62
  40. package/lib/parse-cache.d.ts +0 -28
  41. package/lib/parse-entry-exports.d.ts +0 -30
  42. package/lib/parse-exports.d.ts +0 -25
  43. package/lib/parsed-component-metadata.d.ts +0 -13
  44. package/lib/parser/bindings.d.ts +0 -4
  45. package/lib/parser/context.d.ts +0 -72
  46. package/lib/parser/contexts.d.ts +0 -19
  47. package/lib/parser/diagnostics.d.ts +0 -8
  48. package/lib/parser/events.d.ts +0 -21
  49. package/lib/parser/generics.d.ts +0 -24
  50. package/lib/parser/jsdoc.d.ts +0 -55
  51. package/lib/parser/prop-shared.d.ts +0 -84
  52. package/lib/parser/props.d.ts +0 -71
  53. package/lib/parser/rest-props.d.ts +0 -4
  54. package/lib/parser/runes-detection.d.ts +0 -13
  55. package/lib/parser/runes-props.d.ts +0 -18
  56. package/lib/parser/scopes.d.ts +0 -56
  57. package/lib/parser/slots.d.ts +0 -24
  58. package/lib/parser/source-position.d.ts +0 -26
  59. package/lib/parser/type-resolution.d.ts +0 -17
  60. package/lib/parser/typescript-casts.d.ts +0 -1
  61. package/lib/parser/utils.d.ts +0 -1
  62. package/lib/parser/variable-jsdoc.d.ts +0 -12
  63. package/lib/parser-stack.d.ts +0 -20
  64. package/lib/path.d.ts +0 -2
  65. package/lib/plugin.d.ts +0 -85
  66. package/lib/resolve-alias.d.ts +0 -30
  67. package/lib/resolve-types.d.ts +0 -52
  68. package/lib/sveld.d.ts +0 -29
  69. package/lib/svelte-parse.d.ts +0 -4
  70. package/lib/svelte-version.d.ts +0 -1
  71. package/lib/validate.d.ts +0 -13
  72. package/lib/watch.d.ts +0 -34
  73. package/lib/writer/MarkdownWriterBase.d.ts +0 -26
  74. package/lib/writer/Writer.d.ts +0 -31
  75. package/lib/writer/WriterMarkdown.d.ts +0 -31
  76. package/lib/writer/built-in-writers.d.ts +0 -1
  77. package/lib/writer/document-model.d.ts +0 -34
  78. package/lib/writer/format-generated-ts.d.ts +0 -8
  79. package/lib/writer/markdown-format-utils.d.ts +0 -20
  80. package/lib/writer/markdown-render-utils.d.ts +0 -10
  81. package/lib/writer/registry.d.ts +0 -17
  82. package/lib/writer/writer-custom-elements-core.d.ts +0 -86
  83. package/lib/writer/writer-custom-elements.d.ts +0 -15
  84. package/lib/writer/writer-json.d.ts +0 -27
  85. package/lib/writer/writer-markdown-core.d.ts +0 -32
  86. package/lib/writer/writer-markdown.d.ts +0 -23
  87. package/lib/writer/writer-ts-definitions-core.d.ts +0 -30
  88. package/lib/writer/writer-ts-definitions.d.ts +0 -43
package/lib/index.d.ts CHANGED
@@ -1,10 +1,767 @@
1
- export { default as ComponentParser, type SerializedComponentEvent } from "./ComponentParser";
2
- export { type ApiChange, type CheckResult, diffApiDocuments, formatCheckReport, runCheck, type SemverBump, } from "./check";
3
- export { cli } from "./cli";
4
- export type { SveldDiagnostic, SveldDiagnosticKind } from "./diagnostics";
5
- export type { SvelteEntryPoint } from "./get-svelte-entry";
6
- export { defineConfig, type SveldConfig } from "./load-config";
7
- export { default } from "./plugin";
8
- export { sveld } from "./sveld";
9
- export { buildComponentApiDocument, type ComponentApiDocument } from "./writer/document-model";
10
- export { getWriter, listWriters, type OutputWriter, registerWriter } from "./writer/registry";
1
+ /// <reference types="node" />
2
+
3
+ import type { Property } from "estree";
4
+
5
+ import type { Node } from "estree-walker";
6
+
7
+ interface JsDocPassthroughTag {
8
+ name: string;
9
+ body: string;
10
+ }
11
+
12
+ type DeprecatedValue = string | true;
13
+
14
+ interface SourcePosition {
15
+ /** 1-based source line number */
16
+ line: number;
17
+ /** 0-based source column number */
18
+ column: number;
19
+ }
20
+
21
+ interface SourceRange {
22
+ start: SourcePosition;
23
+ end: SourcePosition;
24
+ }
25
+
26
+ interface ParsedComponentTypeScriptMetadata {
27
+ canonicalPropsType?: string;
28
+ canonicalPropNames: string[];
29
+ localTypeDeclarations: string[];
30
+ typeImportStatements: string[];
31
+ /**
32
+ * Whether `canonicalPropsType` mentions one of the component's own
33
+ * `<script generics="...">` parameters (e.g. `Props<T>`). The semantic
34
+ * resolver has no binding for `T`, so `resolveTypes` must leave this
35
+ * component's props as their AST-derived text rather than expand them.
36
+ */
37
+ referencesComponentGenerics?: boolean;
38
+ }
39
+
40
+ type SyntaxMode = "legacy" | "runes";
41
+
42
+ type ScriptLanguage = "js" | "ts";
43
+
44
+ type ComponentPropTypeSource = "typescript" | "jsdoc" | "default" | "inferred" | "unknown";
45
+
46
+ type ComponentPropDefaultValueKind = "literal" | "array" | "object" | "expression" | "function" | "unknown";
47
+
48
+ interface ComponentPropDefaultValue {
49
+ raw: string;
50
+ kind: ComponentPropDefaultValueKind;
51
+ value?: unknown;
52
+ }
53
+
54
+ type ModernScriptAttribute = {
55
+ name?: string;
56
+ value?: Array<{
57
+ data?: string;
58
+ raw?: string;
59
+ }> | boolean;
60
+ start?: number;
61
+ end?: number;
62
+ };
63
+
64
+ type ModernScriptNode = {
65
+ attributes?: ModernScriptAttribute[];
66
+ };
67
+
68
+ interface ComponentParserDiagnostics {
69
+ moduleName: string;
70
+ filePath: string;
71
+ }
72
+
73
+ type ComponentPropBinding = "readonly" | "writable";
74
+
75
+ interface ComponentPropParam {
76
+ /** Parameter name. */
77
+ name: string;
78
+ /** Parameter type (e.g. `"string"`, `"CustomType"`). */
79
+ type: string;
80
+ /** From JSDoc `@param`. */
81
+ description?: string;
82
+ /** True when optional. */
83
+ optional?: boolean;
84
+ }
85
+
86
+ interface ComponentProp {
87
+ /** Public prop name. */
88
+ name: string;
89
+ /** `"let"` (required), `"const"` (default), or `"function"`. */
90
+ kind: "let" | "const" | "function";
91
+ /** True when declared with `const`. */
92
+ constant: boolean;
93
+ /** TypeScript type text. */
94
+ type?: string;
95
+ /** Conservative provenance for the prop type. See the precedence rule on {@link ComponentProp}. */
96
+ typeSource?: ComponentPropTypeSource;
97
+ /** Local binding when it differs from the public name. */
98
+ localName?: string;
99
+ /** Default value as source text; unset when the prop has no initializer/default. */
100
+ value?: string;
101
+ /** Structured default value metadata for docs UIs; set alongside `value` from the same initializer. */
102
+ defaultValue?: ComponentPropDefaultValue;
103
+ /** From JSDoc, or a matching `@typedef`'s own description (legacy only; see {@link ComponentProp}). */
104
+ description?: string;
105
+ /** From JSDoc `@param` on function props. */
106
+ params?: ComponentPropParam[];
107
+ /** From JSDoc `@returns` on function props. */
108
+ returnType?: string;
109
+ /**
110
+ * True for arrow/function-expression initializers and bare `function`
111
+ * declarations in every mode; additionally true for a function-shaped
112
+ * type/JSDoc signature in runes only (see {@link ComponentProp}).
113
+ */
114
+ isFunction: boolean;
115
+ /** True for `function` declarations. */
116
+ isFunctionDeclaration: boolean;
117
+ /** True when declared with `let` and no default. */
118
+ isRequired: boolean;
119
+ /**
120
+ * True when the prop is mutated locally (legacy, inferred from assignment/
121
+ * binding targets) or declared with `$bindable()` (runes).
122
+ */
123
+ reactive: boolean;
124
+ /** Binding direction from `@bindable` JSDoc. */
125
+ binding?: ComponentPropBinding;
126
+ /** True when declared with Svelte 5 `$bindable()` (runes only). */
127
+ bindable?: true;
128
+ /** From `@deprecated` JSDoc. */
129
+ deprecated?: DeprecatedValue;
130
+ /** `@since` / `@example` tags in source order. */
131
+ tags?: JsDocPassthroughTag[];
132
+ /** Source range when available. */
133
+ source?: SourceRange;
134
+ }
135
+
136
+ interface ComponentSlot {
137
+ /** Slot name (`null` for the default slot). */
138
+ name?: string | null;
139
+ /** True for the default slot. */
140
+ default: boolean;
141
+ /** Fallback content when the slot is empty. */
142
+ fallback?: string;
143
+ /** Slot props as TypeScript type text. */
144
+ slot_props?: string;
145
+ /** From JSDoc `@slot` or `@snippet`. */
146
+ description?: string;
147
+ /** From `@deprecated` JSDoc. */
148
+ deprecated?: DeprecatedValue;
149
+ /** Tags between the description and `@slot`/`@snippet` (e.g. `@example`), in source order. */
150
+ tags?: JsDocPassthroughTag[];
151
+ /** Source range when available. */
152
+ source?: SourceRange;
153
+ }
154
+
155
+ interface DispatchedEvent {
156
+ /** Discriminator: `"dispatched"`. */
157
+ type: "dispatched";
158
+ /** Event name. */
159
+ name: string;
160
+ /** Detail type text. */
161
+ detail?: string;
162
+ /** From JSDoc `@event`. */
163
+ description?: string;
164
+ /** From `@deprecated` JSDoc. */
165
+ deprecated?: DeprecatedValue;
166
+ /** `@since` / `@example` tags in source order. */
167
+ tags?: JsDocPassthroughTag[];
168
+ /** Source range when available. */
169
+ source?: SourceRange;
170
+ }
171
+
172
+ interface SerializedForwardedEvent {
173
+ /** Discriminator: `"forwarded"`. */
174
+ type: "forwarded";
175
+ /** Event name. */
176
+ name: string;
177
+ /** Element name as a string for JSON output. */
178
+ element: string;
179
+ /** From JSDoc `@event`. */
180
+ description?: string;
181
+ /** From `@deprecated` JSDoc. */
182
+ deprecated?: DeprecatedValue;
183
+ /** Detail type from `@event`. */
184
+ detail?: string;
185
+ /** `@since` / `@example` tags in source order. */
186
+ tags?: JsDocPassthroughTag[];
187
+ /** Source range when available. */
188
+ source?: SourceRange;
189
+ }
190
+
191
+ export type SerializedComponentEvent = SerializedForwardedEvent | DispatchedEvent;
192
+
193
+ interface TypeDef {
194
+ /** Type text (e.g. `"{ x: number; y: number }"`). */
195
+ type: string;
196
+ /** Type name. */
197
+ name: string;
198
+ /** From JSDoc. */
199
+ description?: string;
200
+ /** Full `type` alias declaration text. */
201
+ ts: string;
202
+ }
203
+
204
+ type ComponentGenerics = [name: string, type: string] | null;
205
+
206
+ interface ComponentInlineElement {
207
+ /** Discriminator: `"InlineComponent"`. */
208
+ type: "InlineComponent";
209
+ /** Component name. */
210
+ name: string;
211
+ }
212
+
213
+ interface ComponentElement {
214
+ type: "Element";
215
+ name: string;
216
+ /**
217
+ * Static tag for `svelte:element this="div"`. Undefined when `this` is dynamic.
218
+ *
219
+ * @example
220
+ * ```svelte
221
+ * <!-- Static tag -->
222
+ * <svelte:element this="div" bind:this={elementRef} />
223
+ * // thisValue: "div"
224
+ *
225
+ * <!-- Dynamic tag -->
226
+ * <svelte:element this={tagName} bind:this={elementRef} />
227
+ * // thisValue: undefined
228
+ * ```
229
+ */
230
+ thisValue?: string;
231
+ /** From `@restProps` JSDoc. */
232
+ description?: string;
233
+ }
234
+
235
+ type RestProps = undefined | ComponentInlineElement | ComponentElement;
236
+
237
+ interface Extends {
238
+ /** Interface name (e.g. `"ButtonProps"`). */
239
+ interface: string;
240
+ /** Import path (e.g. `"./types"`). */
241
+ import: string;
242
+ }
243
+
244
+ interface ComponentContextProp {
245
+ /** Property name. */
246
+ name: string;
247
+ /** Property type text. */
248
+ type: string;
249
+ /** From JSDoc. */
250
+ description?: string;
251
+ /** True when optional. */
252
+ optional: boolean;
253
+ }
254
+
255
+ interface ComponentContext {
256
+ /** Context key from `setContext`. */
257
+ key: string;
258
+ /** Generated type name (e.g. `"ModalContext"`). */
259
+ typeName: string;
260
+ /** From JSDoc. */
261
+ description?: string;
262
+ /** Context object properties. */
263
+ properties: ComponentContextProp[];
264
+ }
265
+
266
+ interface ParsedComponent {
267
+ /** Source range of the parsed file. */
268
+ source?: SourceRange;
269
+ syntaxMode: SyntaxMode;
270
+ scriptLanguage?: ScriptLanguage;
271
+ /** Instance-level props (`export let`/`export function`, or runes `$props()`). See {@link ComponentProp} for the shared IR these are built from. */
272
+ props: ComponentProp[];
273
+ /** Exports from `<script context="module">`. Same {@link ComponentProp} shape as `props`, resolved through the same shared decisions. */
274
+ moduleExports: ComponentProp[];
275
+ slots: ComponentSlot[];
276
+ /** Serialized events for JSON/API output. */
277
+ events: SerializedComponentEvent[];
278
+ typedefs: TypeDef[];
279
+ generics: null | ComponentGenerics;
280
+ rest_props: RestProps;
281
+ extends?: Extends;
282
+ /** From `@component` HTML comment. */
283
+ componentComment?: string;
284
+ componentCommentSource?: SourceRange;
285
+ contexts?: ComponentContext[];
286
+ customElementTag?: string;
287
+ /**
288
+ * Type guesses from this parse (unknown props, `any` contexts, orphan `@event` tags).
289
+ */
290
+ diagnostics?: SveldDiagnostic[];
291
+ /** Writer-only TypeScript metadata. Not serialized to JSON. */
292
+ [PARSED_COMPONENT_TYPE_SCRIPT_METADATA]?: ParsedComponentTypeScriptMetadata;
293
+ }
294
+
295
+ export class ComponentParser {
296
+ /**
297
+ * All per-parse mutable state (props, slots, events, scopes, source, etc.).
298
+ * See {@link ParserContext} for field-by-field documentation. Replaced
299
+ * wholesale by `cleanup()` between parses.
300
+ */
301
+ private ctx;
302
+ private static mapToArray;
303
+ private static getStaticAttributeValue;
304
+ resolveScriptLanguage(parsed: {
305
+ instance?: ModernScriptNode;
306
+ module?: ModernScriptNode;
307
+ }): ScriptLanguage | undefined;
308
+ /**
309
+ * Reads the `generics` attribute off the instance script (Svelte only allows
310
+ * it there, and only alongside `lang="ts"`). Returns the raw value for later
311
+ * precedence resolution against `@generics`/`@template` JSDoc tags, or
312
+ * `undefined` if absent. Records a `syntax-skipped` diagnostic and returns
313
+ * `undefined` if the attribute is present without `lang="ts"`, since sveld
314
+ * can't safely guess how to parse it as plain JavaScript.
315
+ */
316
+ resolveScriptGenericsAttribute(parsed: {
317
+ instance?: ModernScriptNode;
318
+ }): {
319
+ value: string;
320
+ source?: SourceRange;
321
+ } | undefined;
322
+ private resolvePublicPropName;
323
+ trackPropLocalName(propName: string, localName?: string): void;
324
+ private getPropByLocalOrPublic;
325
+ getPropTypeByLocalOrPublic(name: string): string | undefined;
326
+ getExplicitPropType(name: string): string | undefined;
327
+ getPropertyName(node: Property["key"]): string | undefined;
328
+ isNumericConstant(memberExpr: unknown): boolean;
329
+ resolveLocalVarJSDoc(name: string): {
330
+ type?: string;
331
+ params?: ComponentPropParam[];
332
+ returnType?: string;
333
+ description?: string;
334
+ binding?: ComponentPropBinding;
335
+ deprecated?: DeprecatedValue;
336
+ tags?: JsDocPassthroughTag[];
337
+ } | undefined;
338
+ private addModuleExport;
339
+ /**
340
+ * @example
341
+ * ```ts
342
+ * aliasType("*"); // "any"
343
+ * aliasType(" string "); // "string"
344
+ * ```
345
+ */
346
+ aliasType(type: string): string;
347
+ /**
348
+ * @example
349
+ * ```ts
350
+ * // Given:
351
+ * // /**
352
+ * // * @type {number}
353
+ * // * The count value
354
+ * // *\/
355
+ * // const count = 0;
356
+ *
357
+ * findVariableTypeAndDescription("count");
358
+ * // { type: "number", description: "The count value" }
359
+ * ```
360
+ */
361
+ findVariableTypeAndDescription(varName: string): {
362
+ type: string;
363
+ description?: string;
364
+ } | null;
365
+ accumulateGeneric(name: string, constraint: string): void;
366
+ /**
367
+ * Resets parser state for reuse between parses.
368
+ *
369
+ * @example
370
+ * ```ts
371
+ * parser.parseSvelteComponent(source1, diagnostics1);
372
+ * parser.cleanup();
373
+ * parser.parseSvelteComponent(source2, diagnostics2);
374
+ * ```
375
+ */
376
+ cleanup(): void;
377
+ private static readonly SCRIPT_BLOCK_REGEX;
378
+ private static readonly TS_DIRECTIVE_REGEX;
379
+ private static stripTypeScriptDirectivesFromScripts;
380
+ /**
381
+ * @example
382
+ * ```ts
383
+ * const parser = new ComponentParser();
384
+ * const result = parser.parseSvelteComponent(source, {
385
+ * moduleName: "Button",
386
+ * filePath: "./Button.svelte"
387
+ * });
388
+ * // { props, slots, events, typedefs, ... }
389
+ * ```
390
+ */
391
+ parseSvelteComponent(source: string, diagnostics: ComponentParserDiagnostics): ParsedComponent;
392
+ }
393
+
394
+ export type SveldDiagnosticKind = "prop-unknown-type" | "context-any-type" | "event-no-source" | "example-compile-error" | "syntax-skipped";
395
+
396
+ export interface SveldDiagnostic {
397
+ /** File this came from, e.g. `"./Button.svelte"`. */
398
+ component: string;
399
+ kind: SveldDiagnosticKind;
400
+ /** Prop, context field, or event name. */
401
+ name: string;
402
+ /** What went wrong and what type sveld used. */
403
+ message: string;
404
+ /** Where in the component source this diagnostic points, when the parser holds a stable position. */
405
+ source?: SourceRange;
406
+ }
407
+
408
+ declare const PARSED_COMPONENT_TYPE_SCRIPT_METADATA: unique symbol;
409
+
410
+ export type SemverBump = "major" | "minor" | "patch" | "none";
411
+
412
+ export interface ApiChange {
413
+ /** Component `moduleName` this change belongs to, or `"*"` for document-wide notices. */
414
+ component: string;
415
+ kind: "component" | "prop" | "moduleExport" | "event" | "slot" | "shape";
416
+ /** Prop, event, slot, or shape-field name, when applicable. */
417
+ name?: string;
418
+ bump: SemverBump;
419
+ message: string;
420
+ }
421
+
422
+ export interface CheckResult {
423
+ /** `false` when there was nothing on disk to diff against (e.g. first run). */
424
+ snapshotExists: boolean;
425
+ snapshotFile: string;
426
+ changes: ApiChange[];
427
+ /** Highest bump across all changes. */
428
+ bump: SemverBump;
429
+ }
430
+
431
+ export declare function diffApiDocuments(previous: ComponentApiDocument, next: ComponentApiDocument): ApiChange[];
432
+
433
+ interface RunCheckOptions {
434
+ /** Entry-barrel exports when `documentExports` is on. */
435
+ entryExports?: EntryExports;
436
+ }
437
+
438
+ export declare function runCheck(components: ComponentDocs, snapshotFile: string, options?: RunCheckOptions): Promise<CheckResult>;
439
+
440
+ export declare function formatCheckReport(result: CheckResult): string;
441
+
442
+ export type CheckReportJson = CheckResult & {
443
+ kind: "check-report";
444
+ };
445
+
446
+ export declare function formatCheckReportJson(result: CheckResult): string;
447
+
448
+ interface ComponentDocApi extends ParsedComponent {
449
+ filePath: NormalizedPath;
450
+ moduleName: string;
451
+ }
452
+
453
+ type ComponentDocs = Map<string, ComponentDocApi>;
454
+
455
+ interface GenerateBundleOptions {
456
+ /**
457
+ * Throw on the first component that fails to parse instead of collecting
458
+ * the failure and continuing with the remaining components.
459
+ */
460
+ failFast?: boolean;
461
+ /**
462
+ * Load the TypeScript program to expand opaque imported whole-object `$props()`
463
+ * types into JSON/Markdown props. Off by default; requires `typescript`.
464
+ */
465
+ resolveTypes?: boolean;
466
+ /** Record consts, functions, and types from the entry barrel. Off by default. */
467
+ documentExports?: boolean;
468
+ /**
469
+ * Cache parsed component output to disk. Unchanged files skip re-parsing on
470
+ * later runs. On by default, writing to
471
+ * `node_modules/.cache/sveld/parse-cache.json`; a string sets a custom path.
472
+ * Pass `false` to disable.
473
+ */
474
+ cache?: boolean | string;
475
+ /**
476
+ * Run plain TS/JS `@example` blocks on props, module exports, slots, and
477
+ * events through the TypeScript program. Broken examples become
478
+ * `example-compile-error` diagnostics. Svelte/HTML markup is skipped.
479
+ * Off by default. Requires `typescript`.
480
+ */
481
+ checkExamples?: boolean;
482
+ /**
483
+ * Parse as usual (so cache reads and real errors still apply) but skip
484
+ * persisting the parse cache to disk. Set by the CLI's `--dry-run`.
485
+ */
486
+ dryRun?: boolean;
487
+ }
488
+
489
+ declare const brand: unique symbol;
490
+
491
+ type Brand<TBase extends string, TBrand extends string> = TBase & {
492
+ readonly [brand]: TBrand;
493
+ };
494
+
495
+ export type SvelteEntryPoint = Brand<string, "SvelteEntryPoint">;
496
+
497
+ type NormalizedPath = Brand<string, "NormalizedPath">;
498
+
499
+ type RelativeSourcePath = Brand<string, "RelativeSourcePath">;
500
+
501
+ interface EntryExport {
502
+ name: string;
503
+ kind: "const" | "let" | "var" | "function" | "class" | "type" | "interface" | "enum";
504
+ /** Type text from the source, when present. */
505
+ type?: string;
506
+ /** Initializer text for simple constants. */
507
+ value?: string;
508
+ description?: string;
509
+ /** Declaring module, relative to the entry file. */
510
+ source?: string;
511
+ isTypeOnly: boolean;
512
+ }
513
+
514
+ type EntryExports = EntryExport[];
515
+
516
+ type ParsedExports = Record<string, {
517
+ source: RelativeSourcePath;
518
+ default: boolean;
519
+ mixed?: boolean;
520
+ }>;
521
+
522
+ interface SveldRuntimeOptions extends PluginSveldOptions {
523
+ /** Print unresolved-type diagnostics to stderr. */
524
+ reportDiagnostics?: boolean;
525
+ /** Exit code 1 when diagnostics exist. Implies `reportDiagnostics`. */
526
+ strict?: boolean;
527
+ /**
528
+ * Diff the parsed component API against a committed snapshot (default:
529
+ * the `json` writer's `outFile`, or `COMPONENT_API.json`) and assign a
530
+ * semver bump to each change. Exits `1` on a breaking change. Pass a
531
+ * string for a custom snapshot path.
532
+ */
533
+ check?: boolean | string;
534
+ /** Suppress writer progress logs (`created "..."` / `unchanged "..."`). */
535
+ quiet?: boolean;
536
+ /**
537
+ * Print the single selected `json` / `markdown` / `customElements` document
538
+ * to stdout instead of writing it to disk. Requires exactly one of those
539
+ * three outputs; CLI-only (the Vite plugin ignores it). `"ndjson"` is only
540
+ * valid with `json` and prints one minified JSON object per component per
541
+ * line instead of the single combined document.
542
+ */
543
+ stdout?: boolean | "json" | "ndjson";
544
+ /**
545
+ * Output format for the `--check` report and the `--report-diagnostics` /
546
+ * `--strict` diagnostics summary: `"text"` (default) or `"json"`. Channels
547
+ * are unchanged, the check report on stdout and diagnostics on stderr.
548
+ */
549
+ format?: "text" | "json";
550
+ /**
551
+ * Resolve the entry, load config, and parse components as usual, but print
552
+ * `would write "<path>"` for each output file to stdout instead of writing
553
+ * it (including the parse cache). CLI-only; the Vite plugin ignores it.
554
+ */
555
+ dryRun?: boolean;
556
+ }
557
+
558
+ export type SveldConfig = SveldRuntimeOptions;
559
+
560
+ export declare function defineConfig(config: SveldConfig): SveldConfig;
561
+
562
+ interface PluginSveldOptions extends Pick<GenerateBundleOptions, "resolveTypes" | "cache" | "checkExamples"> {
563
+ /**
564
+ * Specify the entry point to uncompiled Svelte source.
565
+ * If not provided, sveld will use the "svelte" field from package.json.
566
+ */
567
+ entry?: string;
568
+ glob?: boolean;
569
+ /** Record consts, functions, and types from the entry barrel. Off by default. */
570
+ documentExports?: boolean;
571
+ types?: boolean;
572
+ typesOptions?: Partial<Omit<WriteTsDefinitionsOptions, "inputDir">>;
573
+ json?: boolean;
574
+ jsonOptions?: Partial<Omit<WriteJsonOptions, "inputDir">>;
575
+ markdown?: boolean;
576
+ markdownOptions?: Partial<WriteMarkdownOptions>;
577
+ /** Generate a Custom Elements Manifest (`custom-elements.json`, schemaVersion "1.0.0"). */
578
+ customElements?: boolean;
579
+ customElementsOptions?: Partial<Omit<WriteCustomElementsOptions, "inputDir">>;
580
+ /**
581
+ * Run additional, userland-registered writers (via `registerWriter` from
582
+ * "sveld") beyond the built-in `json`/`markdown`/`types` outputs. Keyed by
583
+ * the writer's registered `name`, valued by that writer's options.
584
+ */
585
+ additionalWriters?: Record<string, unknown>;
586
+ /**
587
+ * Abort the entire run when a single component fails to parse.
588
+ * When `false` (the default), parse failures are collected as diagnostics
589
+ * and the remaining components still emit their output.
590
+ */
591
+ failFast?: boolean;
592
+ /**
593
+ * Regenerate output incrementally when `.svelte` source changes during
594
+ * `vite dev` / `vite build --watch`. Only the changed component and the
595
+ * components that depend on it via `@extendProps` / `@extends` are re-parsed.
596
+ * @default false
597
+ */
598
+ watch?: boolean;
599
+ }
600
+
601
+ interface HotUpdateContext {
602
+ file: string;
603
+ }
604
+
605
+ interface SveldPlugin {
606
+ name: string;
607
+ apply?: "build" | "serve";
608
+ enforce?: "pre" | "post";
609
+ buildStart(): void | Promise<void>;
610
+ generateBundle(): Promise<void>;
611
+ writeBundle(): Promise<void>;
612
+ /** Vite dev-server HMR hook (serve mode). */
613
+ handleHotUpdate?(ctx: HotUpdateContext): void;
614
+ /** Rollup/Vite watch hook (build `--watch`). */
615
+ watchChange?(id: string): void;
616
+ }
617
+
618
+ export default function pluginSveld(opts?: PluginSveldOptions): SveldPlugin;
619
+
620
+ interface WriteCustomElementsOptions {
621
+ inputDir: string;
622
+ outFile: string;
623
+ /** Report the resolved path instead of writing. Set by `sveld --dry-run`. */
624
+ dryRun?: boolean;
625
+ }
626
+
627
+ interface WriteJsonOptions {
628
+ input: string;
629
+ inputDir: string;
630
+ outFile: string;
631
+ outDir?: string;
632
+ /** Entry-barrel exports when `documentExports` is on. */
633
+ entryExports?: EntryExports;
634
+ /** Report resolved paths instead of writing. Set by `sveld --dry-run`. */
635
+ dryRun?: boolean;
636
+ }
637
+
638
+ interface WriteMarkdownOptions {
639
+ write?: boolean;
640
+ outFile: string;
641
+ /** Entry-barrel exports when `documentExports` is on. */
642
+ entryExports?: EntryExports;
643
+ onAppend?: (type: AppendType, document: WriterMarkdown, components: ComponentDocs) => void;
644
+ /** Report the resolved path instead of writing. Set by `sveld --dry-run`. */
645
+ dryRun?: boolean;
646
+ }
647
+
648
+ type OnAppend = (type: AppendType, document: WriterMarkdown) => void;
649
+
650
+ interface MarkdownOptions {
651
+ onAppend?: OnAppend;
652
+ }
653
+
654
+ declare class WriterMarkdown extends Writer {
655
+ onAppend?: OnAppend;
656
+ private markdownBase;
657
+ constructor(options: MarkdownOptions);
658
+ get source(): string;
659
+ get hasToC(): boolean;
660
+ get toc(): TocLine[];
661
+ appendLineBreaks(): this;
662
+ append(type: AppendType, raw?: string): this;
663
+ tableOfContents(): this;
664
+ end(): string;
665
+ }
666
+
667
+ type AppendType = "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "quote" | "p" | "divider" | "raw";
668
+
669
+ interface TocLine {
670
+ /** Leading space count; 0 for the top-level (`h2`) entries the TOC currently lists. */
671
+ indent: number;
672
+ raw: string;
673
+ }
674
+
675
+ interface WriterOptions {
676
+ /** Report the resolved path to stdout instead of writing. Set by `sveld --dry-run`. */
677
+ dryRun?: boolean;
678
+ }
679
+
680
+ declare class Writer {
681
+ private readonly dryRun;
682
+ constructor(options?: WriterOptions);
683
+ /**
684
+ * Skips the write when `filePath` already contains `raw`, so repeated runs
685
+ * over unchanged sources don't touch the file (or its mtime). In dry-run
686
+ * mode, prints `would write "<path>"` to stdout and touches nothing.
687
+ *
688
+ * @returns `true` if the file was written, `false` if it was already up to date.
689
+ *
690
+ * @example
691
+ * ```ts
692
+ * const writer = new Writer();
693
+ * await writer.write("./dist/index.d.ts", "export type Props = {};");
694
+ * ```
695
+ */
696
+ write(filePath: string, raw: string): Promise<boolean>;
697
+ }
698
+
699
+ interface WriteTsDefinitionsOptions extends WriteTsDefinitionOptions {
700
+ outDir: string;
701
+ inputDir: string;
702
+ preamble: string;
703
+ exports: ParsedExports;
704
+ /** Report resolved paths instead of writing. Set by `sveld --dry-run`. */
705
+ dryRun?: boolean;
706
+ }
707
+
708
+ interface WriteTsDefinitionOptions {
709
+ /**
710
+ * `"class"` (default) extends the deprecated `SvelteComponentTyped`.
711
+ * `"component"` emits `declare const X: Component<Props, Exports, Bindings>`
712
+ * instead, for Svelte 5+ consumers. Generic components get a per-component
713
+ * interface with a generic call signature instead of `Component<...>`
714
+ * directly, since a `declare const` can't itself carry a generic type
715
+ * parameter (see `genGenericComponentDeclaration`).
716
+ */
717
+ format?: "class" | "component";
718
+ }
719
+
720
+ export interface ComponentApiDocument {
721
+ schemaVersion: 1;
722
+ generator: {
723
+ name: string;
724
+ version: string;
725
+ svelteVersion: string;
726
+ };
727
+ total: number;
728
+ components: ComponentDocApi[];
729
+ /** Only when `documentExports` is on. */
730
+ totalExports?: number;
731
+ exports?: EntryExports;
732
+ }
733
+
734
+ interface BuildComponentApiDocumentOptions {
735
+ /** Entry-barrel exports when `documentExports` is on. */
736
+ entryExports?: EntryExports;
737
+ }
738
+
739
+ export declare function buildComponentApiDocument(components: ComponentDocs, options?: BuildComponentApiDocumentOptions): ComponentApiDocument;
740
+
741
+ export declare function cli(process: NodeJS.Process): Promise<void>;
742
+
743
+ type SveldOptions = SveldRuntimeOptions;
744
+
745
+ interface SveldResult {
746
+ /** Diagnostics from this run. */
747
+ diagnostics: SveldDiagnostic[];
748
+ /** Populated when `check` is enabled: the API diff against the committed snapshot. */
749
+ check?: CheckResult;
750
+ }
751
+
752
+ export declare function sveld(opts?: SveldOptions): Promise<SveldResult>;
753
+
754
+ type WriterComponentSet = "exported" | "all";
755
+
756
+ export interface OutputWriter<TOptions = unknown> {
757
+ name: string;
758
+ /** Which component set this writer expects. @default "exported" */
759
+ componentSet?: WriterComponentSet;
760
+ write(components: ComponentDocs, options: TOptions): Promise<unknown> | unknown;
761
+ }
762
+
763
+ export declare function registerWriter<TOptions = unknown>(writer: OutputWriter<TOptions>): void;
764
+
765
+ export declare function getWriter(name: string): OutputWriter<unknown> | undefined;
766
+
767
+ export declare function listWriters(): OutputWriter<unknown>[];