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