sveld 0.34.1 → 0.35.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 +311 -89
- package/cli.js +6 -1
- package/lib/ComponentParser.d.ts +201 -568
- package/lib/ast-guards.d.ts +3 -1
- package/lib/bundle.d.ts +15 -2
- package/lib/check.d.ts +6 -0
- package/lib/cli.d.ts +18 -18
- package/lib/diagnostics.d.ts +5 -1
- package/lib/example-check.d.ts +3 -1
- package/lib/index.js +446 -719
- package/lib/load-config.d.ts +20 -2
- package/lib/parser/bindings.d.ts +6 -0
- package/lib/parser/context.d.ts +110 -0
- package/lib/parser/contexts.d.ts +19 -0
- package/lib/parser/diagnostics.d.ts +8 -0
- package/lib/parser/events.d.ts +23 -0
- package/lib/parser/generics.d.ts +24 -0
- package/lib/parser/jsdoc.d.ts +59 -0
- package/lib/parser/props.d.ts +67 -0
- package/lib/parser/rest-props.d.ts +6 -0
- package/lib/parser/runes-props.d.ts +18 -0
- package/lib/parser/scopes.d.ts +40 -0
- package/lib/parser/slots.d.ts +29 -0
- package/lib/parser/source-position.d.ts +30 -0
- package/lib/parser/type-resolution.d.ts +27 -0
- package/lib/plugin.d.ts +7 -3
- package/lib/sveld.d.ts +6 -19
- package/lib/writer/MarkdownWriterBase.d.ts +2 -1
- package/lib/writer/Writer.d.ts +13 -49
- package/lib/writer/WriterMarkdown.d.ts +1 -1
- package/lib/writer/format-generated-ts.d.ts +8 -0
- package/lib/writer/writer-custom-elements-core.d.ts +86 -0
- package/lib/writer/writer-custom-elements.d.ts +15 -0
- package/lib/writer/writer-ts-definitions-core.d.ts +12 -1
- package/lib/writer/writer-ts-definitions.d.ts +4 -3
- package/package.json +1 -4
package/lib/writer/Writer.d.ts
CHANGED
|
@@ -1,70 +1,36 @@
|
|
|
1
|
-
import { type ParserOptions } from "prettier";
|
|
2
|
-
export declare const DEFAULT_TYPESCRIPT_PRINT_WIDTH = 80;
|
|
3
1
|
/**
|
|
4
|
-
*
|
|
2
|
+
* Base writer class for file system operations.
|
|
5
3
|
*
|
|
6
|
-
*
|
|
7
|
-
*/
|
|
8
|
-
interface WriterOptions extends Pick<ParserOptions, "parser" | "printWidth"> {
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Base writer class for formatting and writing files.
|
|
12
|
-
*
|
|
13
|
-
* Handles file formatting using Prettier and file system operations.
|
|
14
|
-
* Automatically creates directories as needed and formats content
|
|
15
|
-
* before writing.
|
|
4
|
+
* Automatically creates directories as needed before writing.
|
|
16
5
|
*
|
|
17
6
|
* @example
|
|
18
7
|
* ```ts
|
|
19
|
-
* const writer = new Writer(
|
|
8
|
+
* const writer = new Writer();
|
|
20
9
|
* await writer.write("./dist/index.d.ts", "export type Props = {};");
|
|
21
10
|
* ```
|
|
22
11
|
*/
|
|
23
12
|
export default class Writer {
|
|
24
|
-
options: WriterOptions;
|
|
25
|
-
/**
|
|
26
|
-
* Creates a new Writer instance.
|
|
27
|
-
*
|
|
28
|
-
* @param options - Writer configuration options
|
|
29
|
-
*/
|
|
30
|
-
constructor(options: WriterOptions);
|
|
31
|
-
/**
|
|
32
|
-
* Formats raw content using Prettier.
|
|
33
|
-
*
|
|
34
|
-
* Applies formatting based on the configured parser and print width.
|
|
35
|
-
* Returns the original content if formatting fails.
|
|
36
|
-
*
|
|
37
|
-
* @param raw - The raw content to format
|
|
38
|
-
* @returns Formatted content, or original content if formatting fails
|
|
39
|
-
*
|
|
40
|
-
* @example
|
|
41
|
-
* ```ts
|
|
42
|
-
* const formatted = await writer.format("export type Props={}");
|
|
43
|
-
* // Returns: "export type Props = {};\n"
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
46
|
-
format(raw: string): Promise<string>;
|
|
47
13
|
/**
|
|
48
|
-
* Writes
|
|
14
|
+
* Writes content to a file.
|
|
49
15
|
*
|
|
50
|
-
* Creates the directory structure if needed,
|
|
51
|
-
*
|
|
16
|
+
* Creates the directory structure if needed, then writes the content
|
|
17
|
+
* to the specified file path.
|
|
52
18
|
*
|
|
53
19
|
* @param filePath - The path where the file should be written
|
|
54
|
-
* @param raw - The
|
|
20
|
+
* @param raw - The content to write
|
|
55
21
|
*
|
|
56
22
|
* @example
|
|
57
23
|
* ```ts
|
|
58
24
|
* await writer.write("./dist/index.d.ts", "export type Props={}");
|
|
59
|
-
* // Creates ./dist/index.d.ts with
|
|
25
|
+
* // Creates ./dist/index.d.ts with the given content
|
|
60
26
|
* ```
|
|
61
27
|
*/
|
|
62
28
|
write(filePath: string, raw: string): Promise<void>;
|
|
63
29
|
}
|
|
64
30
|
/**
|
|
65
|
-
* Creates a Writer instance
|
|
31
|
+
* Creates a Writer instance for JSON files.
|
|
66
32
|
*
|
|
67
|
-
* @returns A Writer instance
|
|
33
|
+
* @returns A Writer instance
|
|
68
34
|
*
|
|
69
35
|
* @example
|
|
70
36
|
* ```ts
|
|
@@ -74,10 +40,9 @@ export default class Writer {
|
|
|
74
40
|
*/
|
|
75
41
|
export declare function createJsonWriter(): Writer;
|
|
76
42
|
/**
|
|
77
|
-
* Creates a Writer instance
|
|
43
|
+
* Creates a Writer instance for TypeScript files.
|
|
78
44
|
*
|
|
79
|
-
* @
|
|
80
|
-
* @returns A Writer instance with TypeScript parser and 80 character print width by default
|
|
45
|
+
* @returns A Writer instance
|
|
81
46
|
*
|
|
82
47
|
* @example
|
|
83
48
|
* ```ts
|
|
@@ -85,5 +50,4 @@ export declare function createJsonWriter(): Writer;
|
|
|
85
50
|
* await writer.write("index.d.ts", "export type Props={};");
|
|
86
51
|
* ```
|
|
87
52
|
*/
|
|
88
|
-
export declare function createTypeScriptWriter(
|
|
89
|
-
export {};
|
|
53
|
+
export declare function createTypeScriptWriter(): Writer;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reformats generator-emitted `.d.ts` source for consistent indentation and
|
|
3
|
+
* spacing, without depending on an external formatter. This is a structural
|
|
4
|
+
* cleanup pass (bracket-depth reindentation, blank-line normalization) rather
|
|
5
|
+
* than a full TypeScript printer — it does not wrap long lines or rewrite
|
|
6
|
+
* operator spacing.
|
|
7
|
+
*/
|
|
8
|
+
export declare function formatGeneratedTypeScript(raw: string): string;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { DeprecatedValue } from "../ComponentParser";
|
|
2
|
+
import type { ComponentDocApi, ComponentDocs } from "../plugin";
|
|
3
|
+
/**
|
|
4
|
+
* Minimal local subset of the published Custom Elements Manifest schema
|
|
5
|
+
* (schemaVersion "1.0.0") for the fields sveld can populate. See
|
|
6
|
+
* https://github.com/webcomponents/custom-elements-manifest for the full spec.
|
|
7
|
+
*/
|
|
8
|
+
export interface CemType {
|
|
9
|
+
text: string;
|
|
10
|
+
}
|
|
11
|
+
export interface CemClassField {
|
|
12
|
+
kind: "field";
|
|
13
|
+
name: string;
|
|
14
|
+
type?: CemType;
|
|
15
|
+
default?: string;
|
|
16
|
+
description?: string;
|
|
17
|
+
deprecated?: DeprecatedValue;
|
|
18
|
+
}
|
|
19
|
+
export interface CemAttribute {
|
|
20
|
+
name: string;
|
|
21
|
+
fieldName: string;
|
|
22
|
+
type?: CemType;
|
|
23
|
+
default?: string;
|
|
24
|
+
description?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface CemEvent {
|
|
27
|
+
name: string;
|
|
28
|
+
type: CemType;
|
|
29
|
+
description?: string;
|
|
30
|
+
deprecated?: DeprecatedValue;
|
|
31
|
+
}
|
|
32
|
+
export interface CemSlot {
|
|
33
|
+
name: string;
|
|
34
|
+
description?: string;
|
|
35
|
+
deprecated?: DeprecatedValue;
|
|
36
|
+
}
|
|
37
|
+
export interface CemClassDeclaration {
|
|
38
|
+
kind: "class";
|
|
39
|
+
name: string;
|
|
40
|
+
description?: string;
|
|
41
|
+
members: CemClassField[];
|
|
42
|
+
attributes: CemAttribute[];
|
|
43
|
+
events: CemEvent[];
|
|
44
|
+
slots: CemSlot[];
|
|
45
|
+
/** Only present when the source component sets `<svelte:options customElement="..." />`. */
|
|
46
|
+
tagName?: string;
|
|
47
|
+
/** Only present when the source component sets `<svelte:options customElement="..." />`. */
|
|
48
|
+
customElement?: true;
|
|
49
|
+
}
|
|
50
|
+
export interface CemJavaScriptExport {
|
|
51
|
+
kind: "js";
|
|
52
|
+
name: string;
|
|
53
|
+
declaration: {
|
|
54
|
+
name: string;
|
|
55
|
+
module: string;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export interface CemCustomElementExport {
|
|
59
|
+
kind: "custom-element-definition";
|
|
60
|
+
name: string;
|
|
61
|
+
declaration: {
|
|
62
|
+
name: string;
|
|
63
|
+
module: string;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
export type CemExport = CemJavaScriptExport | CemCustomElementExport;
|
|
67
|
+
export interface CemModule {
|
|
68
|
+
kind: "javascript-module";
|
|
69
|
+
path: string;
|
|
70
|
+
declarations: CemClassDeclaration[];
|
|
71
|
+
exports: CemExport[];
|
|
72
|
+
}
|
|
73
|
+
export interface CustomElementsManifest {
|
|
74
|
+
schemaVersion: "1.0.0";
|
|
75
|
+
modules: CemModule[];
|
|
76
|
+
}
|
|
77
|
+
export interface BuildCustomElementsManifestOptions {
|
|
78
|
+
/** Resolves each component's manifest `path`. Defaults to the component's `filePath` as-is. */
|
|
79
|
+
resolveModulePath?: (component: ComponentDocApi) => string;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Builds a Custom Elements Manifest (schemaVersion "1.0.0") in memory, with
|
|
83
|
+
* no file-system or `node:*` dependency so it can run in the browser (e.g.
|
|
84
|
+
* the playground).
|
|
85
|
+
*/
|
|
86
|
+
export declare function buildCustomElementsManifest(components: ComponentDocs, options?: BuildCustomElementsManifestOptions): CustomElementsManifest;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ComponentDocs } from "../plugin";
|
|
2
|
+
export type { CemAttribute, CemClassDeclaration, CemClassField, CemCustomElementExport, CemEvent, CemExport, CemJavaScriptExport, CemModule, CemSlot, CemType, CustomElementsManifest, } from "./writer-custom-elements-core";
|
|
3
|
+
export interface WriteCustomElementsOptions {
|
|
4
|
+
inputDir: string;
|
|
5
|
+
outFile: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Writes component documentation as a Custom Elements Manifest
|
|
9
|
+
* (schemaVersion "1.0.0"). Components without a `customElementTag` (i.e. not
|
|
10
|
+
* compiled with `<svelte:options customElement="..." />`) still emit a plain
|
|
11
|
+
* class declaration; the manifest is most useful for `customElement`-compiled
|
|
12
|
+
* builds, where editors, Storybook, and other CEM-aware tooling can resolve
|
|
13
|
+
* `tagName`, `attributes`, and `events`.
|
|
14
|
+
*/
|
|
15
|
+
export default function writeCustomElements(components: ComponentDocs, options: WriteCustomElementsOptions): Promise<void>;
|
|
@@ -24,4 +24,15 @@ export declare function getTypeDefs(def: Pick<ComponentDocApi, "typedefs">): str
|
|
|
24
24
|
* ```
|
|
25
25
|
*/
|
|
26
26
|
export declare function getContextDefs(def: Pick<ComponentDocApi, "contexts" | "generics">): string;
|
|
27
|
-
export
|
|
27
|
+
export interface WriteTsDefinitionOptions {
|
|
28
|
+
/**
|
|
29
|
+
* `"class"` (default) extends the deprecated `SvelteComponentTyped`.
|
|
30
|
+
* `"component"` emits `declare const X: Component<Props, Exports, Bindings>`
|
|
31
|
+
* instead, for Svelte 5+ consumers. Generic components get a per-component
|
|
32
|
+
* interface with a generic call signature instead of `Component<...>`
|
|
33
|
+
* directly, since a `declare const` can't itself carry a generic type
|
|
34
|
+
* parameter (see `genGenericComponentDeclaration`).
|
|
35
|
+
*/
|
|
36
|
+
format?: "class" | "component";
|
|
37
|
+
}
|
|
38
|
+
export declare function writeTsDefinition(component: ComponentDocApi, options?: WriteTsDefinitionOptions): string;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ParsedExports } from "../parse-exports";
|
|
2
2
|
import type { ComponentDocs } from "../plugin";
|
|
3
|
+
import { type WriteTsDefinitionOptions } from "./writer-ts-definitions-core";
|
|
3
4
|
/**
|
|
4
5
|
* Re-export browser-compatible functions from core module.
|
|
5
6
|
*
|
|
@@ -9,7 +10,7 @@ import type { ComponentDocs } from "../plugin";
|
|
|
9
10
|
*
|
|
10
11
|
* @see {@link ./writer-ts-definitions-core} for the core implementation
|
|
11
12
|
*/
|
|
12
|
-
export { formatTsProps, getContextDefs, getTypeDefs, writeTsDefinition, } from "./writer-ts-definitions-core";
|
|
13
|
+
export { formatTsProps, getContextDefs, getTypeDefs, type WriteTsDefinitionOptions, writeTsDefinition, } from "./writer-ts-definitions-core";
|
|
13
14
|
/**
|
|
14
15
|
* Options for writing TypeScript definition files.
|
|
15
16
|
*
|
|
@@ -17,6 +18,7 @@ export { formatTsProps, getContextDefs, getTypeDefs, writeTsDefinition, } from "
|
|
|
17
18
|
* @property inputDir - The input directory containing source components
|
|
18
19
|
* @property preamble - Text to prepend to the main `index.d.ts` file
|
|
19
20
|
* @property exports - Parsed export information for generating the index file
|
|
21
|
+
* @property format - `"class"` (default) or `"component"`; see {@link WriteTsDefinitionOptions}
|
|
20
22
|
*
|
|
21
23
|
* @example
|
|
22
24
|
* ```ts
|
|
@@ -28,12 +30,11 @@ export { formatTsProps, getContextDefs, getTypeDefs, writeTsDefinition, } from "
|
|
|
28
30
|
* };
|
|
29
31
|
* ```
|
|
30
32
|
*/
|
|
31
|
-
export interface WriteTsDefinitionsOptions {
|
|
33
|
+
export interface WriteTsDefinitionsOptions extends WriteTsDefinitionOptions {
|
|
32
34
|
outDir: string;
|
|
33
35
|
inputDir: string;
|
|
34
36
|
preamble: string;
|
|
35
37
|
exports: ParsedExports;
|
|
36
|
-
printWidth?: number;
|
|
37
38
|
}
|
|
38
39
|
/**
|
|
39
40
|
* Writes TypeScript definition files for all parsed Svelte components.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sveld",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.35.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "Generate TypeScript definitions and component documentation for your Svelte components.",
|
|
6
6
|
"type": "module",
|
|
@@ -13,9 +13,6 @@
|
|
|
13
13
|
"default": "./lib/index.js"
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
|
-
"dependencies": {
|
|
17
|
-
"prettier": "^3.8.4"
|
|
18
|
-
},
|
|
19
16
|
"bin": {
|
|
20
17
|
"sveld": "cli.js"
|
|
21
18
|
},
|