sveld 0.36.8 → 0.36.10

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