sveld 0.37.5 → 0.37.7
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 +157 -24
- package/lib/browser.d.ts +140 -7
- package/lib/browser.js +190 -162
- package/lib/{chunk-8s0hjkmq.js → chunk-0r8vwqdc.js} +9 -9
- package/lib/chunk-7w571557.js +1 -0
- package/lib/chunk-8xbe5qy3.js +356 -0
- package/lib/chunk-95xn5q1p.js +1 -0
- package/lib/chunk-aw6a570w.js +6 -0
- package/lib/chunk-mxv2ftxe.js +6 -0
- package/lib/cli-entry.js +1 -1
- package/lib/index.js +1 -1
- package/package.json +1 -1
- package/schema/component-api.schema.json +59 -3
- package/lib/chunk-a2krprqa.js +0 -6
- package/lib/chunk-bxzbn9eg.js +0 -1
- package/lib/chunk-k2w5f49f.js +0 -331
- package/lib/chunk-x9qsjgpb.js +0 -6
- package/lib/chunk-znjmdeca.js +0 -1
package/lib/browser.d.ts
CHANGED
|
@@ -42,21 +42,52 @@ interface PendingConstDefaultCandidate {
|
|
|
42
42
|
location: "props" | "moduleExports";
|
|
43
43
|
importSource: string;
|
|
44
44
|
importedName: string;
|
|
45
|
+
/** Members read off the import, through namespace exports: `["DELAY"]` for `C.timing.DELAY`. */
|
|
46
|
+
members?: string[];
|
|
45
47
|
}
|
|
46
48
|
|
|
47
49
|
interface PendingContextKeyCandidate {
|
|
48
50
|
importSource: string;
|
|
49
51
|
importedName: string;
|
|
52
|
+
/** Members read off the import, through namespace exports: `["THEME"]` for `ns.keys.THEME`. */
|
|
53
|
+
members?: string[];
|
|
54
|
+
/** See {@link ComponentContext.type}. */
|
|
55
|
+
type?: string;
|
|
50
56
|
properties: ComponentContextProp[];
|
|
51
57
|
description?: string;
|
|
58
|
+
/** See {@link ComponentContext.hasUnresolvedSpread}. */
|
|
59
|
+
hasUnresolvedSpread?: boolean;
|
|
60
|
+
/** See {@link ComponentContext.internal}. */
|
|
61
|
+
internal?: boolean;
|
|
52
62
|
/** Source range of the `setContext(...)` call, when available. */
|
|
53
63
|
source?: SourceRange;
|
|
54
64
|
}
|
|
55
65
|
|
|
66
|
+
interface PendingDispatchEscapeCandidate {
|
|
67
|
+
importSource: string;
|
|
68
|
+
importedName: string;
|
|
69
|
+
/** Members read off the import, through namespace exports: `["helper"]` for `ns.helper`. */
|
|
70
|
+
members?: string[];
|
|
71
|
+
/** Callee as written, for messages. */
|
|
72
|
+
calleeText: string;
|
|
73
|
+
/** Local name of the `createEventDispatcher()` result. */
|
|
74
|
+
dispatcherName: string;
|
|
75
|
+
/** Argument position the dispatcher is passed at. */
|
|
76
|
+
argumentIndex: number;
|
|
77
|
+
/** Set when passed as an object literal property (`{ dispatch }`): that property's key. */
|
|
78
|
+
property?: string;
|
|
79
|
+
/** Source range of the call, when available. */
|
|
80
|
+
source?: SourceRange;
|
|
81
|
+
/** `@sveld-ignore sveld/dispatch-escapes` on the dispatcher's declaration. */
|
|
82
|
+
ignored?: boolean;
|
|
83
|
+
}
|
|
84
|
+
|
|
56
85
|
interface ParsedComponentTypeScriptMetadata {
|
|
57
86
|
canonicalPropsType?: string;
|
|
58
87
|
canonicalPropNames: string[];
|
|
59
88
|
localTypeDeclarations: string[];
|
|
89
|
+
/** Types the module script exports (`export interface Item`), emitted with `export`. */
|
|
90
|
+
moduleTypeDeclarations?: string[];
|
|
60
91
|
typeImportStatements: string[];
|
|
61
92
|
/**
|
|
62
93
|
* Whether `canonicalPropsType` mentions one of the component's own
|
|
@@ -71,6 +102,18 @@ interface ParsedComponentTypeScriptMetadata {
|
|
|
71
102
|
pendingConstDefaultCandidates?: PendingConstDefaultCandidate[];
|
|
72
103
|
/** Unresolved `setContext` import keys for the cross-file pass in `generateBundle`. */
|
|
73
104
|
pendingContextKeyCandidates?: PendingContextKeyCandidate[];
|
|
105
|
+
/** Dispatchers passed to imported functions, for the cross-file pass in `generateBundle`. */
|
|
106
|
+
pendingDispatchEscapeCandidates?: PendingDispatchEscapeCandidate[];
|
|
107
|
+
/**
|
|
108
|
+
* `event-no-source` diagnostics held back while the dispatcher escapes to
|
|
109
|
+
* imported functions: `generateBundle` keeps those the functions don't dispatch.
|
|
110
|
+
*/
|
|
111
|
+
deferredEventNoSourceDiagnostics?: SveldDiagnostic[];
|
|
112
|
+
/**
|
|
113
|
+
* `@event` tags with no `{type}` or `@property`, whose `null` detail no
|
|
114
|
+
* same-file dispatch replaced; an escaped dispatcher's helper may still.
|
|
115
|
+
*/
|
|
116
|
+
untypedJsDocEventNames?: string[];
|
|
74
117
|
}
|
|
75
118
|
|
|
76
119
|
type SyntaxMode = "legacy" | "runes";
|
|
@@ -126,6 +169,29 @@ interface ComponentPropReExport {
|
|
|
126
169
|
imported: string;
|
|
127
170
|
}
|
|
128
171
|
|
|
172
|
+
interface ComponentClassMember {
|
|
173
|
+
/** `"property"` covers fields, constructor parameter properties, and getter/setter pairs. */
|
|
174
|
+
kind: "constructor" | "method" | "property";
|
|
175
|
+
/** Member name; `"constructor"` for the constructor. */
|
|
176
|
+
name: string;
|
|
177
|
+
/** Property type text; `"any"` when neither TypeScript nor JSDoc types it. */
|
|
178
|
+
type?: string;
|
|
179
|
+
/** Method or constructor parameters, typed from TypeScript or JSDoc `@param`, else `"any"`. A rest parameter's name starts with `...`. */
|
|
180
|
+
params?: ComponentPropParam[];
|
|
181
|
+
/** Method return type from TypeScript or JSDoc `@returns`; unset when neither gives one. */
|
|
182
|
+
returnType?: string;
|
|
183
|
+
/** A method's own type parameter list (`U extends object`), without the angle brackets. */
|
|
184
|
+
typeParameters?: string;
|
|
185
|
+
static?: true;
|
|
186
|
+
/** A `readonly` field, or a getter with no setter. */
|
|
187
|
+
readonly?: true;
|
|
188
|
+
optional?: true;
|
|
189
|
+
abstract?: true;
|
|
190
|
+
description?: string;
|
|
191
|
+
deprecated?: DeprecatedValue;
|
|
192
|
+
tags?: JsDocPassthroughTag[];
|
|
193
|
+
}
|
|
194
|
+
|
|
129
195
|
interface ComponentProp {
|
|
130
196
|
/** Public prop name; `"*"` for a bare `export * from "..."`. */
|
|
131
197
|
name: string;
|
|
@@ -133,8 +199,10 @@ interface ComponentProp {
|
|
|
133
199
|
* `"let"` (required), `"const"` (default), or `"function"`. `"re-export"`
|
|
134
200
|
* is module-export only: `export { x } from "..."`, `export * from "..."`,
|
|
135
201
|
* or `export { x }` of an imported binding, written to the `.d.ts` as-is.
|
|
202
|
+
* `"class"` is module-export only too: a class the module script declares,
|
|
203
|
+
* with its public surface in {@link ComponentProp.members}.
|
|
136
204
|
*/
|
|
137
|
-
kind: "let" | "const" | "function" | "re-export";
|
|
205
|
+
kind: "let" | "const" | "function" | "re-export" | "class";
|
|
138
206
|
/** True when declared with `const`. */
|
|
139
207
|
constant: boolean;
|
|
140
208
|
/** TypeScript type text. */
|
|
@@ -157,8 +225,17 @@ interface ComponentProp {
|
|
|
157
225
|
* A function's own type parameter list from its `@template` tags (e.g.
|
|
158
226
|
* `T extends { id: string }`), without the angle brackets. Also prefixed
|
|
159
227
|
* onto `type` when that signature is built from `@param`/`@returns`.
|
|
228
|
+
* For a `"class"`, the class's type parameters, from TypeScript or `@template`.
|
|
160
229
|
*/
|
|
161
230
|
typeParameters?: string;
|
|
231
|
+
/** Set when `kind` is `"class"`: its public constructor, methods, and properties, in source order. */
|
|
232
|
+
members?: ComponentClassMember[];
|
|
233
|
+
/** Set when `kind` is `"class"` and the class is `abstract`. */
|
|
234
|
+
abstract?: true;
|
|
235
|
+
/** Set when `kind` is `"class"` and it extends a base class: `Base<T>`. */
|
|
236
|
+
extends?: string;
|
|
237
|
+
/** Set when `kind` is `"class"` and it implements interfaces: `["Disposable"]`. */
|
|
238
|
+
implements?: string[];
|
|
162
239
|
/**
|
|
163
240
|
* True for arrow/function-expression initializers and bare `function`
|
|
164
241
|
* declarations in every mode; additionally true for a function-shaped
|
|
@@ -357,9 +434,15 @@ interface ComponentContext {
|
|
|
357
434
|
key: string;
|
|
358
435
|
/** Generated type name (e.g. `"ModalContext"`). */
|
|
359
436
|
typeName: string;
|
|
437
|
+
/**
|
|
438
|
+
* The context's whole type, when the `setContext` value is a variable whose
|
|
439
|
+
* type isn't an object type literal (`ModalAPI`, `Writable<number>`, or `any`
|
|
440
|
+
* when untyped). `properties` is empty then.
|
|
441
|
+
*/
|
|
442
|
+
type?: string;
|
|
360
443
|
/** From JSDoc. */
|
|
361
444
|
description?: string;
|
|
362
|
-
/** Context object properties. */
|
|
445
|
+
/** Context object properties. Empty when {@link ComponentContext.type} is set. */
|
|
363
446
|
properties: ComponentContextProp[];
|
|
364
447
|
/** True when a `{...spread}` in the context's object literal couldn't be resolved; the generated type intersects with `Record<string, any>`. */
|
|
365
448
|
hasUnresolvedSpread?: boolean;
|
|
@@ -452,13 +535,37 @@ export class ComponentParser {
|
|
|
452
535
|
} | undefined;
|
|
453
536
|
private addModuleExport;
|
|
454
537
|
/**
|
|
455
|
-
* Resolves one `export { local as exported }` specifier to the
|
|
456
|
-
*
|
|
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
|
|
457
541
|
* `export { a, b }` exports both, and `const a = 1, b = ""; export { b }`
|
|
458
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.
|
|
459
548
|
*/
|
|
460
549
|
private resolveExportSpecifier;
|
|
461
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;
|
|
462
569
|
/**
|
|
463
570
|
* @example
|
|
464
571
|
* ```ts
|
|
@@ -486,6 +593,17 @@ export class ComponentParser {
|
|
|
486
593
|
description?: string;
|
|
487
594
|
internal?: boolean;
|
|
488
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;
|
|
489
607
|
accumulateGeneric(name: string, constraint: string): void;
|
|
490
608
|
/**
|
|
491
609
|
* Resets parser state for reuse between parses.
|
|
@@ -499,6 +617,7 @@ export class ComponentParser {
|
|
|
499
617
|
*/
|
|
500
618
|
cleanup(): void;
|
|
501
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`). */
|
|
502
621
|
private static readonly TS_DIRECTIVE_REGEX;
|
|
503
622
|
private static stripTypeScriptDirectivesFromScripts;
|
|
504
623
|
/**
|
|
@@ -515,12 +634,15 @@ export class ComponentParser {
|
|
|
515
634
|
parseSvelteComponent(source: string, diagnostics: ComponentParserDiagnostics): ParsedComponent;
|
|
516
635
|
}
|
|
517
636
|
|
|
518
|
-
export type SveldDiagnosticKind = "prop-unknown-type" | "context-any-type" | "slot-missing-type" | "event-no-source" | "example-compile-error" | "example-syntax-error" | "syntax-skipped" | "rest-props-unresolved" | "context-duplicate-key" | "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";
|
|
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";
|
|
519
638
|
|
|
520
639
|
type SveldDiagnosticSeverity = "error" | "warning";
|
|
521
640
|
|
|
522
641
|
export interface SveldDiagnostic {
|
|
523
|
-
/**
|
|
642
|
+
/**
|
|
643
|
+
* File this came from, e.g. `"./Button.svelte"`, or the entry barrel
|
|
644
|
+
* (`"./index.js"`) for `export-ambiguous`.
|
|
645
|
+
*/
|
|
524
646
|
component: string;
|
|
525
647
|
kind: SveldDiagnosticKind;
|
|
526
648
|
/** Stable, namespaced identifier for `kind` (e.g. `"sveld/prop-unknown-type"`). */
|
|
@@ -542,6 +664,13 @@ export interface SveldDiagnostic {
|
|
|
542
664
|
|
|
543
665
|
declare const PARSED_COMPONENT_TYPE_SCRIPT_METADATA: unique symbol;
|
|
544
666
|
|
|
667
|
+
export interface FinalizeWithoutCrossFileResolutionOptions {
|
|
668
|
+
/** Path recorded on the new diagnostics. Defaults to the component's own `filePath`, if it has one. */
|
|
669
|
+
filePath?: string;
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
export declare function finalizeWithoutCrossFileResolution<T extends ParsedComponent>(component: T, options?: FinalizeWithoutCrossFileResolutionOptions): T;
|
|
673
|
+
|
|
545
674
|
export interface ComponentDocApi extends ParsedComponent {
|
|
546
675
|
filePath: NormalizedPath;
|
|
547
676
|
moduleName: string;
|
|
@@ -641,7 +770,11 @@ export declare function writeTsDefinition(component: ComponentDocApi, options?:
|
|
|
641
770
|
interface EntryExport {
|
|
642
771
|
name: string;
|
|
643
772
|
kind: "const" | "let" | "var" | "function" | "class" | "type" | "interface" | "enum";
|
|
644
|
-
/**
|
|
773
|
+
/**
|
|
774
|
+
* Type text from the source, when present. A namespace export
|
|
775
|
+
* (`export * as ns from "./x"`) gets `typeof import("./x.ts")`, the
|
|
776
|
+
* wrapped module relative to the entry file.
|
|
777
|
+
*/
|
|
645
778
|
type?: string;
|
|
646
779
|
/** Initializer text for simple constants. */
|
|
647
780
|
value?: string;
|