sveld 0.26.2 → 0.28.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 +68 -5
- package/cli.js +1 -7
- package/lib/ComponentParser.d.ts +1 -1
- package/lib/index.js +184 -14
- package/package.json +10 -9
- package/lib/ComponentParser.js +0 -2657
- package/lib/cli.js +0 -48
- package/lib/create-exports.js +0 -170
- package/lib/element-tag-map.js +0 -158
- package/lib/get-svelte-entry.js +0 -39
- package/lib/parse-exports.js +0 -112
- package/lib/path.js +0 -12
- package/lib/plugin.js +0 -269
- package/lib/resolve-alias.js +0 -198
- package/lib/sveld.js +0 -33
- package/lib/writer/MarkdownWriterBase.js +0 -70
- package/lib/writer/Writer.js +0 -104
- package/lib/writer/WriterMarkdown.js +0 -65
- package/lib/writer/markdown-format-utils.js +0 -158
- package/lib/writer/markdown-render-utils.js +0 -89
- package/lib/writer/writer-json.js +0 -119
- package/lib/writer/writer-markdown-core.js +0 -44
- package/lib/writer/writer-markdown.js +0 -46
- package/lib/writer/writer-ts-definitions-core.js +0 -753
- package/lib/writer/writer-ts-definitions.js +0 -64
package/README.md
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
# sveld
|
|
2
2
|
|
|
3
3
|
[![NPM][npm]][npm-url]
|
|
4
|
-

|
|
5
4
|

