sveld 0.37.9 → 0.38.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 +175 -4337
- package/lib/browser.d.ts +113 -477
- package/lib/browser.js +178 -188
- package/lib/chunk-12m2j9sx.js +244 -0
- package/lib/chunk-4zz6y1q7.js +5 -0
- package/lib/chunk-bkyrjqfv.js +1 -0
- package/lib/chunk-m08z217p.js +36 -0
- package/lib/{chunk-wd6xaaes.js → chunk-mrkc1dc9.js} +9 -9
- package/lib/cli-entry.js +38 -1
- package/lib/index.d.ts +211 -599
- package/lib/index.js +1 -1
- package/package.json +1 -1
- package/lib/chunk-81w3m3mq.js +0 -8
- package/lib/chunk-f8nq2w4s.js +0 -325
- package/lib/chunk-fk1w3bnw.js +0 -29
- package/lib/chunk-fz6nj0w3.js +0 -4
- package/lib/chunk-r92p6t72.js +0 -1
- package/lib/chunk-yp6p39jn.js +0 -6
package/lib/browser.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Property } from "estree";
|
|
2
2
|
|
|
3
|
-
import type {
|
|
3
|
+
import type { Dirent } from "node:fs";
|
|
4
|
+
|
|
5
|
+
import { type Program } from "acorn";
|
|
4
6
|
|
|
5
7
|
declare const brand: unique symbol;
|
|
6
8
|
|
|
@@ -12,6 +14,49 @@ export type NormalizedPath = Brand<string, "NormalizedPath">;
|
|
|
12
14
|
|
|
13
15
|
export declare function asNormalizedPath(path: string): NormalizedPath;
|
|
14
16
|
|
|
17
|
+
interface ComponentParserDiagnostics {
|
|
18
|
+
moduleName: string;
|
|
19
|
+
filePath: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export class ComponentParser {
|
|
23
|
+
/**
|
|
24
|
+
* All per-parse mutable state (props, slots, events, scopes, source, etc.).
|
|
25
|
+
* See {@link ParserContext} for field-by-field documentation. Replaced
|
|
26
|
+
* wholesale by `cleanup()` between parses.
|
|
27
|
+
*/
|
|
28
|
+
private ctx;
|
|
29
|
+
/**
|
|
30
|
+
* Resets parser state for reuse between parses.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* parser.parseSvelteComponent(source1, diagnostics1);
|
|
35
|
+
* parser.cleanup();
|
|
36
|
+
* parser.parseSvelteComponent(source2, diagnostics2);
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
cleanup(): void;
|
|
40
|
+
/**
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* const parser = new ComponentParser();
|
|
44
|
+
* const result = parser.parseSvelteComponent(source, {
|
|
45
|
+
* moduleName: "Button",
|
|
46
|
+
* filePath: "./Button.svelte"
|
|
47
|
+
* });
|
|
48
|
+
* // { props, slots, events, typedefs, ... }
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
parseSvelteComponent(source: string, diagnostics: ComponentParserDiagnostics): ParsedComponent;
|
|
52
|
+
/**
|
|
53
|
+
* Like {@link parseSvelteComponent}, but returns the candidates only a
|
|
54
|
+
* pass with file access can resolve beside the component rather than
|
|
55
|
+
* inside its metadata.
|
|
56
|
+
*/
|
|
57
|
+
parse(source: string, diagnostics: ComponentParserDiagnostics): ComponentParseResult;
|
|
58
|
+
}
|
|
59
|
+
|
|
15
60
|
interface JsDocPassthroughTag {
|
|
16
61
|
name: string;
|
|
17
62
|
body: string;
|
|
@@ -84,31 +129,18 @@ interface PendingDispatchEscapeCandidate {
|
|
|
84
129
|
ignored?: boolean;
|
|
85
130
|
}
|
|
86
131
|
|
|
87
|
-
interface
|
|
88
|
-
|
|
89
|
-
canonicalPropNames: string[];
|
|
90
|
-
localTypeDeclarations: string[];
|
|
91
|
-
/** Types the module script exports (`export interface Item`), emitted with `export`. */
|
|
92
|
-
moduleTypeDeclarations?: string[];
|
|
93
|
-
typeImportStatements: string[];
|
|
94
|
-
/**
|
|
95
|
-
* Whether `canonicalPropsType` mentions one of the component's own
|
|
96
|
-
* `<script generics="...">` parameters (e.g. `Props<T>`). The semantic
|
|
97
|
-
* resolver has no binding for `T`, so `resolveTypes` must leave this
|
|
98
|
-
* component's props as their AST-derived text rather than expand them.
|
|
99
|
-
*/
|
|
100
|
-
referencesComponentGenerics?: boolean;
|
|
101
|
-
/** Unresolved CallExpression defaults for the cross-file pass in `generateBundle`. */
|
|
132
|
+
interface PendingCrossFileCandidates {
|
|
133
|
+
/** Unresolved CallExpression defaults. */
|
|
102
134
|
pendingCallDefaultCandidates?: PendingCallDefaultCandidate[];
|
|
103
|
-
/** Imported-identifier defaults
|
|
135
|
+
/** Imported-identifier defaults. */
|
|
104
136
|
pendingConstDefaultCandidates?: PendingConstDefaultCandidate[];
|
|
105
|
-
/** Unresolved `setContext` import keys
|
|
137
|
+
/** Unresolved `setContext` import keys. */
|
|
106
138
|
pendingContextKeyCandidates?: PendingContextKeyCandidate[];
|
|
107
|
-
/** Dispatchers passed to imported functions
|
|
139
|
+
/** Dispatchers passed to imported functions. */
|
|
108
140
|
pendingDispatchEscapeCandidates?: PendingDispatchEscapeCandidate[];
|
|
109
141
|
/**
|
|
110
142
|
* `event-no-source` diagnostics held back while the dispatcher escapes to
|
|
111
|
-
* imported functions:
|
|
143
|
+
* imported functions: the cross-file pass keeps those the functions don't dispatch.
|
|
112
144
|
*/
|
|
113
145
|
deferredEventNoSourceDiagnostics?: SveldDiagnostic[];
|
|
114
146
|
/**
|
|
@@ -118,6 +150,21 @@ interface ParsedComponentTypeScriptMetadata {
|
|
|
118
150
|
untypedJsDocEventNames?: string[];
|
|
119
151
|
}
|
|
120
152
|
|
|
153
|
+
interface ParsedComponentTypeScriptMetadata extends PendingCrossFileCandidates {
|
|
154
|
+
canonicalPropsType?: string;
|
|
155
|
+
canonicalPropNames: string[];
|
|
156
|
+
localTypeDeclarations: string[];
|
|
157
|
+
/** Types the module script exports (`export interface Item`), emitted with `export`. */
|
|
158
|
+
moduleTypeDeclarations?: string[];
|
|
159
|
+
typeImportStatements: string[];
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
interface ComponentParseResult {
|
|
163
|
+
component: ParsedComponent;
|
|
164
|
+
/** Undefined when the component depends on no other file's contents. */
|
|
165
|
+
pending?: PendingCrossFileCandidates;
|
|
166
|
+
}
|
|
167
|
+
|
|
121
168
|
type SyntaxMode = "legacy" | "runes";
|
|
122
169
|
|
|
123
170
|
type ScriptLanguage = "js" | "ts";
|
|
@@ -132,25 +179,6 @@ interface ComponentPropDefaultValue {
|
|
|
132
179
|
value?: unknown;
|
|
133
180
|
}
|
|
134
181
|
|
|
135
|
-
type ModernScriptAttribute = {
|
|
136
|
-
name?: string;
|
|
137
|
-
value?: Array<{
|
|
138
|
-
data?: string;
|
|
139
|
-
raw?: string;
|
|
140
|
-
}> | boolean;
|
|
141
|
-
start?: number;
|
|
142
|
-
end?: number;
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
type ModernScriptNode = {
|
|
146
|
-
attributes?: ModernScriptAttribute[];
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
interface ComponentParserDiagnostics {
|
|
150
|
-
moduleName: string;
|
|
151
|
-
filePath: string;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
182
|
type ComponentPropBinding = "readonly" | "writable";
|
|
155
183
|
|
|
156
184
|
interface ComponentPropParam {
|
|
@@ -489,154 +517,7 @@ interface ParsedComponent {
|
|
|
489
517
|
[PARSED_COMPONENT_TYPE_SCRIPT_METADATA]?: ParsedComponentTypeScriptMetadata;
|
|
490
518
|
}
|
|
491
519
|
|
|
492
|
-
export
|
|
493
|
-
/**
|
|
494
|
-
* All per-parse mutable state (props, slots, events, scopes, source, etc.).
|
|
495
|
-
* See {@link ParserContext} for field-by-field documentation. Replaced
|
|
496
|
-
* wholesale by `cleanup()` between parses.
|
|
497
|
-
*/
|
|
498
|
-
private ctx;
|
|
499
|
-
private static mapToArray;
|
|
500
|
-
private static getStaticAttributeValue;
|
|
501
|
-
resolveScriptLanguage(parsed: {
|
|
502
|
-
instance?: ModernScriptNode;
|
|
503
|
-
module?: ModernScriptNode;
|
|
504
|
-
}): ScriptLanguage | undefined;
|
|
505
|
-
/**
|
|
506
|
-
* Reads the `generics` attribute off the instance script (Svelte only allows
|
|
507
|
-
* it there, and only alongside `lang="ts"`). Returns the raw value for later
|
|
508
|
-
* precedence resolution against `@generics`/`@template` JSDoc tags, or
|
|
509
|
-
* `undefined` if absent. Records a `syntax-skipped` diagnostic and returns
|
|
510
|
-
* `undefined` if the attribute is present without `lang="ts"`, since sveld
|
|
511
|
-
* can't safely guess how to parse it as plain JavaScript.
|
|
512
|
-
*/
|
|
513
|
-
resolveScriptGenericsAttribute(parsed: {
|
|
514
|
-
instance?: ModernScriptNode;
|
|
515
|
-
}): {
|
|
516
|
-
value: string;
|
|
517
|
-
source?: SourceRange;
|
|
518
|
-
} | undefined;
|
|
519
|
-
private resolvePublicPropName;
|
|
520
|
-
trackPropLocalName(propName: string, localName?: string): void;
|
|
521
|
-
private getPropByLocalOrPublic;
|
|
522
|
-
getPropTypeByLocalOrPublic(name: string): string | undefined;
|
|
523
|
-
getExplicitPropType(name: string): string | undefined;
|
|
524
|
-
getPropertyName(node: Property["key"]): string | undefined;
|
|
525
|
-
isNumericConstant(memberExpr: unknown): boolean;
|
|
526
|
-
resolveLocalVarJSDoc(name: string): {
|
|
527
|
-
type?: string;
|
|
528
|
-
params?: ComponentPropParam[];
|
|
529
|
-
returnType?: string;
|
|
530
|
-
description?: string;
|
|
531
|
-
binding?: ComponentPropBinding;
|
|
532
|
-
deprecated?: DeprecatedValue;
|
|
533
|
-
tags?: JsDocPassthroughTag[];
|
|
534
|
-
sveldIgnore?: string[];
|
|
535
|
-
internal: boolean;
|
|
536
|
-
typeParameters?: string;
|
|
537
|
-
} | undefined;
|
|
538
|
-
private addModuleExport;
|
|
539
|
-
/**
|
|
540
|
-
* Resolves one `export { local as exported }` specifier to the top-level
|
|
541
|
-
* function, class, or variable declarator (including one destructured
|
|
542
|
-
* from a pattern) it names. Each specifier resolves on its own, so
|
|
543
|
-
* `export { a, b }` exports both, and `const a = 1, b = ""; export { b }`
|
|
544
|
-
* exports `b`'s declarator rather than the first one in the declaration.
|
|
545
|
-
*
|
|
546
|
-
* `program` is the script the export sits in: only its top-level
|
|
547
|
-
* declarations count, not a same-named variable inside a function. An
|
|
548
|
-
* instance-script export can also name a module-script declaration, or a
|
|
549
|
-
* variable that a `$: local = ...` reactive declaration declares implicitly.
|
|
550
|
-
*/
|
|
551
|
-
private resolveExportSpecifier;
|
|
552
|
-
private recordUnresolvedExportSpecifier;
|
|
553
|
-
/**
|
|
554
|
-
* Doc comment for a declaration exported by `node`. A specifier uses the
|
|
555
|
-
* comment on the declaration it names. An `export { ... }` list's own
|
|
556
|
-
* comment documents it too, but only when the list has a single specifier;
|
|
557
|
-
* its tags and description then override the declaration's.
|
|
558
|
-
*/
|
|
559
|
-
private exportJSDoc;
|
|
560
|
-
/** An instance-script `export class Foo {}` or `export { Foo }` of a class: neither a prop nor a documented accessor. */
|
|
561
|
-
private recordClassExport;
|
|
562
|
-
/**
|
|
563
|
-
* The `.d.ts` can only say `extends Base` when `Base` is in scope there:
|
|
564
|
-
* imported, or another exported class. A class extending anything else
|
|
565
|
-
* (a local class, a call like `mixin(Base)`) is declared without it, and
|
|
566
|
-
* flagged, since consumers won't see its inherited members.
|
|
567
|
-
*/
|
|
568
|
-
private dropUndeclaredClassBases;
|
|
569
|
-
/** A module-script `export class Foo {}` or `export { Foo }` of a class, with its public members. */
|
|
570
|
-
private addModuleClassExport;
|
|
571
|
-
/**
|
|
572
|
-
* @example
|
|
573
|
-
* ```ts
|
|
574
|
-
* aliasType("*"); // "any"
|
|
575
|
-
* aliasType(" string "); // "string"
|
|
576
|
-
* ```
|
|
577
|
-
*/
|
|
578
|
-
aliasType(type: string): string;
|
|
579
|
-
/**
|
|
580
|
-
* @example
|
|
581
|
-
* ```ts
|
|
582
|
-
* // Given:
|
|
583
|
-
* // /**
|
|
584
|
-
* // * @type {number}
|
|
585
|
-
* // * The count value
|
|
586
|
-
* // *\/
|
|
587
|
-
* // const count = 0;
|
|
588
|
-
*
|
|
589
|
-
* findVariableTypeAndDescription("count");
|
|
590
|
-
* // { type: "number", description: "The count value" }
|
|
591
|
-
* ```
|
|
592
|
-
*/
|
|
593
|
-
findVariableTypeAndDescription(varName: string): {
|
|
594
|
-
type: string;
|
|
595
|
-
description?: string;
|
|
596
|
-
internal?: boolean;
|
|
597
|
-
} | null;
|
|
598
|
-
/**
|
|
599
|
-
* The description and `@internal` flag of the JSDoc above `varName`,
|
|
600
|
-
* whether or not it has a `@type`. For a variable typed some other way,
|
|
601
|
-
* such as from its initializer.
|
|
602
|
-
*/
|
|
603
|
-
findVariableJsDoc(varName: string): {
|
|
604
|
-
description?: string;
|
|
605
|
-
internal?: boolean;
|
|
606
|
-
};
|
|
607
|
-
/** The JSDoc table entry for `varName`, building the table on first use. */
|
|
608
|
-
private variableJsDocEntry;
|
|
609
|
-
accumulateGeneric(name: string, constraint: string): void;
|
|
610
|
-
/**
|
|
611
|
-
* Resets parser state for reuse between parses.
|
|
612
|
-
*
|
|
613
|
-
* @example
|
|
614
|
-
* ```ts
|
|
615
|
-
* parser.parseSvelteComponent(source1, diagnostics1);
|
|
616
|
-
* parser.cleanup();
|
|
617
|
-
* parser.parseSvelteComponent(source2, diagnostics2);
|
|
618
|
-
* ```
|
|
619
|
-
*/
|
|
620
|
-
cleanup(): void;
|
|
621
|
-
private static readonly SCRIPT_BLOCK_REGEX;
|
|
622
|
-
/** A `// @ts-...` comment, but not one on a `*` line of a JSDoc block (e.g. in an `@example`). */
|
|
623
|
-
private static readonly TS_DIRECTIVE_REGEX;
|
|
624
|
-
private static stripTypeScriptDirectivesFromScripts;
|
|
625
|
-
/**
|
|
626
|
-
* @example
|
|
627
|
-
* ```ts
|
|
628
|
-
* const parser = new ComponentParser();
|
|
629
|
-
* const result = parser.parseSvelteComponent(source, {
|
|
630
|
-
* moduleName: "Button",
|
|
631
|
-
* filePath: "./Button.svelte"
|
|
632
|
-
* });
|
|
633
|
-
* // { props, slots, events, typedefs, ... }
|
|
634
|
-
* ```
|
|
635
|
-
*/
|
|
636
|
-
parseSvelteComponent(source: string, diagnostics: ComponentParserDiagnostics): ParsedComponent;
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
export type SveldDiagnosticKind = "prop-unknown-type" | "context-any-type" | "slot-missing-type" | "event-no-source" | "dispatch-escapes" | "example-compile-error" | "example-syntax-error" | "syntax-skipped" | "rest-props-unresolved" | "context-duplicate-key" | "context-key-unresolved" | "context-value-unresolved" | "spread-unresolved" | "export-unresolved" | "module-export-conflict" | "extend-props-target-missing" | "extend-props-duplicate" | "extend-props-override" | "jsdoc-unknown-tag" | "typedef-duplicate" | "property-duplicate" | "generics-conflict" | "event-description-ambiguous" | "jsdoc-tag-dropped" | "internal-typedef-referenced" | "types-inline-unresolved" | "cross-file-unresolved" | "export-ambiguous";
|
|
520
|
+
export type SveldDiagnosticKind = "prop-unknown-type" | "context-any-type" | "slot-missing-type" | "event-no-source" | "dispatch-escapes" | "example-compile-error" | "example-syntax-error" | "syntax-skipped" | "type-syntax-error" | "rest-props-unresolved" | "context-duplicate-key" | "context-key-unresolved" | "context-value-unresolved" | "spread-unresolved" | "export-unresolved" | "module-export-conflict" | "extend-props-target-missing" | "extend-props-duplicate" | "extend-props-override" | "jsdoc-unknown-tag" | "typedef-duplicate" | "property-duplicate" | "generics-conflict" | "event-description-ambiguous" | "jsdoc-tag-dropped" | "internal-typedef-referenced" | "cross-file-unresolved" | "export-ambiguous";
|
|
640
521
|
|
|
641
522
|
type SveldDiagnosticSeverity = "error" | "warning";
|
|
642
523
|
|
|
@@ -680,95 +561,6 @@ export interface ComponentDocApi extends ParsedComponent {
|
|
|
680
561
|
|
|
681
562
|
export type ComponentDocs = Map<string, ComponentDocApi>;
|
|
682
563
|
|
|
683
|
-
interface InlinedTypes {
|
|
684
|
-
/** Exact `typeImportStatements` entries the writer must drop. */
|
|
685
|
-
droppedImportStatements: string[];
|
|
686
|
-
/** Declarations to emit (already stripped of `export`), in dependency order. */
|
|
687
|
-
declarations: string[];
|
|
688
|
-
/** Absolute paths of every file read, for watch-mode invalidation. */
|
|
689
|
-
dependencies: string[];
|
|
690
|
-
}
|
|
691
|
-
|
|
692
|
-
type CommentLevel = "all" | "descriptions" | "none";
|
|
693
|
-
|
|
694
|
-
export declare function formatTsProps(props?: string): string;
|
|
695
|
-
|
|
696
|
-
export declare function getTypeDefs(def: Pick<ComponentDocApi, "typedefs">, emit?: {
|
|
697
|
-
export: boolean;
|
|
698
|
-
}, commentLevel?: CommentLevel): string;
|
|
699
|
-
|
|
700
|
-
export declare function getContextDefs(def: Pick<ComponentDocApi, "contexts" | "generics">, emit?: {
|
|
701
|
-
export: boolean;
|
|
702
|
-
}, commentLevel?: CommentLevel): string;
|
|
703
|
-
|
|
704
|
-
export interface WriteTsDefinitionOptions {
|
|
705
|
-
/**
|
|
706
|
-
* `"class"` (default) extends the deprecated `SvelteComponentTyped`.
|
|
707
|
-
* `"component"` emits `declare const X: Component<Props, Exports, Bindings>`
|
|
708
|
-
* instead, for Svelte 5+ consumers. Generic components get a per-component
|
|
709
|
-
* interface with a generic call signature instead of `Component<...>`
|
|
710
|
-
* directly, since a `declare const` can't itself carry a generic type
|
|
711
|
-
* parameter (see `genGenericComponentDeclaration`).
|
|
712
|
-
*/
|
|
713
|
-
format?: "class" | "component";
|
|
714
|
-
/**
|
|
715
|
-
* Which generated type declarations get an `export` keyword. `true`
|
|
716
|
-
* (default) exports all; `false` exports none; an object picks per kind.
|
|
717
|
-
* Module-script exports (`export declare const/function`) are runtime
|
|
718
|
-
* exports and are always emitted as exports.
|
|
719
|
-
*/
|
|
720
|
-
exportTypes?: boolean | {
|
|
721
|
-
props?: boolean;
|
|
722
|
-
exports?: boolean;
|
|
723
|
-
typedefs?: boolean;
|
|
724
|
-
contexts?: boolean;
|
|
725
|
-
};
|
|
726
|
-
/** @internal Set by `writeTsDefinitions` for `@extends` targets; overrides `exportTypes.props`. */
|
|
727
|
-
forceExportProps?: boolean;
|
|
728
|
-
/**
|
|
729
|
-
* Templates for generated type names. `{name}` is replaced with the
|
|
730
|
-
* component's module name. Defaults: `"{name}Props"`, `"{name}Exports"`.
|
|
731
|
-
*/
|
|
732
|
-
typeNames?: {
|
|
733
|
-
props?: string;
|
|
734
|
-
exports?: string;
|
|
735
|
-
};
|
|
736
|
-
/**
|
|
737
|
-
* How much JSDoc to emit. `"all"` (default) keeps descriptions,
|
|
738
|
-
* `@deprecated`, `@default`, and passthrough tags (`@since`, `@see`,
|
|
739
|
-
* `@example`, `@link`). `"descriptions"` keeps descriptions and
|
|
740
|
-
* `@deprecated` only. `"none"` emits no comments at all.
|
|
741
|
-
*/
|
|
742
|
-
comments?: "all" | "descriptions" | "none";
|
|
743
|
-
/**
|
|
744
|
-
* `"type"` (default) emits the props type as a type alias.
|
|
745
|
-
* `"interface"` emits `interface <Name>Props { ... }` when the props are a
|
|
746
|
-
* plain object (no `@restProps`, no `@extendProps`, no whole-object
|
|
747
|
-
* `$props()` type); other shapes are intersections and stay aliases.
|
|
748
|
-
*/
|
|
749
|
-
propsDeclaration?: "type" | "interface";
|
|
750
|
-
/**
|
|
751
|
-
* Copies `type`/`interface` declarations imported from a relative source (or a
|
|
752
|
-
* tsconfig/jsconfig path alias) directly into the `.d.ts`, dropping the import. `"local"`
|
|
753
|
-
* follows relative sources, path aliases, re-exports, and same-file dependencies; bare package
|
|
754
|
-
* imports, `.svelte` sources, and unsupported exports (enums, classes, functions, consts,
|
|
755
|
-
* namespaces) stay imports and get a `types-inline-unresolved` warning. `"all"` additionally
|
|
756
|
-
* inlines bare/package imports (e.g. `import type { Foo } from "some-lib"`) using the real
|
|
757
|
-
* TypeScript checker - same unsupported-export/collision rules, same warning on failure - with
|
|
758
|
-
* two exceptions kept as plain imports regardless: `svelte`/`svelte/elements` (a hard-coded
|
|
759
|
-
* allow-list; copying framework types would freeze a Svelte version into consumer output) and
|
|
760
|
-
* `@extendProps`/`@extends` targets (deferred; unrelated mechanism). `"all"` needs `typescript`
|
|
761
|
-
* 7+ and a `tsconfig.json`, same hard requirement as `resolveTypes`. `false` (default)
|
|
762
|
-
* preserves every import as-is.
|
|
763
|
-
* @default false
|
|
764
|
-
*/
|
|
765
|
-
inline?: false | "local" | "all";
|
|
766
|
-
/** @internal Set by `writeTsDefinitions` from `GenerateBundleResult.inlinedTypesByFilePath` when `inline` resolved something for this component. */
|
|
767
|
-
inlined?: InlinedTypes;
|
|
768
|
-
}
|
|
769
|
-
|
|
770
|
-
export declare function writeTsDefinition(component: ComponentDocApi, options?: WriteTsDefinitionOptions): string;
|
|
771
|
-
|
|
772
564
|
interface EntryExport {
|
|
773
565
|
name: string;
|
|
774
566
|
kind: "const" | "let" | "var" | "function" | "class" | "type" | "interface" | "enum";
|
|
@@ -794,151 +586,28 @@ interface EntryExport {
|
|
|
794
586
|
|
|
795
587
|
type EntryExports = EntryExport[];
|
|
796
588
|
|
|
797
|
-
export
|
|
798
|
-
text: string;
|
|
799
|
-
}
|
|
800
|
-
|
|
801
|
-
export interface CemClassField {
|
|
802
|
-
kind: "field";
|
|
803
|
-
name: string;
|
|
804
|
-
type?: CemType;
|
|
805
|
-
default?: string;
|
|
806
|
-
description?: string;
|
|
807
|
-
deprecated?: DeprecatedValue;
|
|
808
|
-
/** Present, and `true`, for an `export const` prop. */
|
|
809
|
-
readonly?: true;
|
|
810
|
-
}
|
|
811
|
-
|
|
812
|
-
interface CemParameter {
|
|
813
|
-
name: string;
|
|
814
|
-
type?: CemType;
|
|
815
|
-
optional?: true;
|
|
816
|
-
rest?: true;
|
|
817
|
-
}
|
|
818
|
-
|
|
819
|
-
interface CemClassMethod {
|
|
820
|
-
kind: "method";
|
|
821
|
-
name: string;
|
|
822
|
-
static: boolean;
|
|
823
|
-
parameters?: CemParameter[];
|
|
824
|
-
return?: {
|
|
825
|
-
type: CemType;
|
|
826
|
-
};
|
|
827
|
-
description?: string;
|
|
828
|
-
deprecated?: DeprecatedValue;
|
|
829
|
-
}
|
|
830
|
-
|
|
831
|
-
export interface CemAttribute {
|
|
832
|
-
name: string;
|
|
833
|
-
fieldName: string;
|
|
834
|
-
type?: CemType;
|
|
835
|
-
default?: string;
|
|
836
|
-
description?: string;
|
|
837
|
-
/** Present, and `true`, when the prop's `customElement` config sets `reflect: true`. */
|
|
838
|
-
reflects?: true;
|
|
839
|
-
}
|
|
840
|
-
|
|
841
|
-
interface CemCssPart {
|
|
842
|
-
name: string;
|
|
843
|
-
description?: string;
|
|
844
|
-
}
|
|
845
|
-
|
|
846
|
-
interface CemCssCustomProperty {
|
|
847
|
-
/** Includes the leading `--`. */
|
|
848
|
-
name: string;
|
|
849
|
-
type?: CemType;
|
|
850
|
-
default?: string;
|
|
851
|
-
description?: string;
|
|
852
|
-
}
|
|
853
|
-
|
|
854
|
-
export interface CemEvent {
|
|
855
|
-
name: string;
|
|
856
|
-
type: CemType;
|
|
857
|
-
description?: string;
|
|
858
|
-
deprecated?: DeprecatedValue;
|
|
859
|
-
}
|
|
860
|
-
|
|
861
|
-
export interface CemSlot {
|
|
862
|
-
name: string;
|
|
863
|
-
description?: string;
|
|
864
|
-
deprecated?: DeprecatedValue;
|
|
865
|
-
}
|
|
866
|
-
|
|
867
|
-
export interface CemClassDeclaration {
|
|
868
|
-
kind: "class";
|
|
869
|
-
name: string;
|
|
870
|
-
description?: string;
|
|
871
|
-
members: Array<CemClassField | CemClassMethod>;
|
|
872
|
-
attributes: CemAttribute[];
|
|
873
|
-
events: CemEvent[];
|
|
874
|
-
slots: CemSlot[];
|
|
875
|
-
/** From component-level `@csspart` JSDoc tags. */
|
|
876
|
-
cssParts?: CemCssPart[];
|
|
877
|
-
/** From component-level `@cssprop`/`@cssproperty` JSDoc tags. */
|
|
878
|
-
cssProperties?: CemCssCustomProperty[];
|
|
879
|
-
/** Only present when the source component sets `<svelte:options customElement="..." />`. */
|
|
880
|
-
tagName?: string;
|
|
881
|
-
/** Only present when the source component sets `<svelte:options customElement="..." />`. */
|
|
882
|
-
customElement?: true;
|
|
883
|
-
}
|
|
884
|
-
|
|
885
|
-
export interface CemJavaScriptExport {
|
|
886
|
-
kind: "js";
|
|
887
|
-
name: string;
|
|
888
|
-
declaration: {
|
|
889
|
-
name: string;
|
|
890
|
-
module: string;
|
|
891
|
-
};
|
|
892
|
-
}
|
|
589
|
+
export declare const COMPONENT_API_SCHEMA_VERSION = 1;
|
|
893
590
|
|
|
894
|
-
export interface
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
declaration: {
|
|
591
|
+
export interface ComponentApiDocument {
|
|
592
|
+
schemaVersion: 1;
|
|
593
|
+
generator: {
|
|
898
594
|
name: string;
|
|
899
|
-
|
|
595
|
+
version: string;
|
|
596
|
+
svelteVersion: string;
|
|
900
597
|
};
|
|
598
|
+
total: number;
|
|
599
|
+
components: ComponentDocApi[];
|
|
600
|
+
/** Only when `documentExports` is on. */
|
|
601
|
+
totalExports?: number;
|
|
602
|
+
exports?: EntryExports;
|
|
901
603
|
}
|
|
902
604
|
|
|
903
|
-
export
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
kind: "javascript-module";
|
|
907
|
-
path: string;
|
|
908
|
-
declarations: CemClassDeclaration[];
|
|
909
|
-
exports: CemExport[];
|
|
910
|
-
}
|
|
911
|
-
|
|
912
|
-
export interface CustomElementsManifest {
|
|
913
|
-
schemaVersion: "1.0.0";
|
|
914
|
-
modules: CemModule[];
|
|
915
|
-
}
|
|
916
|
-
|
|
917
|
-
export interface BuildCustomElementsManifestOptions {
|
|
918
|
-
/** Resolves each component's manifest `path`. Defaults to the component's `filePath` as-is. */
|
|
919
|
-
resolveModulePath?: (component: ComponentDocApi) => string;
|
|
920
|
-
}
|
|
921
|
-
|
|
922
|
-
export declare function buildCustomElementsManifest(components: ComponentDocs, options?: BuildCustomElementsManifestOptions): CustomElementsManifest;
|
|
923
|
-
|
|
924
|
-
type OnAppend = (type: AppendType, document: WriterMarkdown) => void;
|
|
925
|
-
|
|
926
|
-
interface MarkdownOptions {
|
|
927
|
-
onAppend?: OnAppend;
|
|
605
|
+
export interface BuildComponentApiDocumentOptions {
|
|
606
|
+
/** Entry-barrel exports when `documentExports` is on. */
|
|
607
|
+
entryExports?: EntryExports;
|
|
928
608
|
}
|
|
929
609
|
|
|
930
|
-
declare
|
|
931
|
-
onAppend?: OnAppend;
|
|
932
|
-
private markdownBase;
|
|
933
|
-
constructor(options: MarkdownOptions);
|
|
934
|
-
get source(): string;
|
|
935
|
-
get hasToC(): boolean;
|
|
936
|
-
get toc(): TocLine[];
|
|
937
|
-
appendLineBreaks(): this;
|
|
938
|
-
append(type: AppendType, raw?: string): this;
|
|
939
|
-
tableOfContents(): this;
|
|
940
|
-
end(): string;
|
|
941
|
-
}
|
|
610
|
+
export declare function buildComponentApiDocument(components: ComponentDocs, options?: BuildComponentApiDocumentOptions): ComponentApiDocument;
|
|
942
611
|
|
|
943
612
|
export type AppendType = "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "quote" | "p" | "divider" | "raw";
|
|
944
613
|
|
|
@@ -948,21 +617,18 @@ export interface TocLine {
|
|
|
948
617
|
raw: string;
|
|
949
618
|
}
|
|
950
619
|
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
appendLineBreaks(): this;
|
|
956
|
-
append(type: AppendType, raw?: string): this;
|
|
957
|
-
tableOfContents(): this;
|
|
958
|
-
end(): string;
|
|
959
|
-
get source(): string;
|
|
620
|
+
type MarkdownAppendCallback = (type: AppendType, document: MarkdownDocument) => void;
|
|
621
|
+
|
|
622
|
+
interface MarkdownDocumentOptions {
|
|
623
|
+
onAppend?: MarkdownAppendCallback;
|
|
960
624
|
}
|
|
961
625
|
|
|
962
|
-
declare class
|
|
626
|
+
export declare class MarkdownDocument {
|
|
963
627
|
sourceParts: string[];
|
|
964
628
|
hasToC: boolean;
|
|
965
629
|
toc: TocLine[];
|
|
630
|
+
onAppend?: MarkdownAppendCallback;
|
|
631
|
+
constructor(options?: MarkdownDocumentOptions);
|
|
966
632
|
get source(): string;
|
|
967
633
|
appendLineBreaks(): this;
|
|
968
634
|
append(type: AppendType, raw?: string): this;
|
|
@@ -970,70 +636,40 @@ declare class MarkdownWriterBaseImpl implements MarkdownWriterBase {
|
|
|
970
636
|
end(): string;
|
|
971
637
|
}
|
|
972
638
|
|
|
973
|
-
|
|
974
|
-
/** Report the resolved path to stdout instead of writing. Set by `sveld --dry-run`. */
|
|
975
|
-
dryRun?: boolean;
|
|
976
|
-
}
|
|
977
|
-
|
|
978
|
-
declare class Writer {
|
|
979
|
-
private readonly dryRun;
|
|
980
|
-
/** Directories already created by this writer, so sibling files skip the `mkdir` round trip. */
|
|
981
|
-
private readonly ensuredDirs;
|
|
982
|
-
constructor(options?: WriterOptions);
|
|
983
|
-
/**
|
|
984
|
-
* Skips the write when `filePath` already contains `raw`, so repeated runs
|
|
985
|
-
* over unchanged sources don't touch the file (or its mtime). In dry-run
|
|
986
|
-
* mode, prints `would write "<path>"` to stdout and touches nothing.
|
|
987
|
-
*
|
|
988
|
-
* @returns `true` if the file was written, `false` if it was already up to date.
|
|
989
|
-
*
|
|
990
|
-
* @example
|
|
991
|
-
* ```ts
|
|
992
|
-
* const writer = new Writer();
|
|
993
|
-
* await writer.write("./dist/index.d.ts", "export type Props = {};");
|
|
994
|
-
* ```
|
|
995
|
-
*/
|
|
996
|
-
write(filePath: string, raw: string): Promise<boolean>;
|
|
639
|
+
export declare class BrowserWriterMarkdown extends MarkdownDocument {
|
|
997
640
|
}
|
|
998
641
|
|
|
999
|
-
export
|
|
642
|
+
export type MarkdownWriterBase = MarkdownDocument;
|
|
1000
643
|
|
|
1001
|
-
export
|
|
1002
|
-
schemaVersion: 1;
|
|
1003
|
-
generator: {
|
|
1004
|
-
name: string;
|
|
1005
|
-
version: string;
|
|
1006
|
-
svelteVersion: string;
|
|
1007
|
-
};
|
|
1008
|
-
total: number;
|
|
1009
|
-
components: ComponentDocApi[];
|
|
1010
|
-
/** Only when `documentExports` is on. */
|
|
1011
|
-
totalExports?: number;
|
|
1012
|
-
exports?: EntryExports;
|
|
1013
|
-
}
|
|
644
|
+
export declare function formatTsProps(props?: string): string;
|
|
1014
645
|
|
|
1015
|
-
export
|
|
1016
|
-
/** Entry-barrel exports when `documentExports` is on. */
|
|
1017
|
-
entryExports?: EntryExports;
|
|
1018
|
-
}
|
|
646
|
+
export declare function getTypeDefs(def: Pick<ComponentDocApi, "typedefs">): string;
|
|
1019
647
|
|
|
1020
|
-
export declare function
|
|
648
|
+
export declare function getContextDefs(def: Pick<ComponentDocApi, "contexts" | "generics">): string;
|
|
1021
649
|
|
|
1022
|
-
interface
|
|
1023
|
-
|
|
1024
|
-
|
|
650
|
+
export interface WriteTsDefinitionOptions {
|
|
651
|
+
/**
|
|
652
|
+
* `"class"` (default) extends the deprecated `SvelteComponentTyped`.
|
|
653
|
+
* `"component"` emits `declare const X: Component<Props, Exports, Bindings>`
|
|
654
|
+
* instead, for Svelte 5+ consumers. Generic components get a per-component
|
|
655
|
+
* interface with a generic call signature instead of `Component<...>`
|
|
656
|
+
* directly, since a `declare const` can't itself carry a generic type
|
|
657
|
+
* parameter (see `genGenericComponentDeclaration`).
|
|
658
|
+
*/
|
|
659
|
+
format?: "class" | "component";
|
|
1025
660
|
}
|
|
1026
661
|
|
|
1027
|
-
export declare function
|
|
662
|
+
export declare function writeTsDefinition(component: ComponentDocApi, options?: WriteTsDefinitionOptions): string;
|
|
1028
663
|
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
append(type: AppendType, raw?: string): this;
|
|
664
|
+
interface MarkdownRenderTarget {
|
|
665
|
+
append(type: AppendType, raw?: string): MarkdownRenderTarget;
|
|
666
|
+
tableOfContents(): MarkdownRenderTarget;
|
|
1033
667
|
}
|
|
1034
668
|
|
|
669
|
+
export declare function renderComponentsToMarkdown(document: MarkdownRenderTarget, components: ComponentDocs, entryExports?: EntryExports): void;
|
|
670
|
+
|
|
1035
671
|
export interface WriteMarkdownCoreOptions {
|
|
1036
|
-
onAppend?: (type: AppendType, document:
|
|
672
|
+
onAppend?: (type: AppendType, document: MarkdownDocument, components: ComponentDocs) => void;
|
|
1037
673
|
}
|
|
1038
674
|
|
|
1039
675
|
export declare function writeMarkdownCore(components: ComponentDocs, options?: WriteMarkdownCoreOptions): string;
|