sveld 0.36.10 → 0.36.11

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 CHANGED
@@ -141,18 +141,28 @@ export default class Button extends SvelteComponentTyped<
141
141
  - [JSON Output](#json-output)
142
142
  - [Custom Elements Manifest](#custom-elements-manifest)
143
143
  - [Consuming the manifest](#consuming-the-manifest)
144
+ - [Custom Writers](#custom-writers)
145
+ - [The `OutputWriter` contract](#the-outputwriter-contract)
146
+ - [Registering a writer](#registering-a-writer)
147
+ - [Running it via the plugin](#running-it-via-the-plugin)
148
+ - [Worked example: a minimal `llms.txt` writer](#worked-example-a-minimal-llmstxt-writer)
144
149
  - [API Reference](#api-reference)
145
150
  - [reactive](#reactive)
146
151
  - [binding](#binding)
147
152
  - [@type](#type)
148
153
  - [@default](#default)
149
154
  - [@typedef](#typedef)
155
+ - [@property](#property)
150
156
  - [@callback](#callback)
151
157
  - [@slot / @snippet](#slot--snippet)
152
158
  - [Extra JSDoc tags before `@slot`](#extra-jsdoc-tags-before-slot)
153
159
  - [Svelte 5 Snippet Compatibility](#svelte-5-snippet-compatibility)
154
160
  - [@event](#event)
155
161
  - [@deprecated](#deprecated)
162
+ - [@since](#since)
163
+ - [@see](#see)
164
+ - [@link](#link)
165
+ - [@example](#example)
156
166
  - [Context API](#context-api)
157
167
  - [@restProps](#restprops)
158
168
  - [@extendProps](#extendprops)
@@ -708,14 +718,22 @@ The `svelte` condition lets bundlers that understand it (Vite, Rollup, webpack v
708
718
  - **`glob`** (boolean, optional): Enable glob mode to analyze all `*.svelte` files.
709
719
  - **`documentExports`** (boolean, optional): Include consts, functions, and types from the entry barrel in JSON (`exports`) and Markdown ("Exports"). Off by default. See [Documenting Entry Exports](#documenting-entry-exports).
710
720
  - **`types`** (boolean, optional, default: `true`): Generate TypeScript definitions.
711
- - **`typesOptions`** (object, optional): Options for TypeScript definition generation, including `outDir`, `preamble`, and `format`.
721
+ - **`typesOptions`** (object, optional): Options for TypeScript definition generation.
722
+ - **`outDir`** (string, optional, default: `"types"`): Output directory for generated `.d.ts` files, relative to the project root.
723
+ - **`preamble`** (string, optional, default: `""`): Raw text prepended to the top of the generated `index.d.ts` barrel file, before the `export * from "./..."` lines. Useful for license headers or lint-disable comments. See [`typesOptions.preamble`](#typesoptionspreamble) below.
712
724
  - **`format`** (`"class"` | `"component"`, optional, default: `"class"`): `.d.ts` output shape. `"class"` extends `SvelteComponentTyped`; `"component"` emits the Svelte 5 `Component` type. Also available as `--types-format`. See [`.d.ts` output format](#dts-output-format-typesoptionsformat).
713
725
  - **`json`** (boolean, optional): Generate component documentation in JSON format.
714
726
  - **`jsonOptions`** (object, optional): Options for JSON output.
727
+ - **`outFile`** (string, optional, default: `"COMPONENT_API.json"`): Path (relative to the project root) for the single combined JSON document. Ignored when `outDir` is set.
728
+ - **`outDir`** (string, optional): Emit one JSON file per component (`<ComponentName>.api.json`) into this directory instead of a single combined file. See [`jsonOptions.outDir`](#jsonoptionsoutdir).
715
729
  - **`markdown`** (boolean, optional): Generate component documentation in Markdown format.
716
730
  - **`markdownOptions`** (object, optional): Options for Markdown output.
731
+ - **`outFile`** (string, optional, default: `"COMPONENT_INDEX.md"`): Path (relative to the project root) for the generated Markdown file.
732
+ - **`write`** (boolean, optional, default: `true`): Set to `false` to render the Markdown document without writing it to disk.
733
+ - **`onAppend`** (function, optional): Callback invoked every time a heading, quote, paragraph, divider, or raw block is appended to the document. Lets you inject extra content, e.g. a summary line under the title. See [`markdownOptions.onAppend`](#markdownoptionsonappend) below.
717
734
  - **`customElements`** (boolean, optional): Generate a [Custom Elements Manifest](#custom-elements-manifest) (`custom-elements.json`). Also available as the `--custom-elements` CLI flag.
718
- - **`customElementsOptions`** (object, optional): Options for Custom Elements Manifest output, including `outFile`.
735
+ - **`customElementsOptions`** (object, optional): Options for Custom Elements Manifest output.
736
+ - **`outFile`** (string, optional, default: `"custom-elements.json"`): Path (relative to the project root) for the generated manifest file.
719
737
  - **`watch`** (boolean, optional, default: `false`): Regenerate output incrementally when `.svelte` source changes during `vite dev` / `vite build --watch`. Only the changed component and the components that depend on it via [`@extendProps`](#extendprops) / `@extends` are re-parsed, rather than rebuilding every component. Without this option, the plugin only runs during `vite build`.
720
738
  - **`failFast`** (boolean, optional, default: `false`): Abort the entire run when a single component fails to parse. By default, parse failures are collected as diagnostics (and reported to `stderr`) so the remaining components still emit their output. Also available as the `--fail-fast` CLI flag.
721
739
  - **`resolveTypes`** (boolean, optional, default: `false`): Load the TypeScript program to expand opaque imported whole-object `$props()` types into JSON. Also available as `--resolve-types` (`--resolveTypes` remains as a deprecated alias). See [Opt-in semantic resolution](#opt-in-semantic-resolution-resolvetypes).
@@ -738,6 +756,56 @@ sveld({
738
756
  })
739
757
  ```
740
758
 
759
+ #### `typesOptions.preamble`
760
+
761
+ Use `typesOptions.preamble` to prepend raw text to the generated `types/index.d.ts` barrel file — for example, a license header that should ship with every published `.d.ts` file.
762
+
763
+ ```js
764
+ sveld({
765
+ types: true,
766
+ typesOptions: {
767
+ preamble: "// Copyright (c) 2026 Acme Inc. All rights reserved.\n\n",
768
+ },
769
+ });
770
+ ```
771
+
772
+ ```ts
773
+ // types/index.d.ts
774
+ // Copyright (c) 2026 Acme Inc. All rights reserved.
775
+
776
+ export { default as Button } from "./Button.svelte";
777
+ ```
778
+
779
+ `preamble` only affects the barrel file (`index.d.ts`); per-component `.d.ts` files are untouched.
780
+
781
+ #### `markdownOptions.onAppend`
782
+
783
+ `markdownOptions.onAppend` fires on every heading, quote, paragraph, divider, and raw block written to the Markdown document, and receives the block's `type`, the in-progress `WriterMarkdown` document, and the full component map. Use it to inject extra content, e.g. a summary line under the `h1` title.
784
+
785
+ ```js
786
+ import pkg from "./package.json" with { type: "json" };
787
+
788
+ sveld({
789
+ markdown: true,
790
+ markdownOptions: {
791
+ onAppend: (type, document, components) => {
792
+ if (type === "h1") {
793
+ document.append(
794
+ "quote",
795
+ `${components.size} components exported from ${pkg.name}@${pkg.version}.`,
796
+ );
797
+ }
798
+ },
799
+ },
800
+ });
801
+ ```
802
+
803
+ ```md
804
+ # Component Index
805
+
806
+ > 1 components exported from sveld-scratch@1.0.0.
807
+ ```
808
+
741
809
  ## Documenting Entry Exports
742
810
 
743
811
  Most entry barrels re-export more than `.svelte` components. Set `documentExports: true` to add consts, functions, and types to the JSON and Markdown output.
@@ -931,6 +999,139 @@ With that in place:
931
999
  - [Storybook](https://storybook.js.org/docs/api/doc-blocks/doc-block-argtypes#extracting-argtypes) for web components reads the manifest to auto-generate `argTypes` (controls, docs tables) for `customElement`-compiled components, once you point it at the file (e.g. `setCustomElementsManifest` from `@storybook/web-components`, or `customElements: "custom-elements.json"` in `.storybook/main.js`).
932
1000
  - Any other tool built against the [Custom Elements Manifest spec](https://github.com/webcomponents/custom-elements-manifest) (API viewers, doc generators, linters) can read the file directly without sveld-specific integration.
933
1001
 
1002
+ ## Custom Writers
1003
+
1004
+ `json`, `markdown`, `types`, and `custom-elements` are all built on the same
1005
+ extensibility point: a small writer registry that third parties can use to
1006
+ add new output formats without a core PR. This is a stable, public part of
1007
+ sveld's API — the four built-in writers register through it in
1008
+ `src/writer/built-in-writers.ts`, there is no separate "internal" path.
1009
+
1010
+ ### The `OutputWriter` contract
1011
+
1012
+ ```ts
1013
+ interface OutputWriter<TOptions = unknown> {
1014
+ name: string;
1015
+ /** Which component set this writer expects. @default "exported" */
1016
+ componentSet?: "exported" | "all";
1017
+ write(components: ComponentDocs, options: TOptions): Promise<unknown> | unknown;
1018
+ }
1019
+ ```
1020
+
1021
+ - **`name`** is how the plugin's `additionalWriters` option (and anything else
1022
+ that calls `getWriter`) looks the writer up. Pick something that won't
1023
+ collide with `types` / `json` / `markdown` / `custom-elements` or another
1024
+ third-party writer.
1025
+ - **`componentSet`** picks which map `write` receives:
1026
+ - `"exported"` (the default) — components reachable from the entry barrel,
1027
+ keyed by `moduleName`. This is what `json` / `markdown` /
1028
+ `custom-elements` use.
1029
+ - `"all"` — every `--glob`-discovered `.svelte` file, keyed by resolved
1030
+ `filePath` instead of `moduleName` (two files in different directories
1031
+ can share a basename). This is what `types` uses.
1032
+ - **`write`** receives a `ComponentDocs` (`Map<string, ComponentDocApi>`) —
1033
+ the same `ComponentDocApi` shape documented in [JSON Output](#json-output).
1034
+ Don't iterate the raw map yourself; call `buildComponentApiDocument(components, { entryExports })`
1035
+ (also exported from `sveld`) to get the sorted, `diagnostics`-stripped,
1036
+ schema-versioned document the built-in writers build from. It's memoized
1037
+ per `components` map, so calling it more than once in one run is free.
1038
+
1039
+ ### Registering a writer
1040
+
1041
+ ```ts
1042
+ import { registerWriter } from "sveld";
1043
+
1044
+ registerWriter({
1045
+ name: "my-format",
1046
+ write(components, options) {
1047
+ // ...
1048
+ },
1049
+ });
1050
+ ```
1051
+
1052
+ `registerWriter` is a side effect — call it once, before the plugin or CLI
1053
+ runs, e.g. at the top of `vite.config.ts` or `sveld.config.ts`, or in a file
1054
+ either of those imports.
1055
+
1056
+ ### Running it via the plugin
1057
+
1058
+ ```ts
1059
+ // vite.config.ts
1060
+ import sveld from "sveld";
1061
+ import "./writers/my-format"; // calls registerWriter as a side effect
1062
+
1063
+ export default {
1064
+ plugins: [
1065
+ sveld({
1066
+ additionalWriters: {
1067
+ "my-format": { outFile: "MY_FORMAT.txt" },
1068
+ },
1069
+ }),
1070
+ ],
1071
+ };
1072
+ ```
1073
+
1074
+ `additionalWriters` is keyed by the writer's registered `name`; the value is
1075
+ whatever options object that writer's `write` expects. An unknown name logs a
1076
+ warning and is skipped rather than failing the build. Registered writers run
1077
+ alongside whichever built-in outputs (`types` / `json` / `markdown` /
1078
+ `customElements`) are also enabled, and the same option is available from the
1079
+ programmatic Node API and from `sveld.config.ts` (`additionalWriters` lives on
1080
+ the options shared by all three entry points).
1081
+
1082
+ ### Worked example: a minimal `llms.txt` writer
1083
+
1084
+ A plain-text, one-file-per-library summary — the kind of thing
1085
+ [llms.txt](https://llmstxt.org)-aware tools look for — is a good demo because
1086
+ it needs nothing beyond `ComponentApiDocument`.
1087
+
1088
+ ```ts
1089
+ // writers/llms-writer.ts
1090
+ import { writeFileSync } from "node:fs";
1091
+ import { join } from "node:path";
1092
+ import { buildComponentApiDocument, registerWriter } from "sveld";
1093
+
1094
+ interface LlmsWriterOptions {
1095
+ outFile?: string;
1096
+ }
1097
+
1098
+ registerWriter<LlmsWriterOptions>({
1099
+ name: "llms-demo",
1100
+ componentSet: "exported",
1101
+ write(components, options = {}) {
1102
+ const document = buildComponentApiDocument(components);
1103
+
1104
+ const sections = document.components.map((component) => {
1105
+ const props = component.props.map((prop) => `${prop.name}: ${prop.type ?? "unknown"}`).join(", ");
1106
+ return `## ${component.moduleName}\n\nProps: ${props || "none"}`;
1107
+ });
1108
+
1109
+ const rendered = ["# My Library", "", "> Auto-generated component reference.", "", ...sections].join("\n\n");
1110
+
1111
+ writeFileSync(join(process.cwd(), options.outFile ?? "llms.txt"), rendered);
1112
+ },
1113
+ });
1114
+ ```
1115
+
1116
+ ```ts
1117
+ // vite.config.ts
1118
+ import sveld from "sveld";
1119
+ import "./writers/llms-writer";
1120
+
1121
+ export default {
1122
+ plugins: [
1123
+ sveld({
1124
+ additionalWriters: {
1125
+ "llms-demo": { outFile: "llms.txt" },
1126
+ },
1127
+ }),
1128
+ ],
1129
+ };
1130
+ ```
1131
+
1132
+ Running a build now produces an `llms.txt` alongside the usual output, with
1133
+ one section per exported component.
1134
+
934
1135
  ## API Reference
935
1136
 
936
1137
  ### `reactive`
@@ -1299,7 +1500,7 @@ The `@typedef` tag defines a shared type used multiple times in a component. All
1299
1500
 
1300
1501
  #### Using `@property` for complex typedefs
1301
1502
 
1302
- For complex object types, use `@property` to document individual fields. That gives per-property tooltips in the IDE.
1503
+ For complex object types, use `@property` to document individual fields. That gives per-property tooltips in the IDE. See the [`@property`](#property) reference for the tag's valid contexts.
1303
1504
 
1304
1505
  **Signature:**
1305
1506
 
@@ -1696,6 +1897,35 @@ function render(value: unknown, props: ComponentProps) {
1696
1897
  }
1697
1898
  ```
1698
1899
 
1900
+ ### `@property`
1901
+
1902
+ `@property` documents one field of an object. `sveld` only reads it in two places: directly inside a `@typedef {object}` block, and directly inside an `@event` block (after an explicit `@type {object}`, or with no `@type` at all — `sveld` builds the detail type from the collected `@property` entries). It has no effect anywhere else.
1903
+
1904
+ **Valid contexts:**
1905
+
1906
+ | Context | Behavior |
1907
+ | :- | :- |
1908
+ | After `@typedef {object} Name`, in the same comment block | Builds `Name`'s fields. See [Using `@property` for complex typedefs](#using-property-for-complex-typedefs). |
1909
+ | After `@event eventname`, in the same comment block | Builds the event's detail type. See [Using `@property` for complex event details](#using-property-for-complex-event-details). |
1910
+ | A plain prop with no `@typedef`/`@type {object}` | Not structured. Folded into the prop's description as literal text (`@property name - description`). |
1911
+ | Before a `@slot` / `@snippet` line | Dropped entirely — no structured output, and unlike other unrecognized tags in that position, it is not folded into the slot's description either. |
1912
+ | Inside `@callback` | Not read. Use `@param` for callback parameters instead. |
1913
+
1914
+ **Signature:**
1915
+
1916
+ ```js
1917
+ /**
1918
+ * @typedef {object} TypeName
1919
+ * @property {Type} propertyName - Property description
1920
+ *
1921
+ * @event eventname
1922
+ * @type {object}
1923
+ * @property {Type} propertyName - Property description
1924
+ */
1925
+ ```
1926
+
1927
+ Both forms support the same modifiers as typedef properties elsewhere in this doc: optional properties (`[name]`), default values (`[name=value]`), and nested/discriminated-union shapes. See the linked sections above for full signatures and worked examples with generated output.
1928
+
1699
1929
  ### `@callback`
1700
1930
 
1701
1931
  The `@callback` tag defines a function type with `@param` and `@returns`, following the [TypeScript JSDoc `@callback` spec](https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html#callback). Like `@typedef`, callbacks are exported from the generated `.d.ts`.
@@ -2083,7 +2313,7 @@ export default class Component extends SvelteComponentTyped<
2083
2313
 
2084
2314
  #### Using `@property` for complex event details
2085
2315
 
2086
- For events with complex object payloads, use `@property` to document individual fields. The main comment becomes the event description.
2316
+ For events with complex object payloads, use `@property` to document individual fields. The main comment becomes the event description. See the [`@property`](#property) reference for the tag's valid contexts.
2087
2317
 
2088
2318
  This is the idiomatic way to describe each field of an event detail. An inline object literal such as `@event {{ items: string[]; added: string[] }} change` types the payload but cannot carry per-field descriptions, since a nested block comment would terminate the host JSDoc. Declare the detail with `@type {object}` and `@property` instead to document every field.
2089
2319
 
@@ -2358,6 +2588,174 @@ label?: string;
2358
2588
  { "name": "label", "deprecated": "Use the `text` prop instead." }
2359
2589
  ```
2360
2590
 
2591
+ ### `@since`
2592
+
2593
+ `@since` records the version a prop, event, or slot was introduced. `sveld` does not validate or parse the version text — whatever follows the tag is copied through as-is.
2594
+
2595
+ **Valid contexts:**
2596
+
2597
+ - **Prop / module export** — captured as a structured tag: JSON adds a `tags: [{ "name": "since", "body": "..." }]` array on the prop (kept separate from `description`), and the generated `.d.ts` emits `@since ...` as its own JSDoc line above `@default`. **Not rendered in the Markdown table** — the Markdown props/events renderers only read `description`, not `tags` (only the slots renderer does; see [extra tags before `@slot`](#extra-jsdoc-tags-before-slot)).
2598
+ - **`@event`** — same structured behavior as props, but only when `@since` is placed **after** the `@event` line in the same comment block (matching the [`@deprecated`](#deprecated) rule for events). Placed before `@event`, it is silently dropped.
2599
+ - **`@slot` / `@snippet`** — placed before the `@slot`/`@snippet` line, alongside the description. Fully surfaced in JSON, `.d.ts`, *and* the Markdown table. See [extra tags before `@slot`](#extra-jsdoc-tags-before-slot).
2600
+ - **`@typedef`** — **not supported.** A `@since` before `@typedef` produces no output anywhere; it is silently dropped.
2601
+ - **`@component` comments** — passed through verbatim as part of the raw HTML comment text. See [@component comments](#component-comments).
2602
+
2603
+ **Example:**
2604
+
2605
+ ```svelte
2606
+ <script>
2607
+ /**
2608
+ * A width prop.
2609
+ * @since 1.2.0
2610
+ * @type {number}
2611
+ */
2612
+ let { width = 0 } = $props();
2613
+ </script>
2614
+ ```
2615
+
2616
+ Output (`.d.ts`):
2617
+
2618
+ ```ts
2619
+ export type ScratchProps = {
2620
+ /**
2621
+ * A width prop.
2622
+ * @since 1.2.0
2623
+ * @default 0
2624
+ */
2625
+ width?: number;
2626
+ };
2627
+ ```
2628
+
2629
+ Output (JSON, relevant slice):
2630
+
2631
+ ```json
2632
+ { "name": "width", "description": "A width prop.", "tags": [{ "name": "since", "body": "1.2.0" }] }
2633
+ ```
2634
+
2635
+ The Markdown table for the same prop shows only `A width prop.` in the Description column — `@since` does not appear there.
2636
+
2637
+ ### `@see`
2638
+
2639
+ `@see` adds a reference link or citation. Like `@since`, `sveld` does not resolve or validate the target — it is free text.
2640
+
2641
+ **Valid contexts:**
2642
+
2643
+ - **Prop / module export** — `@see` is *not* one of the small set of tags `sveld` structures specially, so it is folded verbatim into the prop's `description` as an extra line (`@see ...`) rather than getting its own `tags` entry. Because it lives in `description`, it *does* show up everywhere `description` is used: JSON, `.d.ts`, and the Markdown table.
2644
+ - **`@event`** — **not supported in either position** (before or after `@event`). A `@see` tag near an `@event` block is silently dropped in both JSON and `.d.ts`.
2645
+ - **`@slot` / `@snippet`** — placed before `@slot`/`@snippet`, alongside the description: fully supported in JSON, `.d.ts`, and Markdown, same as `@since`. See [extra tags before `@slot`](#extra-jsdoc-tags-before-slot).
2646
+ - **`@typedef`** — **not supported.** Dropped silently, same as `@since`.
2647
+ - **`@component` comments** — passed through verbatim, same as `@since`.
2648
+
2649
+ **Example:**
2650
+
2651
+ ```svelte
2652
+ <script>
2653
+ /**
2654
+ * A width prop.
2655
+ * @see https://example.com/width-docs
2656
+ * @type {number}
2657
+ */
2658
+ let { width = 0 } = $props();
2659
+ </script>
2660
+ ```
2661
+
2662
+ Output (`.d.ts`):
2663
+
2664
+ ```ts
2665
+ export type ScratchProps = {
2666
+ /**
2667
+ * A width prop.
2668
+ * @see https://example.com/width-docs
2669
+ * @default 0
2670
+ */
2671
+ width?: number;
2672
+ };
2673
+ ```
2674
+
2675
+ Output (Markdown props table Description column):
2676
+
2677
+ ```
2678
+ A width prop.<br />@see https://example.com/width-docs
2679
+ ```
2680
+
2681
+ ### `@link`
2682
+
2683
+ `{@link target}` (optionally `{@link target|display text}`) is an inline JSDoc tag used inside prose, not a block-level tag like the others on this page. `sveld`'s comment parser only treats a *line* as starting a new tag when it begins with `@` — `{@link ...}` always starts with `{`, so it's never intercepted. It is always literal text.
2684
+
2685
+ **Valid contexts:** anywhere free-form description text is read — prop and module export descriptions, event descriptions, slot descriptions, typedef descriptions, `@component` HTML comments, and `@example` bodies. In every case `sveld` copies it through unchanged, with no link resolution or target validation, into JSON `description`, `.d.ts` JSDoc, and Markdown.
2686
+
2687
+ **Example:**
2688
+
2689
+ ```svelte
2690
+ <script>
2691
+ /**
2692
+ * The element's width in pixels. See {@link https://example.com/width|width docs}.
2693
+ * @type {number}
2694
+ */
2695
+ let { width = 0 } = $props();
2696
+ </script>
2697
+ ```
2698
+
2699
+ Output (`.d.ts`):
2700
+
2701
+ ```ts
2702
+ export type ScratchProps = {
2703
+ /**
2704
+ * The element's width in pixels. See {@link https://example.com/width|width docs}.
2705
+ * @default 0
2706
+ */
2707
+ width?: number;
2708
+ };
2709
+ ```
2710
+
2711
+ The same literal string appears unchanged in JSON `description` and in the Markdown table's Description column.
2712
+
2713
+ ### `@example`
2714
+
2715
+ `@example` has two related uses: as a plain JSDoc tag whose body is copied into generated output, and — with `checkExamples: true` — as input to sveld's compile-checker for plain TS/JS example code. This section covers the tag itself; see [Compile-checked `@example` blocks (`checkExamples`)](#compile-checked-example-blocks-checkexamples) for the type-checking feature.
2716
+
2717
+ `@example` shares its underlying mechanism with `@since` (both are in the small set of tags `sveld` treats as structured "IDE passthrough" tags), so the valid contexts are the same:
2718
+
2719
+ - **Prop / module export (including functions)** — structured `tags` entry in JSON, its own `@example` block in `.d.ts`. **Not rendered in the Markdown table**, same gap as `@since`.
2720
+ - **`@event`** — only when placed **after** the `@event` line in the same block, same rule as `@since`.
2721
+ - **`@slot` / `@snippet`** — placed before `@slot`/`@snippet`: fully supported in JSON, `.d.ts`, and Markdown. See [extra tags before `@slot`](#extra-jsdoc-tags-before-slot).
2722
+ - **`@typedef`** — **not supported**, dropped silently, same as `@since`.
2723
+ - **`@component` comments** — passed through verbatim; this is already how the [`@component` comments](#component-comments) example on this page uses `@example`.
2724
+
2725
+ **Example:**
2726
+
2727
+ ```svelte
2728
+ <script>
2729
+ /**
2730
+ * Formats a value.
2731
+ * @param {string} value
2732
+ * @returns {string}
2733
+ * @example
2734
+ * ```js
2735
+ * formatValue("ok");
2736
+ * ```
2737
+ */
2738
+ export function formatValue(value) {
2739
+ return value;
2740
+ }
2741
+ </script>
2742
+ ```
2743
+
2744
+ Output (`.d.ts`):
2745
+
2746
+ ```ts
2747
+ /**
2748
+ * Formats a value.
2749
+ * @example
2750
+ * ```js
2751
+ * formatValue("ok");
2752
+ * ```
2753
+ */
2754
+ formatValue: (value: string) => string;
2755
+ ```
2756
+
2757
+ `@param`/`@returns` are consumed into the function's type signature rather than kept as separate JSDoc lines. The Markdown table shows only `Formats a value.` in the Description column — the `@example` block does not appear there.
2758
+
2361
2759
  ### Context API
2362
2760
 
2363
2761
  `sveld` generates TypeScript definitions for Svelte's `setContext`/`getContext` by extracting types from JSDoc on context values.