|
|
6
5
|
|
|
7
6
|
`sveld` is a TypeScript definition generator for Svelte components. It analyzes props, events, slots, and other component features through static analysis. Types and signatures can be defined using [JSDoc notation](https://jsdoc.app/). The tool can also generate component documentation in Markdown and JSON formats.
|
|
@@ -50,7 +49,7 @@ type $Props = {
|
|
|
50
49
|
*/
|
|
51
50
|
primary?: boolean;
|
|
52
51
|
|
|
53
|
-
[key: `data-${string}`]:
|
|
52
|
+
[key: `data-${string}`]: unknown;
|
|
54
53
|
};
|
|
55
54
|
|
|
56
55
|
export type ButtonProps = Omit<$RestProps, keyof $Props> & $Props;
|
|
@@ -120,6 +119,7 @@ export default class Button extends SvelteComponentTyped<
|
|
|
120
119
|
- [API Reference](#api-reference)
|
|
121
120
|
- [@type](#type)
|
|
122
121
|
- [@typedef](#typedef)
|
|
122
|
+
- [@callback](#callback)
|
|
123
123
|
- [@slot](#slot)
|
|
124
124
|
- [Svelte 5 Snippet Compatibility](#svelte-5-snippet-compatibility)
|
|
125
125
|
- [@event](#event)
|
|
@@ -222,13 +222,13 @@ npx sveld --json --markdown
|
|
|
222
222
|
|
|
223
223
|
### Node.js
|
|
224
224
|
|
|
225
|
-
You can also use `sveld` programmatically in Node.js.
|
|
225
|
+
You can also use `sveld` programmatically in Node.js. The package is **ESM-only**; `require("sveld")` is not supported. Use `import` or dynamic `import()`.
|
|
226
226
|
|
|
227
227
|
If no `input` is specified, `sveld` will infer the entry point based on the `package.json#svelte` field.
|
|
228
228
|
|
|
229
229
|
```js
|
|
230
|
-
|
|
231
|
-
|
|
230
|
+
import { sveld } from "sveld";
|
|
231
|
+
import pkg from "./package.json" with { type: "json" };
|
|
232
232
|
|
|
233
233
|
sveld({
|
|
234
234
|
input: "./src/index.js",
|
|
@@ -485,6 +485,69 @@ export type ComponentProps = {
|
|
|
485
485
|
|
|
486
486
|
> **Note:** The inline syntax `@typedef {{ name: string }} User` continues to work for backwards compatibility.
|
|
487
487
|
|
|
488
|
+
### `@callback`
|
|
489
|
+
|
|
490
|
+
The `@callback` tag defines a function type using `@param` and `@returns` tags, following the [TypeScript JSDoc `@callback` specification](https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html#callback). Like `@typedef`, callbacks are exported from the generated TypeScript definition file.
|
|
491
|
+
|
|
492
|
+
This is useful for typing callback props without using inline function type syntax.
|
|
493
|
+
|
|
494
|
+
Signature:
|
|
495
|
+
|
|
496
|
+
```js
|
|
497
|
+
/**
|
|
498
|
+
* Optional description
|
|
499
|
+
* @callback CallbackName
|
|
500
|
+
* @param {Type} paramName - Parameter description
|
|
501
|
+
* @returns {ReturnType}
|
|
502
|
+
*/
|
|
503
|
+
```
|
|
504
|
+
|
|
505
|
+
Example:
|
|
506
|
+
|
|
507
|
+
```js
|
|
508
|
+
/**
|
|
509
|
+
* Callback fired when the value changes
|
|
510
|
+
* @callback OnChange
|
|
511
|
+
* @param {string} value - The new value
|
|
512
|
+
* @param {number} index - The index of the changed item
|
|
513
|
+
* @returns {void}
|
|
514
|
+
*/
|
|
515
|
+
|
|
516
|
+
/** @type {OnChange} */
|
|
517
|
+
export let onChange = (value, index) => {};
|
|
518
|
+
```
|
|
519
|
+
|
|
520
|
+
Output:
|
|
521
|
+
|
|
522
|
+
```ts
|
|
523
|
+
/**
|
|
524
|
+
* Callback fired when the value changes
|
|
525
|
+
*/
|
|
526
|
+
export type OnChange = (value: string, index: number) => void;
|
|
527
|
+
|
|
528
|
+
export type ComponentProps = {
|
|
529
|
+
/**
|
|
530
|
+
* Callback fired when the value changes
|
|
531
|
+
*/
|
|
532
|
+
onChange?: OnChange;
|
|
533
|
+
};
|
|
534
|
+
```
|
|
535
|
+
|
|
536
|
+
Callbacks can be combined with `@typedef` in the same comment block:
|
|
537
|
+
|
|
538
|
+
```js
|
|
539
|
+
/**
|
|
540
|
+
* @typedef {"asc" | "desc"} SortDirection
|
|
541
|
+
* @callback SortFn
|
|
542
|
+
* @param {any} a
|
|
543
|
+
* @param {any} b
|
|
544
|
+
* @param {SortDirection} direction
|
|
545
|
+
* @returns {number}
|
|
546
|
+
*/
|
|
547
|
+
```
|
|
548
|
+
|
|
549
|
+
When `@returns` is omitted, the return type defaults to `void`. When no `@param` tags are present, the callback is typed as a no-argument function.
|
|
550
|
+
|
|
488
551
|
### `@slot`
|
|
489
552
|
|
|
490
553
|
Use the `@slot` tag for typing component slots. Note that `@slot` is a non-standard JSDoc tag.
|
package/cli.js
CHANGED
package/lib/ComponentParser.d.ts
CHANGED
|
@@ -601,7 +601,7 @@ export default class ComponentParser {
|
|
|
601
601
|
* Parses custom types, events, slots, and other JSDoc annotations from component comments.
|
|
602
602
|
*
|
|
603
603
|
* Scans the entire source for JSDoc comment blocks and extracts structured information
|
|
604
|
-
* about events, typedefs, slots, extends, restProps, and generics. Handles complex
|
|
604
|
+
* about events, typedefs, callbacks, slots, extends, restProps, and generics. Handles complex
|
|
605
605
|
* description extraction logic that supports both inline descriptions and preceding
|
|
606
606
|
* line descriptions.
|
|
607
607
|
*
|