sveld 0.37.8 → 0.37.9
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 +21 -6
- package/cli.js +7 -0
- package/lib/browser.d.ts +2 -0
- package/lib/browser.js +149 -149
- package/lib/chunk-81w3m3mq.js +8 -0
- package/lib/chunk-f8nq2w4s.js +325 -0
- package/lib/chunk-fk1w3bnw.js +29 -0
- package/lib/chunk-fz6nj0w3.js +4 -0
- package/lib/chunk-r92p6t72.js +1 -0
- package/lib/{chunk-0s0w60zm.js → chunk-wd6xaaes.js} +9 -9
- package/lib/{chunk-dh2cbpn0.js → chunk-yp6p39jn.js} +2 -2
- package/lib/cli-entry.js +1 -1
- package/lib/index.d.ts +1348 -1
- 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-p9hkwnfy.js +0 -1
- package/lib/chunk-sg7vsn8d.js +0 -6
package/lib/index.d.ts
CHANGED
|
@@ -1,3 +1,1350 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import type { Node, Property } from "estree";
|
|
4
|
+
|
|
5
|
+
import type { FunctionDeclaration, VariableDeclaration } from "estree";
|
|
6
|
+
|
|
7
|
+
interface JsDocPassthroughTag {
|
|
8
|
+
name: string;
|
|
9
|
+
body: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
type DeprecatedValue = string | true;
|
|
13
|
+
|
|
14
|
+
interface SourcePosition {
|
|
15
|
+
/** 1-based source line number */
|
|
16
|
+
line: number;
|
|
17
|
+
/** 0-based source column number */
|
|
18
|
+
column: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface SourceRange {
|
|
22
|
+
start: SourcePosition;
|
|
23
|
+
end: SourcePosition;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface PendingCallDefaultCandidate {
|
|
27
|
+
propName: string;
|
|
28
|
+
location: "props" | "moduleExports";
|
|
29
|
+
calleeName: string;
|
|
30
|
+
importSource?: string;
|
|
31
|
+
importedName?: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface PendingConstDefaultCandidate {
|
|
35
|
+
propName: string;
|
|
36
|
+
location: "props" | "moduleExports";
|
|
37
|
+
importSource: string;
|
|
38
|
+
importedName: string;
|
|
39
|
+
/** Members read off the import, through namespace exports: `["DELAY"]` for `C.timing.DELAY`. */
|
|
40
|
+
members?: string[];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
interface PendingContextKeyCandidate {
|
|
44
|
+
importSource: string;
|
|
45
|
+
importedName: string;
|
|
46
|
+
/** Members read off the import, through namespace exports: `["THEME"]` for `ns.keys.THEME`. */
|
|
47
|
+
members?: string[];
|
|
48
|
+
/** See {@link ComponentContext.type}. */
|
|
49
|
+
type?: string;
|
|
50
|
+
properties: ComponentContextProp[];
|
|
51
|
+
description?: string;
|
|
52
|
+
/** See {@link ComponentContext.hasUnresolvedSpread}. */
|
|
53
|
+
hasUnresolvedSpread?: boolean;
|
|
54
|
+
/** See {@link ComponentContext.internal}. */
|
|
55
|
+
internal?: boolean;
|
|
56
|
+
/** Source range of the `setContext(...)` call, when available. */
|
|
57
|
+
source?: SourceRange;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
interface PendingDispatchEscapeCandidate {
|
|
61
|
+
importSource: string;
|
|
62
|
+
importedName: string;
|
|
63
|
+
/** Members read off the import, through namespace exports: `["helper"]` for `ns.helper`. */
|
|
64
|
+
members?: string[];
|
|
65
|
+
/** Callee as written, for messages. */
|
|
66
|
+
calleeText: string;
|
|
67
|
+
/** Local name of the `createEventDispatcher()` result. */
|
|
68
|
+
dispatcherName: string;
|
|
69
|
+
/** Argument position the dispatcher is passed at. */
|
|
70
|
+
argumentIndex: number;
|
|
71
|
+
/** Set when passed as an object literal property (`{ dispatch }`): that property's key. */
|
|
72
|
+
property?: string;
|
|
73
|
+
/** Source range of the call, when available. */
|
|
74
|
+
source?: SourceRange;
|
|
75
|
+
/** `@sveld-ignore sveld/dispatch-escapes` on the dispatcher's declaration. */
|
|
76
|
+
ignored?: boolean;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
interface ParsedComponentTypeScriptMetadata {
|
|
80
|
+
canonicalPropsType?: string;
|
|
81
|
+
canonicalPropNames: string[];
|
|
82
|
+
localTypeDeclarations: string[];
|
|
83
|
+
/** Types the module script exports (`export interface Item`), emitted with `export`. */
|
|
84
|
+
moduleTypeDeclarations?: string[];
|
|
85
|
+
typeImportStatements: string[];
|
|
86
|
+
/**
|
|
87
|
+
* Whether `canonicalPropsType` mentions one of the component's own
|
|
88
|
+
* `<script generics="...">` parameters (e.g. `Props<T>`). The semantic
|
|
89
|
+
* resolver has no binding for `T`, so `resolveTypes` must leave this
|
|
90
|
+
* component's props as their AST-derived text rather than expand them.
|
|
91
|
+
*/
|
|
92
|
+
referencesComponentGenerics?: boolean;
|
|
93
|
+
/** Unresolved CallExpression defaults for the cross-file pass in `generateBundle`. */
|
|
94
|
+
pendingCallDefaultCandidates?: PendingCallDefaultCandidate[];
|
|
95
|
+
/** Imported-identifier defaults for the cross-file pass in `generateBundle`. */
|
|
96
|
+
pendingConstDefaultCandidates?: PendingConstDefaultCandidate[];
|
|
97
|
+
/** Unresolved `setContext` import keys for the cross-file pass in `generateBundle`. */
|
|
98
|
+
pendingContextKeyCandidates?: PendingContextKeyCandidate[];
|
|
99
|
+
/** Dispatchers passed to imported functions, for the cross-file pass in `generateBundle`. */
|
|
100
|
+
pendingDispatchEscapeCandidates?: PendingDispatchEscapeCandidate[];
|
|
101
|
+
/**
|
|
102
|
+
* `event-no-source` diagnostics held back while the dispatcher escapes to
|
|
103
|
+
* imported functions: `generateBundle` keeps those the functions don't dispatch.
|
|
104
|
+
*/
|
|
105
|
+
deferredEventNoSourceDiagnostics?: SveldDiagnostic[];
|
|
106
|
+
/**
|
|
107
|
+
* `@event` tags with no `{type}` or `@property`, whose `null` detail no
|
|
108
|
+
* same-file dispatch replaced; an escaped dispatcher's helper may still.
|
|
109
|
+
*/
|
|
110
|
+
untypedJsDocEventNames?: string[];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
type SyntaxMode = "legacy" | "runes";
|
|
114
|
+
|
|
115
|
+
type ScriptLanguage = "js" | "ts";
|
|
116
|
+
|
|
117
|
+
type ComponentPropTypeSource = "typescript" | "jsdoc" | "default" | "inferred" | "unknown";
|
|
118
|
+
|
|
119
|
+
type ComponentPropDefaultValueKind = "literal" | "array" | "object" | "expression" | "function" | "unknown";
|
|
120
|
+
|
|
121
|
+
interface ComponentPropDefaultValue {
|
|
122
|
+
raw: string;
|
|
123
|
+
kind: ComponentPropDefaultValueKind;
|
|
124
|
+
value?: unknown;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
type ModernScriptAttribute = {
|
|
128
|
+
name?: string;
|
|
129
|
+
value?: Array<{
|
|
130
|
+
data?: string;
|
|
131
|
+
raw?: string;
|
|
132
|
+
}> | boolean;
|
|
133
|
+
start?: number;
|
|
134
|
+
end?: number;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
type ModernScriptNode = {
|
|
138
|
+
attributes?: ModernScriptAttribute[];
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
interface ComponentParserDiagnostics {
|
|
142
|
+
moduleName: string;
|
|
143
|
+
filePath: string;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
type ComponentPropBinding = "readonly" | "writable";
|
|
147
|
+
|
|
148
|
+
interface ComponentPropParam {
|
|
149
|
+
/** Parameter name. */
|
|
150
|
+
name: string;
|
|
151
|
+
/** Parameter type (e.g. `"string"`, `"CustomType"`). */
|
|
152
|
+
type: string;
|
|
153
|
+
/** From JSDoc `@param`. */
|
|
154
|
+
description?: string;
|
|
155
|
+
/** True when optional. */
|
|
156
|
+
optional?: boolean;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
interface ComponentPropReExport {
|
|
160
|
+
/** Module specifier as written in the source (e.g. `"./utils.js"`). */
|
|
161
|
+
from: string;
|
|
162
|
+
/** Name `from` exports: `"default"` for a default import, `"*"` for `export *` or a namespace import. */
|
|
163
|
+
imported: string;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
interface ComponentClassMember {
|
|
167
|
+
/** `"property"` covers fields, constructor parameter properties, and getter/setter pairs. */
|
|
168
|
+
kind: "constructor" | "method" | "property";
|
|
169
|
+
/** Member name; `"constructor"` for the constructor. */
|
|
170
|
+
name: string;
|
|
171
|
+
/** Property type text; `"any"` when neither TypeScript nor JSDoc types it. */
|
|
172
|
+
type?: string;
|
|
173
|
+
/** Method or constructor parameters, typed from TypeScript or JSDoc `@param`, else `"any"`. A rest parameter's name starts with `...`. */
|
|
174
|
+
params?: ComponentPropParam[];
|
|
175
|
+
/** Method return type from TypeScript or JSDoc `@returns`; unset when neither gives one. */
|
|
176
|
+
returnType?: string;
|
|
177
|
+
/** A method's own type parameter list (`U extends object`), without the angle brackets. */
|
|
178
|
+
typeParameters?: string;
|
|
179
|
+
static?: true;
|
|
180
|
+
/** A `readonly` field, or a getter with no setter. */
|
|
181
|
+
readonly?: true;
|
|
182
|
+
optional?: true;
|
|
183
|
+
abstract?: true;
|
|
184
|
+
description?: string;
|
|
185
|
+
deprecated?: DeprecatedValue;
|
|
186
|
+
tags?: JsDocPassthroughTag[];
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
interface ComponentProp {
|
|
190
|
+
/** Public prop name; `"*"` for a bare `export * from "..."`. */
|
|
191
|
+
name: string;
|
|
192
|
+
/**
|
|
193
|
+
* `"let"` (required), `"const"` (default), or `"function"`. `"re-export"`
|
|
194
|
+
* is module-export only: `export { x } from "..."`, `export * from "..."`,
|
|
195
|
+
* or `export { x }` of an imported binding, written to the `.d.ts` as-is.
|
|
196
|
+
* `"class"` is module-export only too: a class the module script declares,
|
|
197
|
+
* with its public surface in {@link ComponentProp.members}.
|
|
198
|
+
*/
|
|
199
|
+
kind: "let" | "const" | "function" | "re-export" | "class";
|
|
200
|
+
/** True when declared with `const`. */
|
|
201
|
+
constant: boolean;
|
|
202
|
+
/** TypeScript type text. */
|
|
203
|
+
type?: string;
|
|
204
|
+
/** Conservative provenance for the prop type. See the precedence rule on {@link ComponentProp}. */
|
|
205
|
+
typeSource?: ComponentPropTypeSource;
|
|
206
|
+
/** Local binding when it differs from the public name. */
|
|
207
|
+
localName?: string;
|
|
208
|
+
/** Default value as source text; unset when the prop has no initializer/default. */
|
|
209
|
+
value?: string;
|
|
210
|
+
/** Structured default value metadata for docs UIs; set alongside `value` from the same initializer. */
|
|
211
|
+
defaultValue?: ComponentPropDefaultValue;
|
|
212
|
+
/** From JSDoc, or a matching `@typedef`'s own description (legacy only; see {@link ComponentProp}). */
|
|
213
|
+
description?: string;
|
|
214
|
+
/** From JSDoc `@param` on function props. */
|
|
215
|
+
params?: ComponentPropParam[];
|
|
216
|
+
/** From JSDoc `@returns` on function props. */
|
|
217
|
+
returnType?: string;
|
|
218
|
+
/**
|
|
219
|
+
* A function's own type parameter list from its `@template` tags (e.g.
|
|
220
|
+
* `T extends { id: string }`), without the angle brackets. Also prefixed
|
|
221
|
+
* onto `type` when that signature is built from `@param`/`@returns`.
|
|
222
|
+
* For a `"class"`, the class's type parameters, from TypeScript or `@template`.
|
|
223
|
+
*/
|
|
224
|
+
typeParameters?: string;
|
|
225
|
+
/** Set when `kind` is `"class"`: its public constructor, methods, and properties, in source order. */
|
|
226
|
+
members?: ComponentClassMember[];
|
|
227
|
+
/** Set when `kind` is `"class"` and the class is `abstract`. */
|
|
228
|
+
abstract?: true;
|
|
229
|
+
/** Set when `kind` is `"class"` and it extends a base class: `Base<T>`. */
|
|
230
|
+
extends?: string;
|
|
231
|
+
/** Set when `kind` is `"class"` and it implements interfaces: `["Disposable"]`. */
|
|
232
|
+
implements?: string[];
|
|
233
|
+
/**
|
|
234
|
+
* True for arrow/function-expression initializers and bare `function`
|
|
235
|
+
* declarations in every mode; additionally true for a function-shaped
|
|
236
|
+
* type/JSDoc signature in runes only (see {@link ComponentProp}).
|
|
237
|
+
*/
|
|
238
|
+
isFunction: boolean;
|
|
239
|
+
/** True for `function` declarations. */
|
|
240
|
+
isFunctionDeclaration: boolean;
|
|
241
|
+
/** True when declared with `let` and no default. */
|
|
242
|
+
isRequired: boolean;
|
|
243
|
+
/**
|
|
244
|
+
* True when the prop is mutated locally (legacy, inferred from assignment/
|
|
245
|
+
* binding targets) or declared with `$bindable()` (runes).
|
|
246
|
+
*/
|
|
247
|
+
reactive: boolean;
|
|
248
|
+
/** Binding direction from `@bindable` JSDoc. */
|
|
249
|
+
binding?: ComponentPropBinding;
|
|
250
|
+
/** True when declared with Svelte 5 `$bindable()` (runes only). */
|
|
251
|
+
bindable?: true;
|
|
252
|
+
/** From `@deprecated` JSDoc. */
|
|
253
|
+
deprecated?: DeprecatedValue;
|
|
254
|
+
/** `@since` / `@example` tags in source order. */
|
|
255
|
+
tags?: JsDocPassthroughTag[];
|
|
256
|
+
/** True from `@ignore`/`@internal` JSDoc; excluded from every output by `buildComponentApiDocument`. */
|
|
257
|
+
internal?: boolean;
|
|
258
|
+
/** Set when `kind` is `"re-export"`. */
|
|
259
|
+
reExport?: ComponentPropReExport;
|
|
260
|
+
/** Source range when available. */
|
|
261
|
+
source?: SourceRange;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
interface ComponentSlot {
|
|
265
|
+
/** Slot name (`null` for the default slot). */
|
|
266
|
+
name?: string | null;
|
|
267
|
+
/** True for the default slot. */
|
|
268
|
+
default: boolean;
|
|
269
|
+
/** Fallback content when the slot is empty. */
|
|
270
|
+
fallback?: string;
|
|
271
|
+
/** Slot props as TypeScript type text. */
|
|
272
|
+
slot_props?: string;
|
|
273
|
+
/** From JSDoc `@slot` or `@snippet`. */
|
|
274
|
+
description?: string;
|
|
275
|
+
/** From `@deprecated` JSDoc. */
|
|
276
|
+
deprecated?: DeprecatedValue;
|
|
277
|
+
/** Tags between the description and `@slot`/`@snippet` (e.g. `@example`), in source order. */
|
|
278
|
+
tags?: JsDocPassthroughTag[];
|
|
279
|
+
/** True from `@ignore`/`@internal` JSDoc; excluded from every output by `buildComponentApiDocument`. */
|
|
280
|
+
internal?: boolean;
|
|
281
|
+
/** Source range when available. */
|
|
282
|
+
source?: SourceRange;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
interface DispatchedEvent {
|
|
286
|
+
/** Discriminator: `"dispatched"`. */
|
|
287
|
+
type: "dispatched";
|
|
288
|
+
/** Event name. */
|
|
289
|
+
name: string;
|
|
290
|
+
/** Detail type text. */
|
|
291
|
+
detail?: string;
|
|
292
|
+
/** From JSDoc `@event`. */
|
|
293
|
+
description?: string;
|
|
294
|
+
/** From `@deprecated` JSDoc. */
|
|
295
|
+
deprecated?: DeprecatedValue;
|
|
296
|
+
/** `@since` / `@example` tags in source order. */
|
|
297
|
+
tags?: JsDocPassthroughTag[];
|
|
298
|
+
/** True from `@ignore`/`@internal` JSDoc; excluded from every output by `buildComponentApiDocument`. */
|
|
299
|
+
internal?: boolean;
|
|
300
|
+
/** Source range when available. */
|
|
301
|
+
source?: SourceRange;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
interface SerializedForwardedEvent {
|
|
305
|
+
/** Discriminator: `"forwarded"`. */
|
|
306
|
+
type: "forwarded";
|
|
307
|
+
/** Event name. */
|
|
308
|
+
name: string;
|
|
309
|
+
/** Element name as a string for JSON output. */
|
|
310
|
+
element: string;
|
|
311
|
+
/** From JSDoc `@event`. */
|
|
312
|
+
description?: string;
|
|
313
|
+
/** From `@deprecated` JSDoc. */
|
|
314
|
+
deprecated?: DeprecatedValue;
|
|
315
|
+
/** Detail type from `@event`. */
|
|
316
|
+
detail?: string;
|
|
317
|
+
/** `@since` / `@example` tags in source order. */
|
|
318
|
+
tags?: JsDocPassthroughTag[];
|
|
319
|
+
/** True from `@ignore`/`@internal` JSDoc; excluded from every output by `buildComponentApiDocument`. */
|
|
320
|
+
internal?: boolean;
|
|
321
|
+
/** Source range when available. */
|
|
322
|
+
source?: SourceRange;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
export type SerializedComponentEvent = SerializedForwardedEvent | DispatchedEvent;
|
|
326
|
+
|
|
327
|
+
interface TypeDef {
|
|
328
|
+
/** Type text (e.g. `"{ x: number; y: number }"`). */
|
|
329
|
+
type: string;
|
|
330
|
+
/** Type name. */
|
|
331
|
+
name: string;
|
|
332
|
+
/** From JSDoc. */
|
|
333
|
+
description?: string;
|
|
334
|
+
/** Full `type` alias declaration text. */
|
|
335
|
+
ts: string;
|
|
336
|
+
/** Tags in the same block (e.g. `@since`, `@example`, `@see`), in source order. */
|
|
337
|
+
tags?: JsDocPassthroughTag[];
|
|
338
|
+
/** True from `@ignore`/`@internal` JSDoc; excluded from every output by `buildComponentApiDocument`. */
|
|
339
|
+
internal?: boolean;
|
|
340
|
+
/** Source range of the `@typedef`/`@callback` tag, when available. */
|
|
341
|
+
source?: SourceRange;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
type ComponentGenerics = [name: string, type: string] | null;
|
|
345
|
+
|
|
346
|
+
interface ComponentInlineElement {
|
|
347
|
+
/** Discriminator: `"InlineComponent"`. */
|
|
348
|
+
type: "InlineComponent";
|
|
349
|
+
/** Component name. */
|
|
350
|
+
name: string;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
interface ComponentElement {
|
|
354
|
+
type: "Element";
|
|
355
|
+
name: string;
|
|
356
|
+
/**
|
|
357
|
+
* Static tag for `svelte:element this="div"`. Undefined when `this` is dynamic.
|
|
358
|
+
*
|
|
359
|
+
* @example
|
|
360
|
+
* ```svelte
|
|
361
|
+
* <!-- Static tag -->
|
|
362
|
+
* <svelte:element this="div" bind:this={elementRef} />
|
|
363
|
+
* // thisValue: "div"
|
|
364
|
+
*
|
|
365
|
+
* <!-- Dynamic tag -->
|
|
366
|
+
* <svelte:element this={tagName} bind:this={elementRef} />
|
|
367
|
+
* // thisValue: undefined
|
|
368
|
+
* ```
|
|
369
|
+
*/
|
|
370
|
+
thisValue?: string;
|
|
371
|
+
/** From `@restProps` JSDoc. */
|
|
372
|
+
description?: string;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
type RestProps = undefined | ComponentInlineElement | ComponentElement;
|
|
376
|
+
|
|
377
|
+
interface Extends {
|
|
378
|
+
/** Interface name (e.g. `"ButtonProps"`). */
|
|
379
|
+
interface: string;
|
|
380
|
+
/** Import path (e.g. `"./types"`). */
|
|
381
|
+
import: string;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
type CustomElementPropType = "String" | "Boolean" | "Number" | "Array" | "Object";
|
|
385
|
+
|
|
386
|
+
interface CustomElementPropConfig {
|
|
387
|
+
/** Explicit attribute name. Svelte itself always observes every prop as an attribute; sveld's own output omits the attribute entirely when this is `false`. */
|
|
388
|
+
attribute?: string | false;
|
|
389
|
+
reflect?: boolean;
|
|
390
|
+
type?: CustomElementPropType;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
interface CustomElementOptions {
|
|
394
|
+
tag?: string;
|
|
395
|
+
shadow?: "open" | "none";
|
|
396
|
+
props?: Record<string, CustomElementPropConfig>;
|
|
397
|
+
extend?: true;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
interface ComponentCssPart {
|
|
401
|
+
name: string;
|
|
402
|
+
description?: string;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
interface ComponentCssProperty {
|
|
406
|
+
/** Includes the leading `--`. */
|
|
407
|
+
name: string;
|
|
408
|
+
type?: string;
|
|
409
|
+
default?: string;
|
|
410
|
+
description?: string;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
interface ComponentContextProp {
|
|
414
|
+
/** Property name. */
|
|
415
|
+
name: string;
|
|
416
|
+
/** Property type text. */
|
|
417
|
+
type: string;
|
|
418
|
+
/** From JSDoc. */
|
|
419
|
+
description?: string;
|
|
420
|
+
/** True when optional. */
|
|
421
|
+
optional: boolean;
|
|
422
|
+
/** True from `@ignore`/`@internal` JSDoc; excluded from every output by `buildComponentApiDocument`. */
|
|
423
|
+
internal?: boolean;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
interface ComponentContext {
|
|
427
|
+
/** Context key from `setContext`. */
|
|
428
|
+
key: string;
|
|
429
|
+
/** Generated type name (e.g. `"ModalContext"`). */
|
|
430
|
+
typeName: string;
|
|
431
|
+
/**
|
|
432
|
+
* The context's whole type, when the `setContext` value is a variable whose
|
|
433
|
+
* type isn't an object type literal (`ModalAPI`, `Writable<number>`, or `any`
|
|
434
|
+
* when untyped). `properties` is empty then.
|
|
435
|
+
*/
|
|
436
|
+
type?: string;
|
|
437
|
+
/** From JSDoc. */
|
|
438
|
+
description?: string;
|
|
439
|
+
/** Context object properties. Empty when {@link ComponentContext.type} is set. */
|
|
440
|
+
properties: ComponentContextProp[];
|
|
441
|
+
/** True when a `{...spread}` in the context's object literal couldn't be resolved; the generated type intersects with `Record<string, any>`. */
|
|
442
|
+
hasUnresolvedSpread?: boolean;
|
|
443
|
+
/** True from `@ignore`/`@internal` JSDoc on the `setContext` call; excluded from every output by `buildComponentApiDocument`. */
|
|
444
|
+
internal?: boolean;
|
|
445
|
+
/** Source range of the `setContext(...)` call, when available. */
|
|
446
|
+
source?: SourceRange;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
interface ParsedComponent {
|
|
450
|
+
/** Source range of the parsed file. */
|
|
451
|
+
source?: SourceRange;
|
|
452
|
+
syntaxMode: SyntaxMode;
|
|
453
|
+
scriptLanguage?: ScriptLanguage;
|
|
454
|
+
/** Instance-level props (`export let`/`export function`, or runes `$props()`). See {@link ComponentProp} for the shared IR these are built from. */
|
|
455
|
+
props: ComponentProp[];
|
|
456
|
+
/** Exports from `<script context="module">`. Same {@link ComponentProp} shape as `props`, resolved through the same shared decisions. */
|
|
457
|
+
moduleExports: ComponentProp[];
|
|
458
|
+
slots: ComponentSlot[];
|
|
459
|
+
/** Serialized events for JSON/API output. */
|
|
460
|
+
events: SerializedComponentEvent[];
|
|
461
|
+
typedefs: TypeDef[];
|
|
462
|
+
generics: null | ComponentGenerics;
|
|
463
|
+
rest_props: RestProps;
|
|
464
|
+
extends?: Extends;
|
|
465
|
+
/** From `@component` HTML comment. */
|
|
466
|
+
componentComment?: string;
|
|
467
|
+
componentCommentSource?: SourceRange;
|
|
468
|
+
contexts?: ComponentContext[];
|
|
469
|
+
customElementTag?: string;
|
|
470
|
+
/** Full `<svelte:options customElement=... />` config (shorthand or object form), when present. */
|
|
471
|
+
customElement?: CustomElementOptions;
|
|
472
|
+
/** From component-level `@csspart` JSDoc tags. */
|
|
473
|
+
cssParts?: ComponentCssPart[];
|
|
474
|
+
/** From component-level `@cssprop`/`@cssproperty` JSDoc tags. */
|
|
475
|
+
cssProperties?: ComponentCssProperty[];
|
|
476
|
+
/**
|
|
477
|
+
* Type guesses from this parse (unknown props, `any` contexts, orphan `@event` tags).
|
|
478
|
+
*/
|
|
479
|
+
diagnostics?: SveldDiagnostic[];
|
|
480
|
+
/** Writer-only TypeScript metadata. Not serialized to JSON. */
|
|
481
|
+
[PARSED_COMPONENT_TYPE_SCRIPT_METADATA]?: ParsedComponentTypeScriptMetadata;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
export class ComponentParser {
|
|
485
|
+
/**
|
|
486
|
+
* All per-parse mutable state (props, slots, events, scopes, source, etc.).
|
|
487
|
+
* See {@link ParserContext} for field-by-field documentation. Replaced
|
|
488
|
+
* wholesale by `cleanup()` between parses.
|
|
489
|
+
*/
|
|
490
|
+
private ctx;
|
|
491
|
+
private static mapToArray;
|
|
492
|
+
private static getStaticAttributeValue;
|
|
493
|
+
resolveScriptLanguage(parsed: {
|
|
494
|
+
instance?: ModernScriptNode;
|
|
495
|
+
module?: ModernScriptNode;
|
|
496
|
+
}): ScriptLanguage | undefined;
|
|
497
|
+
/**
|
|
498
|
+
* Reads the `generics` attribute off the instance script (Svelte only allows
|
|
499
|
+
* it there, and only alongside `lang="ts"`). Returns the raw value for later
|
|
500
|
+
* precedence resolution against `@generics`/`@template` JSDoc tags, or
|
|
501
|
+
* `undefined` if absent. Records a `syntax-skipped` diagnostic and returns
|
|
502
|
+
* `undefined` if the attribute is present without `lang="ts"`, since sveld
|
|
503
|
+
* can't safely guess how to parse it as plain JavaScript.
|
|
504
|
+
*/
|
|
505
|
+
resolveScriptGenericsAttribute(parsed: {
|
|
506
|
+
instance?: ModernScriptNode;
|
|
507
|
+
}): {
|
|
508
|
+
value: string;
|
|
509
|
+
source?: SourceRange;
|
|
510
|
+
} | undefined;
|
|
511
|
+
private resolvePublicPropName;
|
|
512
|
+
trackPropLocalName(propName: string, localName?: string): void;
|
|
513
|
+
private getPropByLocalOrPublic;
|
|
514
|
+
getPropTypeByLocalOrPublic(name: string): string | undefined;
|
|
515
|
+
getExplicitPropType(name: string): string | undefined;
|
|
516
|
+
getPropertyName(node: Property["key"]): string | undefined;
|
|
517
|
+
isNumericConstant(memberExpr: unknown): boolean;
|
|
518
|
+
resolveLocalVarJSDoc(name: string): {
|
|
519
|
+
type?: string;
|
|
520
|
+
params?: ComponentPropParam[];
|
|
521
|
+
returnType?: string;
|
|
522
|
+
description?: string;
|
|
523
|
+
binding?: ComponentPropBinding;
|
|
524
|
+
deprecated?: DeprecatedValue;
|
|
525
|
+
tags?: JsDocPassthroughTag[];
|
|
526
|
+
sveldIgnore?: string[];
|
|
527
|
+
internal: boolean;
|
|
528
|
+
typeParameters?: string;
|
|
529
|
+
} | undefined;
|
|
530
|
+
private addModuleExport;
|
|
531
|
+
/**
|
|
532
|
+
* Resolves one `export { local as exported }` specifier to the top-level
|
|
533
|
+
* function, class, or variable declarator (including one destructured
|
|
534
|
+
* from a pattern) it names. Each specifier resolves on its own, so
|
|
535
|
+
* `export { a, b }` exports both, and `const a = 1, b = ""; export { b }`
|
|
536
|
+
* exports `b`'s declarator rather than the first one in the declaration.
|
|
537
|
+
*
|
|
538
|
+
* `program` is the script the export sits in: only its top-level
|
|
539
|
+
* declarations count, not a same-named variable inside a function. An
|
|
540
|
+
* instance-script export can also name a module-script declaration, or a
|
|
541
|
+
* variable that a `$: local = ...` reactive declaration declares implicitly.
|
|
542
|
+
*/
|
|
543
|
+
private resolveExportSpecifier;
|
|
544
|
+
private recordUnresolvedExportSpecifier;
|
|
545
|
+
/**
|
|
546
|
+
* Doc comment for a declaration exported by `node`. A specifier uses the
|
|
547
|
+
* comment on the declaration it names. An `export { ... }` list's own
|
|
548
|
+
* comment documents it too, but only when the list has a single specifier;
|
|
549
|
+
* its tags and description then override the declaration's.
|
|
550
|
+
*/
|
|
551
|
+
private exportJSDoc;
|
|
552
|
+
/** An instance-script `export class Foo {}` or `export { Foo }` of a class: neither a prop nor a documented accessor. */
|
|
553
|
+
private recordClassExport;
|
|
554
|
+
/**
|
|
555
|
+
* The `.d.ts` can only say `extends Base` when `Base` is in scope there:
|
|
556
|
+
* imported, or another exported class. A class extending anything else
|
|
557
|
+
* (a local class, a call like `mixin(Base)`) is declared without it, and
|
|
558
|
+
* flagged, since consumers won't see its inherited members.
|
|
559
|
+
*/
|
|
560
|
+
private dropUndeclaredClassBases;
|
|
561
|
+
/** A module-script `export class Foo {}` or `export { Foo }` of a class, with its public members. */
|
|
562
|
+
private addModuleClassExport;
|
|
563
|
+
/**
|
|
564
|
+
* @example
|
|
565
|
+
* ```ts
|
|
566
|
+
* aliasType("*"); // "any"
|
|
567
|
+
* aliasType(" string "); // "string"
|
|
568
|
+
* ```
|
|
569
|
+
*/
|
|
570
|
+
aliasType(type: string): string;
|
|
571
|
+
/**
|
|
572
|
+
* @example
|
|
573
|
+
* ```ts
|
|
574
|
+
* // Given:
|
|
575
|
+
* // /**
|
|
576
|
+
* // * @type {number}
|
|
577
|
+
* // * The count value
|
|
578
|
+
* // *\/
|
|
579
|
+
* // const count = 0;
|
|
580
|
+
*
|
|
581
|
+
* findVariableTypeAndDescription("count");
|
|
582
|
+
* // { type: "number", description: "The count value" }
|
|
583
|
+
* ```
|
|
584
|
+
*/
|
|
585
|
+
findVariableTypeAndDescription(varName: string): {
|
|
586
|
+
type: string;
|
|
587
|
+
description?: string;
|
|
588
|
+
internal?: boolean;
|
|
589
|
+
} | null;
|
|
590
|
+
/**
|
|
591
|
+
* The description and `@internal` flag of the JSDoc above `varName`,
|
|
592
|
+
* whether or not it has a `@type`. For a variable typed some other way,
|
|
593
|
+
* such as from its initializer.
|
|
594
|
+
*/
|
|
595
|
+
findVariableJsDoc(varName: string): {
|
|
596
|
+
description?: string;
|
|
597
|
+
internal?: boolean;
|
|
598
|
+
};
|
|
599
|
+
/** The JSDoc table entry for `varName`, building the table on first use. */
|
|
600
|
+
private variableJsDocEntry;
|
|
601
|
+
accumulateGeneric(name: string, constraint: string): void;
|
|
602
|
+
/**
|
|
603
|
+
* Resets parser state for reuse between parses.
|
|
604
|
+
*
|
|
605
|
+
* @example
|
|
606
|
+
* ```ts
|
|
607
|
+
* parser.parseSvelteComponent(source1, diagnostics1);
|
|
608
|
+
* parser.cleanup();
|
|
609
|
+
* parser.parseSvelteComponent(source2, diagnostics2);
|
|
610
|
+
* ```
|
|
611
|
+
*/
|
|
612
|
+
cleanup(): void;
|
|
613
|
+
private static readonly SCRIPT_BLOCK_REGEX;
|
|
614
|
+
/** A `// @ts-...` comment, but not one on a `*` line of a JSDoc block (e.g. in an `@example`). */
|
|
615
|
+
private static readonly TS_DIRECTIVE_REGEX;
|
|
616
|
+
private static stripTypeScriptDirectivesFromScripts;
|
|
617
|
+
/**
|
|
618
|
+
* @example
|
|
619
|
+
* ```ts
|
|
620
|
+
* const parser = new ComponentParser();
|
|
621
|
+
* const result = parser.parseSvelteComponent(source, {
|
|
622
|
+
* moduleName: "Button",
|
|
623
|
+
* filePath: "./Button.svelte"
|
|
624
|
+
* });
|
|
625
|
+
* // { props, slots, events, typedefs, ... }
|
|
626
|
+
* ```
|
|
627
|
+
*/
|
|
628
|
+
parseSvelteComponent(source: string, diagnostics: ComponentParserDiagnostics): ParsedComponent;
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
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";
|
|
632
|
+
|
|
633
|
+
export type SveldDiagnosticSeverity = "error" | "warning";
|
|
634
|
+
|
|
635
|
+
export declare const DIAGNOSTIC_CODES: Record<SveldDiagnosticKind, string>;
|
|
636
|
+
|
|
637
|
+
export interface SveldDiagnostic {
|
|
638
|
+
/**
|
|
639
|
+
* File this came from, e.g. `"./Button.svelte"`, or the entry barrel
|
|
640
|
+
* (`"./index.js"`) for `export-ambiguous`.
|
|
641
|
+
*/
|
|
642
|
+
component: string;
|
|
643
|
+
kind: SveldDiagnosticKind;
|
|
644
|
+
/** Stable, namespaced identifier for `kind` (e.g. `"sveld/prop-unknown-type"`). */
|
|
645
|
+
code: string;
|
|
646
|
+
severity: SveldDiagnosticSeverity;
|
|
647
|
+
/** Prop, context field, or event name. */
|
|
648
|
+
name: string;
|
|
649
|
+
/** What went wrong and what type sveld used. */
|
|
650
|
+
message: string;
|
|
651
|
+
/** Where in the component source this diagnostic points, when the parser holds a stable position. */
|
|
652
|
+
source?: SourceRange;
|
|
653
|
+
/**
|
|
654
|
+
* True when suppressed by an inline `@sveld-ignore` tag or a `diagnostics.ignore`
|
|
655
|
+
* config matcher. Still present here (and counted in the summary) but never
|
|
656
|
+
* fails `--strict` / `--strict=errors`.
|
|
657
|
+
*/
|
|
658
|
+
ignored?: boolean;
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
export interface DiagnosticIgnoreMatcher {
|
|
662
|
+
code?: string;
|
|
663
|
+
component?: string;
|
|
664
|
+
name?: string;
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
export declare const DIAGNOSTICS_SCHEMA_VERSION = 1;
|
|
668
|
+
|
|
669
|
+
export interface DiagnosticsJson {
|
|
670
|
+
kind: "diagnostics";
|
|
671
|
+
schemaVersion: typeof DIAGNOSTICS_SCHEMA_VERSION;
|
|
672
|
+
diagnostics: SveldDiagnostic[];
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
declare const PARSED_COMPONENT_TYPE_SCRIPT_METADATA: unique symbol;
|
|
676
|
+
|
|
677
|
+
export type SemverBump = "major" | "minor" | "patch" | "none";
|
|
678
|
+
|
|
679
|
+
export interface ApiChange {
|
|
680
|
+
/** Component `moduleName` this change belongs to, or `"*"` for document-wide notices. */
|
|
681
|
+
component: string;
|
|
682
|
+
kind: "component" | "prop" | "moduleExport" | "event" | "slot" | "shape" | "schema";
|
|
683
|
+
/** Prop, event, slot, or shape-field name, when applicable. */
|
|
684
|
+
name?: string;
|
|
685
|
+
bump: SemverBump;
|
|
686
|
+
message: string;
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
export interface CheckResult {
|
|
690
|
+
/** `false` when there was nothing on disk to diff against (e.g. first run). */
|
|
691
|
+
snapshotExists: boolean;
|
|
692
|
+
snapshotFile: string;
|
|
693
|
+
changes: ApiChange[];
|
|
694
|
+
/** Highest bump across all changes. */
|
|
695
|
+
bump: SemverBump;
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
export declare function diffApiDocuments(previous: ComponentApiDocument, next: ComponentApiDocument): ApiChange[];
|
|
699
|
+
|
|
700
|
+
interface RunCheckOptions {
|
|
701
|
+
/** Entry-barrel exports when `documentExports` is on. */
|
|
702
|
+
entryExports?: EntryExports;
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
export declare function runCheck(components: ComponentDocs, snapshotFile: string, options?: RunCheckOptions): Promise<CheckResult>;
|
|
706
|
+
|
|
707
|
+
export declare function formatCheckReport(result: CheckResult): string;
|
|
708
|
+
|
|
709
|
+
export declare const CHECK_REPORT_SCHEMA_VERSION = 1;
|
|
710
|
+
|
|
711
|
+
export type CheckReportJson = CheckResult & {
|
|
712
|
+
kind: "check-report";
|
|
713
|
+
schemaVersion: typeof CHECK_REPORT_SCHEMA_VERSION;
|
|
714
|
+
};
|
|
715
|
+
|
|
716
|
+
export declare function formatCheckReportJson(result: CheckResult): string;
|
|
717
|
+
|
|
718
|
+
interface ComponentDocApi extends ParsedComponent {
|
|
719
|
+
filePath: NormalizedPath;
|
|
720
|
+
moduleName: string;
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
type ComponentDocs = Map<string, ComponentDocApi>;
|
|
724
|
+
|
|
725
|
+
interface ComponentParseError {
|
|
726
|
+
filePath: string;
|
|
727
|
+
moduleName: string;
|
|
728
|
+
message: string;
|
|
729
|
+
stack?: string;
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
interface GenerateBundleOptions {
|
|
733
|
+
/**
|
|
734
|
+
* Throw on the first component that fails to parse instead of collecting
|
|
735
|
+
* the failure and continuing with the remaining components.
|
|
736
|
+
*/
|
|
737
|
+
failFast?: boolean;
|
|
738
|
+
/**
|
|
739
|
+
* Load the TypeScript program to expand opaque imported whole-object `$props()`
|
|
740
|
+
* types into JSON/Markdown props. Off by default; requires `typescript`.
|
|
741
|
+
*/
|
|
742
|
+
resolveTypes?: boolean;
|
|
743
|
+
/** Record consts, functions, and types from the entry barrel. Off by default. */
|
|
744
|
+
documentExports?: boolean;
|
|
745
|
+
/**
|
|
746
|
+
* Cache parsed component output to disk. Unchanged files skip re-parsing on
|
|
747
|
+
* later runs. On by default, writing to
|
|
748
|
+
* `node_modules/.cache/sveld/parse-cache.json`; a string sets a custom path.
|
|
749
|
+
* Pass `false` to disable.
|
|
750
|
+
*/
|
|
751
|
+
cache?: boolean | string;
|
|
752
|
+
/**
|
|
753
|
+
* Check `@example` blocks on props, module exports, slots, and events.
|
|
754
|
+
* `true` runs plain TS/JS examples through the TypeScript program
|
|
755
|
+
* (`example-compile-error` diagnostics; requires `typescript`) and
|
|
756
|
+
* Svelte/HTML examples through sveld's own template parser
|
|
757
|
+
* (`example-syntax-error` diagnostics; no `typescript` needed). Pass
|
|
758
|
+
* `"syntax"` to run only the markup path, so `typescript` is never loaded
|
|
759
|
+
* even when TS/JS examples exist. Off by default.
|
|
760
|
+
*/
|
|
761
|
+
checkExamples?: boolean | "syntax";
|
|
762
|
+
/**
|
|
763
|
+
* Parse as usual (so cache reads and real errors still apply) but skip
|
|
764
|
+
* persisting the parse cache to disk. Set by the CLI's `--dry-run`.
|
|
765
|
+
*/
|
|
766
|
+
dryRun?: boolean;
|
|
767
|
+
/**
|
|
768
|
+
* `ignore`: diagnostics matching at least one `{ code?, component?, name? }`
|
|
769
|
+
* matcher are marked `ignored` (an omitted field matches anything;
|
|
770
|
+
* `component` is a glob). Ignored diagnostics still appear in
|
|
771
|
+
* `SveldResult.diagnostics` and are counted in the text summary, but never
|
|
772
|
+
* fail `--strict` / `--strict=errors`.
|
|
773
|
+
*/
|
|
774
|
+
diagnostics?: {
|
|
775
|
+
ignore?: DiagnosticIgnoreMatcher[];
|
|
776
|
+
};
|
|
777
|
+
/**
|
|
778
|
+
* Mirrors `typesOptions.typeNames`: templates for the `<Name>Props`
|
|
779
|
+
* interface name that `@extends`/`@extendProps` validation checks against.
|
|
780
|
+
*/
|
|
781
|
+
typesTypeNames?: WriteTsDefinitionOptions["typeNames"];
|
|
782
|
+
/**
|
|
783
|
+
* Mirrors `typesOptions.inline`: `"local"`/`"all"` runs the cross-file
|
|
784
|
+
* inlining pass (see `inline-types.ts`) after every component has parsed.
|
|
785
|
+
*/
|
|
786
|
+
typesInline?: WriteTsDefinitionOptions["inline"];
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
declare const brand: unique symbol;
|
|
790
|
+
|
|
791
|
+
type Brand<TBase extends string, TBrand extends string> = TBase & {
|
|
792
|
+
readonly [brand]: TBrand;
|
|
793
|
+
};
|
|
794
|
+
|
|
795
|
+
export type SvelteEntryPoint = Brand<string, "SvelteEntryPoint">;
|
|
796
|
+
|
|
797
|
+
type NormalizedPath = Brand<string, "NormalizedPath">;
|
|
798
|
+
|
|
799
|
+
type RelativeSourcePath = Brand<string, "RelativeSourcePath">;
|
|
800
|
+
|
|
801
|
+
interface InlinedTypes {
|
|
802
|
+
/** Exact `typeImportStatements` entries the writer must drop. */
|
|
803
|
+
droppedImportStatements: string[];
|
|
804
|
+
/** Declarations to emit (already stripped of `export`), in dependency order. */
|
|
805
|
+
declarations: string[];
|
|
806
|
+
/** Absolute paths of every file read, for watch-mode invalidation. */
|
|
807
|
+
dependencies: string[];
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
interface WriteTsDefinitionOptions {
|
|
811
|
+
/**
|
|
812
|
+
* `"class"` (default) extends the deprecated `SvelteComponentTyped`.
|
|
813
|
+
* `"component"` emits `declare const X: Component<Props, Exports, Bindings>`
|
|
814
|
+
* instead, for Svelte 5+ consumers. Generic components get a per-component
|
|
815
|
+
* interface with a generic call signature instead of `Component<...>`
|
|
816
|
+
* directly, since a `declare const` can't itself carry a generic type
|
|
817
|
+
* parameter (see `genGenericComponentDeclaration`).
|
|
818
|
+
*/
|
|
819
|
+
format?: "class" | "component";
|
|
820
|
+
/**
|
|
821
|
+
* Which generated type declarations get an `export` keyword. `true`
|
|
822
|
+
* (default) exports all; `false` exports none; an object picks per kind.
|
|
823
|
+
* Module-script exports (`export declare const/function`) are runtime
|
|
824
|
+
* exports and are always emitted as exports.
|
|
825
|
+
*/
|
|
826
|
+
exportTypes?: boolean | {
|
|
827
|
+
props?: boolean;
|
|
828
|
+
exports?: boolean;
|
|
829
|
+
typedefs?: boolean;
|
|
830
|
+
contexts?: boolean;
|
|
831
|
+
};
|
|
832
|
+
/** @internal Set by `writeTsDefinitions` for `@extends` targets; overrides `exportTypes.props`. */
|
|
833
|
+
forceExportProps?: boolean;
|
|
834
|
+
/**
|
|
835
|
+
* Templates for generated type names. `{name}` is replaced with the
|
|
836
|
+
* component's module name. Defaults: `"{name}Props"`, `"{name}Exports"`.
|
|
837
|
+
*/
|
|
838
|
+
typeNames?: {
|
|
839
|
+
props?: string;
|
|
840
|
+
exports?: string;
|
|
841
|
+
};
|
|
842
|
+
/**
|
|
843
|
+
* How much JSDoc to emit. `"all"` (default) keeps descriptions,
|
|
844
|
+
* `@deprecated`, `@default`, and passthrough tags (`@since`, `@see`,
|
|
845
|
+
* `@example`, `@link`). `"descriptions"` keeps descriptions and
|
|
846
|
+
* `@deprecated` only. `"none"` emits no comments at all.
|
|
847
|
+
*/
|
|
848
|
+
comments?: "all" | "descriptions" | "none";
|
|
849
|
+
/**
|
|
850
|
+
* `"type"` (default) emits the props type as a type alias.
|
|
851
|
+
* `"interface"` emits `interface <Name>Props { ... }` when the props are a
|
|
852
|
+
* plain object (no `@restProps`, no `@extendProps`, no whole-object
|
|
853
|
+
* `$props()` type); other shapes are intersections and stay aliases.
|
|
854
|
+
*/
|
|
855
|
+
propsDeclaration?: "type" | "interface";
|
|
856
|
+
/**
|
|
857
|
+
* Copies `type`/`interface` declarations imported from a relative source (or a
|
|
858
|
+
* tsconfig/jsconfig path alias) directly into the `.d.ts`, dropping the import. `"local"`
|
|
859
|
+
* follows relative sources, path aliases, re-exports, and same-file dependencies; bare package
|
|
860
|
+
* imports, `.svelte` sources, and unsupported exports (enums, classes, functions, consts,
|
|
861
|
+
* namespaces) stay imports and get a `types-inline-unresolved` warning. `"all"` additionally
|
|
862
|
+
* inlines bare/package imports (e.g. `import type { Foo } from "some-lib"`) using the real
|
|
863
|
+
* TypeScript checker - same unsupported-export/collision rules, same warning on failure - with
|
|
864
|
+
* two exceptions kept as plain imports regardless: `svelte`/`svelte/elements` (a hard-coded
|
|
865
|
+
* allow-list; copying framework types would freeze a Svelte version into consumer output) and
|
|
866
|
+
* `@extendProps`/`@extends` targets (deferred; unrelated mechanism). `"all"` needs `typescript`
|
|
867
|
+
* 7+ and a `tsconfig.json`, same hard requirement as `resolveTypes`. `false` (default)
|
|
868
|
+
* preserves every import as-is.
|
|
869
|
+
* @default false
|
|
870
|
+
*/
|
|
871
|
+
inline?: false | "local" | "all";
|
|
872
|
+
/** @internal Set by `writeTsDefinitions` from `GenerateBundleResult.inlinedTypesByFilePath` when `inline` resolved something for this component. */
|
|
873
|
+
inlined?: InlinedTypes;
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
interface PluginSveldOptions extends Pick<GenerateBundleOptions, "resolveTypes" | "cache" | "checkExamples" | "diagnostics"> {
|
|
877
|
+
/**
|
|
878
|
+
* Specify the entry point to uncompiled Svelte source.
|
|
879
|
+
* If not provided, sveld will use the "svelte" field from package.json.
|
|
880
|
+
*/
|
|
881
|
+
entry?: string;
|
|
882
|
+
/**
|
|
883
|
+
* Load `sveld.config.{js,mjs,ts}` and merge it with these options; these
|
|
884
|
+
* options win when a key is set in both. `true` resolves the config from
|
|
885
|
+
* the Vite project root (or `process.cwd()` if the plugin isn't running
|
|
886
|
+
* under Vite); a string is an explicit path to the config file itself.
|
|
887
|
+
* @default false
|
|
888
|
+
*/
|
|
889
|
+
config?: boolean | string;
|
|
890
|
+
glob?: boolean;
|
|
891
|
+
/** Suppress writer progress logs (`created "..."` / `unchanged "..."`). */
|
|
892
|
+
quiet?: boolean;
|
|
893
|
+
/** Record consts, functions, and types from the entry barrel. Off by default. */
|
|
894
|
+
documentExports?: boolean;
|
|
895
|
+
types?: boolean;
|
|
896
|
+
typesOptions?: Partial<Omit<WriteTsDefinitionsOptions, "inputDir">>;
|
|
897
|
+
json?: boolean;
|
|
898
|
+
jsonOptions?: Partial<Omit<WriteJsonOptions, "inputDir">>;
|
|
899
|
+
markdown?: boolean;
|
|
900
|
+
markdownOptions?: Partial<WriteMarkdownOptions>;
|
|
901
|
+
/** Generate a Custom Elements Manifest (`custom-elements.json`, schemaVersion "1.0.0"). */
|
|
902
|
+
customElements?: boolean;
|
|
903
|
+
customElementsOptions?: Partial<Omit<WriteCustomElementsOptions, "inputDir">>;
|
|
904
|
+
/** Generate a first-party `llms.txt` / `llms-full.txt` pair (per https://llmstxt.org). */
|
|
905
|
+
llms?: boolean;
|
|
906
|
+
llmsOptions?: Partial<WriteLlmsOptions>;
|
|
907
|
+
/**
|
|
908
|
+
* Run additional, userland-registered writers (via `registerWriter` from
|
|
909
|
+
* "sveld") beyond the built-in `json`/`markdown`/`types` outputs. Keyed by
|
|
910
|
+
* the writer's registered `name`, valued by that writer's options.
|
|
911
|
+
*/
|
|
912
|
+
additionalWriters?: Record<string, unknown>;
|
|
913
|
+
/**
|
|
914
|
+
* Abort the entire run when a single component fails to parse.
|
|
915
|
+
* When `false` (the default), parse failures are collected as diagnostics
|
|
916
|
+
* and the remaining components still emit their output.
|
|
917
|
+
*/
|
|
918
|
+
failFast?: boolean;
|
|
919
|
+
/**
|
|
920
|
+
* Regenerate output incrementally when relevant source changes during
|
|
921
|
+
* `vite dev` / `vite build --watch`: a component, the entry barrel itself
|
|
922
|
+
* (adding/removing an export), or a non-`.svelte` file a component depends
|
|
923
|
+
* on via `@extendProps` / `@extends` or a typedef `import("./x")`
|
|
924
|
+
* reference. Only the affected components are re-parsed.
|
|
925
|
+
* @default false
|
|
926
|
+
*/
|
|
927
|
+
watch?: boolean;
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
interface HotUpdateContext {
|
|
931
|
+
file: string;
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
interface RollupPluginContext {
|
|
935
|
+
error(message: string): never;
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
interface ResolvedViteConfig {
|
|
939
|
+
root: string;
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
interface SveldPlugin {
|
|
943
|
+
name: string;
|
|
944
|
+
apply?: "build" | "serve";
|
|
945
|
+
enforce?: "pre" | "post";
|
|
946
|
+
/** Vite-only hook: captures the project root before `buildStart` runs. */
|
|
947
|
+
configResolved?(config: ResolvedViteConfig): void;
|
|
948
|
+
buildStart(): void | Promise<void>;
|
|
949
|
+
generateBundle(this: RollupPluginContext): Promise<void>;
|
|
950
|
+
writeBundle(this: RollupPluginContext): Promise<void>;
|
|
951
|
+
/** Vite dev-server HMR hook (serve mode). */
|
|
952
|
+
handleHotUpdate?(ctx: HotUpdateContext): void;
|
|
953
|
+
/** Rollup/Vite watch hook (build `--watch`). */
|
|
954
|
+
watchChange?(id: string): void;
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
export default function pluginSveld(opts?: PluginSveldOptions): SveldPlugin;
|
|
958
|
+
|
|
959
|
+
interface WriteCustomElementsOptions {
|
|
960
|
+
/** @internal Resolved from `entry` and always injected by the caller (`plugin.ts`); not user-configurable via `customElementsOptions`. */
|
|
961
|
+
inputDir: string;
|
|
962
|
+
outFile: string;
|
|
963
|
+
/** @internal Report the resolved path instead of writing. Always set by the caller from `sveld --dry-run`. */
|
|
964
|
+
dryRun?: boolean;
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
interface WriteJsonOptions {
|
|
968
|
+
/** @internal Unused by this writer; kept for backward compatibility. Always set by the caller. */
|
|
969
|
+
input: string;
|
|
970
|
+
/** @internal Resolved from `entry` and always injected by the caller (`plugin.ts`); not user-configurable via `jsonOptions`. */
|
|
971
|
+
inputDir: string;
|
|
972
|
+
outFile: string;
|
|
973
|
+
outDir?: string;
|
|
974
|
+
/**
|
|
975
|
+
* @internal Entry-barrel exports when `documentExports` is on. Always
|
|
976
|
+
* computed from the parsed bundle and injected by the caller; setting it
|
|
977
|
+
* via `jsonOptions` has no effect.
|
|
978
|
+
*/
|
|
979
|
+
entryExports?: EntryExports;
|
|
980
|
+
/**
|
|
981
|
+
* Include `source`/`componentCommentSource` position ranges in the
|
|
982
|
+
* output. These are the bulk of a large component library's
|
|
983
|
+
* `COMPONENT_API.json` (roughly a quarter of the file for a 150+
|
|
984
|
+
* component library); set to `false` to omit them and shrink the file
|
|
985
|
+
* when consumers don't need exact source positions.
|
|
986
|
+
* @default true
|
|
987
|
+
*/
|
|
988
|
+
source?: boolean;
|
|
989
|
+
/** @internal Report resolved paths instead of writing. Always set by the caller from `sveld --dry-run`. */
|
|
990
|
+
dryRun?: boolean;
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
interface EntryExport {
|
|
994
|
+
name: string;
|
|
995
|
+
kind: "const" | "let" | "var" | "function" | "class" | "type" | "interface" | "enum";
|
|
996
|
+
/**
|
|
997
|
+
* Type text from the source, when present. A namespace export
|
|
998
|
+
* (`export * as ns from "./x"`) gets `typeof import("./x.ts")`, the
|
|
999
|
+
* wrapped module relative to the entry file.
|
|
1000
|
+
*/
|
|
1001
|
+
type?: string;
|
|
1002
|
+
/** Initializer text for simple constants. */
|
|
1003
|
+
value?: string;
|
|
1004
|
+
description?: string;
|
|
1005
|
+
/** From `@deprecated` JSDoc. */
|
|
1006
|
+
deprecated?: DeprecatedValue;
|
|
1007
|
+
/** `@since` / `@example` / `@see` tags in source order. */
|
|
1008
|
+
tags?: JsDocPassthroughTag[];
|
|
1009
|
+
/** True from `@ignore`/`@internal` JSDoc; excluded from every output by `buildComponentApiDocument`. */
|
|
1010
|
+
internal?: boolean;
|
|
1011
|
+
/** Declaring module, relative to the entry file. */
|
|
1012
|
+
source?: string;
|
|
1013
|
+
isTypeOnly: boolean;
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
type EntryExports = EntryExport[];
|
|
1017
|
+
|
|
1018
|
+
interface WriteLlmsOptions {
|
|
1019
|
+
outDir?: string;
|
|
1020
|
+
/** Prefixed to each component's link path, e.g. `[Name](<linkBase>/Name)`. @default "" */
|
|
1021
|
+
linkBase?: string;
|
|
1022
|
+
/** @default the "name" field from the project's package.json */
|
|
1023
|
+
title?: string;
|
|
1024
|
+
/** @default the "description" field from the project's package.json */
|
|
1025
|
+
summary?: string;
|
|
1026
|
+
/** @internal Entry-barrel exports when `documentExports` is on. Always computed from the parsed bundle and injected by the caller. */
|
|
1027
|
+
entryExports?: EntryExports;
|
|
1028
|
+
/** @internal Report the resolved paths instead of writing. Always set by the caller from `sveld --dry-run`. */
|
|
1029
|
+
dryRun?: boolean;
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
interface WriteMarkdownOptions {
|
|
1033
|
+
write?: boolean;
|
|
1034
|
+
outFile: string;
|
|
1035
|
+
/**
|
|
1036
|
+
* Emit one `<ModuleName>.md` file per component into this directory,
|
|
1037
|
+
* plus an index `README.md` linking to each, instead of the single
|
|
1038
|
+
* combined `outFile`. See `jsonOptions.outDir` for the equivalent JSON
|
|
1039
|
+
* option.
|
|
1040
|
+
*/
|
|
1041
|
+
outDir?: string;
|
|
1042
|
+
/**
|
|
1043
|
+
* @internal Entry-barrel exports when `documentExports` is on. Always
|
|
1044
|
+
* computed from the parsed bundle and injected by the caller; setting it
|
|
1045
|
+
* via `markdownOptions` has no effect.
|
|
1046
|
+
*/
|
|
1047
|
+
entryExports?: EntryExports;
|
|
1048
|
+
onAppend?: (type: AppendType, document: WriterMarkdown, components: ComponentDocs) => void;
|
|
1049
|
+
/** @internal Report the resolved path instead of writing. Always set by the caller from `sveld --dry-run`. */
|
|
1050
|
+
dryRun?: boolean;
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
type OnAppend = (type: AppendType, document: WriterMarkdown) => void;
|
|
1054
|
+
|
|
1055
|
+
interface MarkdownOptions {
|
|
1056
|
+
onAppend?: OnAppend;
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
declare class WriterMarkdown extends Writer {
|
|
1060
|
+
onAppend?: OnAppend;
|
|
1061
|
+
private markdownBase;
|
|
1062
|
+
constructor(options: MarkdownOptions);
|
|
1063
|
+
get source(): string;
|
|
1064
|
+
get hasToC(): boolean;
|
|
1065
|
+
get toc(): TocLine[];
|
|
1066
|
+
appendLineBreaks(): this;
|
|
1067
|
+
append(type: AppendType, raw?: string): this;
|
|
1068
|
+
tableOfContents(): this;
|
|
1069
|
+
end(): string;
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
type AppendType = "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "quote" | "p" | "divider" | "raw";
|
|
1073
|
+
|
|
1074
|
+
interface TocLine {
|
|
1075
|
+
/** Leading space count; 0 for the top-level (`h2`) entries the TOC currently lists. */
|
|
1076
|
+
indent: number;
|
|
1077
|
+
raw: string;
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
interface WriterOptions {
|
|
1081
|
+
/** Report the resolved path to stdout instead of writing. Set by `sveld --dry-run`. */
|
|
1082
|
+
dryRun?: boolean;
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
declare class Writer {
|
|
1086
|
+
private readonly dryRun;
|
|
1087
|
+
/** Directories already created by this writer, so sibling files skip the `mkdir` round trip. */
|
|
1088
|
+
private readonly ensuredDirs;
|
|
1089
|
+
constructor(options?: WriterOptions);
|
|
1090
|
+
/**
|
|
1091
|
+
* Skips the write when `filePath` already contains `raw`, so repeated runs
|
|
1092
|
+
* over unchanged sources don't touch the file (or its mtime). In dry-run
|
|
1093
|
+
* mode, prints `would write "<path>"` to stdout and touches nothing.
|
|
1094
|
+
*
|
|
1095
|
+
* @returns `true` if the file was written, `false` if it was already up to date.
|
|
1096
|
+
*
|
|
1097
|
+
* @example
|
|
1098
|
+
* ```ts
|
|
1099
|
+
* const writer = new Writer();
|
|
1100
|
+
* await writer.write("./dist/index.d.ts", "export type Props = {};");
|
|
1101
|
+
* ```
|
|
1102
|
+
*/
|
|
1103
|
+
write(filePath: string, raw: string): Promise<boolean>;
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1106
|
+
type TransformContext = {
|
|
1107
|
+
kind: "component";
|
|
1108
|
+
component: ComponentDocApi;
|
|
1109
|
+
filePath: string;
|
|
1110
|
+
} | {
|
|
1111
|
+
kind: "index";
|
|
1112
|
+
filePath: string;
|
|
1113
|
+
};
|
|
1114
|
+
|
|
1115
|
+
interface WriteTsDefinitionsOptions extends WriteTsDefinitionOptions {
|
|
1116
|
+
outDir: string;
|
|
1117
|
+
/** @internal Resolved from `entry` and always injected by the caller (`plugin.ts`); not user-configurable via `typesOptions`. */
|
|
1118
|
+
inputDir: string;
|
|
1119
|
+
preamble: string;
|
|
1120
|
+
/** @internal Always computed from the parsed bundle and injected by the caller; not user-configurable via `typesOptions`. */
|
|
1121
|
+
exports: ParsedExports;
|
|
1122
|
+
/** @internal Report resolved paths instead of writing. Always set by the caller from `sveld --dry-run`. */
|
|
1123
|
+
dryRun?: boolean;
|
|
1124
|
+
/**
|
|
1125
|
+
* @internal Reuses generated `.d.ts` text across runs for components whose
|
|
1126
|
+
* source (and every emit option from `serializeEmitOptions`) hasn't
|
|
1127
|
+
* changed. Requires `resolvedPathByFilePath` to key lookups; both come
|
|
1128
|
+
* from `GenerateBundleResult`.
|
|
1129
|
+
*/
|
|
1130
|
+
cache?: ParseCache;
|
|
1131
|
+
/** @internal See `cache`. Lookups use `component.filePath`. */
|
|
1132
|
+
resolvedPathByFilePath?: Map<string, string>;
|
|
1133
|
+
/**
|
|
1134
|
+
* @internal See `cache`. For components whose output was resolved from
|
|
1135
|
+
* other files, so their text is keyed on their content too.
|
|
1136
|
+
*/
|
|
1137
|
+
crossFileResolvedPathByFilePath?: Map<string, string>;
|
|
1138
|
+
/**
|
|
1139
|
+
* @internal From `GenerateBundleResult.inlinedTypesByFilePath`, populated when
|
|
1140
|
+
* `typesOptions.inline` is `"local"`/`"all"`. Lookups use `component.filePath`.
|
|
1141
|
+
*/
|
|
1142
|
+
inlinedTypesByFilePath?: Map<string, InlinedTypes>;
|
|
1143
|
+
/**
|
|
1144
|
+
* Post-processes each generated file's text before it is written. Runs
|
|
1145
|
+
* after the generated-text cache, so it applies on every run. Config file
|
|
1146
|
+
* or `sveld()` only.
|
|
1147
|
+
*/
|
|
1148
|
+
transform?: (text: string, context: TransformContext) => string | Promise<string>;
|
|
1149
|
+
/**
|
|
1150
|
+
* Also re-export generated types from `index.d.ts`. `true` re-exports each
|
|
1151
|
+
* component's `Props` type (and `Exports` under `format: "component"`); an
|
|
1152
|
+
* object can additionally include typedefs and contexts. Skips any type
|
|
1153
|
+
* that `exportTypes` keeps local.
|
|
1154
|
+
*/
|
|
1155
|
+
indexTypes?: boolean | {
|
|
1156
|
+
props?: boolean;
|
|
1157
|
+
exports?: boolean;
|
|
1158
|
+
typedefs?: boolean;
|
|
1159
|
+
contexts?: boolean;
|
|
1160
|
+
};
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
declare class ParseCache {
|
|
1164
|
+
private readonly cacheFilePath;
|
|
1165
|
+
private readonly file;
|
|
1166
|
+
private readonly next;
|
|
1167
|
+
/** Paths forced to miss this run (e.g. dependents of a changed `@extends` target). */
|
|
1168
|
+
private readonly blocked;
|
|
1169
|
+
/**
|
|
1170
|
+
* Whether `next` differs from what's on disk: an entry was added or its
|
|
1171
|
+
* generated text changed. Dropped entries show up as `next` holding fewer
|
|
1172
|
+
* entries than `savedEntryCount`, since without a `set()` every entry in
|
|
1173
|
+
* `next` came from the file.
|
|
1174
|
+
*/
|
|
1175
|
+
private dirty;
|
|
1176
|
+
private savedEntryCount;
|
|
1177
|
+
constructor(cacheFilePath: string);
|
|
1178
|
+
/** True when `get()` would return a hit for `resolvedPath` and `hash`. */
|
|
1179
|
+
has(resolvedPath: string, hash: string): boolean;
|
|
1180
|
+
/** Returns the cached parse for `resolvedPath` when its content hash still matches. */
|
|
1181
|
+
get(resolvedPath: string, hash: string): ParsedComponent | null;
|
|
1182
|
+
/**
|
|
1183
|
+
* Records a freshly parsed component so it can be reused on a future run.
|
|
1184
|
+
* Stores a copy, for the same reason `get()` returns one.
|
|
1185
|
+
*/
|
|
1186
|
+
set(resolvedPath: string, hash: string, parsed: ParsedComponent): void;
|
|
1187
|
+
/** Skip cache for `resolvedPath` this run (e.g. an @extends dependent). */
|
|
1188
|
+
invalidate(resolvedPath: string): void;
|
|
1189
|
+
/**
|
|
1190
|
+
* Returns the cached generated `.d.ts` text for `resolvedPath`, if this
|
|
1191
|
+
* run's parse entry for it (a fresh parse or a hash-verified hit - see
|
|
1192
|
+
* `get()`/`set()`) already carries text generated for `key`, the
|
|
1193
|
+
* serialized emit options (see `serializeEmitOptions`).
|
|
1194
|
+
*/
|
|
1195
|
+
getGeneratedText(resolvedPath: string, key: string): string | undefined;
|
|
1196
|
+
/**
|
|
1197
|
+
* Records generated `.d.ts` text against this run's parse entry for
|
|
1198
|
+
* `resolvedPath`. No-op if that entry hasn't been recorded via `get()`/`set()`
|
|
1199
|
+
* (shouldn't happen: the write phase only runs after every component has
|
|
1200
|
+
* been parsed).
|
|
1201
|
+
*/
|
|
1202
|
+
setGeneratedText(resolvedPath: string, key: string, text: string): void;
|
|
1203
|
+
/**
|
|
1204
|
+
* Persists this run's cache entries back to disk. Writes to a pid-suffixed
|
|
1205
|
+
* temp file and renames it over the target so concurrent sveld processes
|
|
1206
|
+
* sharing a cache dir can't interleave writes into a truncated file; a
|
|
1207
|
+
* failed rename (e.g. read-only cache dir) falls back to a direct write so
|
|
1208
|
+
* generation never fails just because the cache couldn't be saved.
|
|
1209
|
+
* Skipped when nothing changed since the file was read or last saved.
|
|
1210
|
+
*/
|
|
1211
|
+
save(): void;
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1214
|
+
type ParsedExports = Record<string, {
|
|
1215
|
+
source: RelativeSourcePath;
|
|
1216
|
+
default: boolean;
|
|
1217
|
+
mixed?: boolean;
|
|
1218
|
+
}>;
|
|
1219
|
+
|
|
1220
|
+
export interface SveldRuntimeOptions extends PluginSveldOptions {
|
|
1221
|
+
/** Print unresolved-type diagnostics to stderr. */
|
|
1222
|
+
reportDiagnostics?: boolean;
|
|
1223
|
+
/**
|
|
1224
|
+
* Exit code 4 when diagnostics exist. Implies `reportDiagnostics`. Pass
|
|
1225
|
+
* `"errors"` to fail only on `severity: "error"` diagnostics
|
|
1226
|
+
* (`example-compile-error`, `syntax-skipped`), letting warnings
|
|
1227
|
+
* (`prop-unknown-type`, `context-any-type`, `event-no-source`) through.
|
|
1228
|
+
*
|
|
1229
|
+
* `"ci"` and `"local"` are strictness profiles, expanded by
|
|
1230
|
+
* {@link expandStrictProfile} into a set of other options before this
|
|
1231
|
+
* object's own explicit keys are applied (so they can still opt back out
|
|
1232
|
+
* of one, e.g. `{ strict: "ci", checkExamples: false }`):
|
|
1233
|
+
* - `"ci"`: `{ strict: true, reportDiagnostics: true, check: true, checkExamples: true }`.
|
|
1234
|
+
* - `"local"`: `{ reportDiagnostics: true }` (does not itself enable `strict`).
|
|
1235
|
+
*/
|
|
1236
|
+
strict?: boolean | "errors" | "ci" | "local";
|
|
1237
|
+
/**
|
|
1238
|
+
* Diff the parsed component API against a committed snapshot (default:
|
|
1239
|
+
* the `json` writer's `outFile`, or `COMPONENT_API.json`) and assign a
|
|
1240
|
+
* semver bump to each change. Exits `3` on a breaking change. Pass a
|
|
1241
|
+
* string for a custom snapshot path.
|
|
1242
|
+
*/
|
|
1243
|
+
check?: boolean | string;
|
|
1244
|
+
/**
|
|
1245
|
+
* Minimum bump `--check` fails the run (exit `3`) on: `"major"` (default,
|
|
1246
|
+
* preserves prior behavior), `"minor"`, or `"patch"`.
|
|
1247
|
+
*/
|
|
1248
|
+
checkLevel?: "major" | "minor" | "patch";
|
|
1249
|
+
/** Suppress writer progress logs (`created "..."` / `unchanged "..."`). */
|
|
1250
|
+
quiet?: boolean;
|
|
1251
|
+
/**
|
|
1252
|
+
* Print the single selected `json` / `markdown` / `customElements` document
|
|
1253
|
+
* to stdout instead of writing it to disk. Requires exactly one of those
|
|
1254
|
+
* three outputs; CLI-only (the Vite plugin ignores it). `"ndjson"` is only
|
|
1255
|
+
* valid with `json` and prints one minified JSON object per component per
|
|
1256
|
+
* line instead of the single combined document.
|
|
1257
|
+
*/
|
|
1258
|
+
stdout?: boolean | "json" | "ndjson";
|
|
1259
|
+
/**
|
|
1260
|
+
* Output format for the `--check` report and the `--report-diagnostics` /
|
|
1261
|
+
* `--strict` diagnostics summary: `"text"` (default), `"json"`, or
|
|
1262
|
+
* `"github"` (GitHub Actions `::error`/`::warning` workflow commands, plus
|
|
1263
|
+
* a `GITHUB_STEP_SUMMARY` Markdown table when that env var is set).
|
|
1264
|
+
* Channels are unchanged, the check report on stdout and diagnostics on
|
|
1265
|
+
* stderr. CLI-only; `sveld()` ignores `format` for its own console output.
|
|
1266
|
+
*/
|
|
1267
|
+
format?: "text" | "json" | "github";
|
|
1268
|
+
/**
|
|
1269
|
+
* Resolve the entry, load config, and parse components as usual, but print
|
|
1270
|
+
* `would write "<path>"` for each output file to stdout instead of writing
|
|
1271
|
+
* it (including the parse cache). CLI-only; the Vite plugin ignores it.
|
|
1272
|
+
*/
|
|
1273
|
+
dryRun?: boolean;
|
|
1274
|
+
}
|
|
1275
|
+
|
|
1276
|
+
export type SveldConfig = SveldRuntimeOptions;
|
|
1277
|
+
|
|
1278
|
+
export declare function defineConfig(config: SveldConfig): SveldConfig;
|
|
1279
|
+
|
|
1280
|
+
export interface ComponentApiDocument {
|
|
1281
|
+
schemaVersion: 1;
|
|
1282
|
+
generator: {
|
|
1283
|
+
name: string;
|
|
1284
|
+
version: string;
|
|
1285
|
+
svelteVersion: string;
|
|
1286
|
+
};
|
|
1287
|
+
total: number;
|
|
1288
|
+
components: ComponentDocApi[];
|
|
1289
|
+
/** Only when `documentExports` is on. */
|
|
1290
|
+
totalExports?: number;
|
|
1291
|
+
exports?: EntryExports;
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1294
|
+
interface BuildComponentApiDocumentOptions {
|
|
1295
|
+
/** Entry-barrel exports when `documentExports` is on. */
|
|
1296
|
+
entryExports?: EntryExports;
|
|
1297
|
+
}
|
|
1298
|
+
|
|
1299
|
+
export declare function buildComponentApiDocument(components: ComponentDocs, options?: BuildComponentApiDocumentOptions): ComponentApiDocument;
|
|
1300
|
+
|
|
1301
|
+
export declare function cli(process: NodeJS.Process): Promise<void>;
|
|
1302
|
+
|
|
1303
|
+
type SveldOptions = SveldRuntimeOptions;
|
|
1304
|
+
|
|
1305
|
+
export interface SveldResult {
|
|
1306
|
+
/** Diagnostics from this run. */
|
|
1307
|
+
diagnostics: SveldDiagnostic[];
|
|
1308
|
+
/** Populated when `check` is enabled: the API diff against the committed snapshot. */
|
|
1309
|
+
check?: CheckResult;
|
|
1310
|
+
/** Parse errors for components that failed to parse (empty unless `failFast` is disabled and a component errors). */
|
|
1311
|
+
errors: ComponentParseError[];
|
|
1312
|
+
/**
|
|
1313
|
+
* Suggested process exit code for this run, using the same mapping as the
|
|
1314
|
+
* CLI (a breaking `check` result wins over `strict` diagnostics): `0` on
|
|
1315
|
+
* success, `3` on a breaking API change, `4` when `strict` diagnostics
|
|
1316
|
+
* exist. `sveld()` never mutates `process.exitCode` itself; assign this
|
|
1317
|
+
* value yourself if you want the process to exit non-zero.
|
|
1318
|
+
*/
|
|
1319
|
+
exitCode: 0 | 3 | 4;
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
export declare function sveld(opts?: SveldOptions): Promise<SveldResult>;
|
|
1323
|
+
|
|
1324
|
+
type WriterComponentSet = "exported" | "all";
|
|
1325
|
+
|
|
1326
|
+
export interface OutputWriter<TOptions = unknown> {
|
|
1327
|
+
name: string;
|
|
1328
|
+
/** Which component set this writer expects — see {@link WriterComponentSet}. @default "exported" */
|
|
1329
|
+
componentSet?: WriterComponentSet;
|
|
1330
|
+
/**
|
|
1331
|
+
* `options` always carries `dryRun: true` under `sveld --dry-run` (or
|
|
1332
|
+
* `{ dryRun: true }` from the programmatic API), alongside whatever
|
|
1333
|
+
* `TOptions` fields the writer defines. `write` must check it and skip
|
|
1334
|
+
* touching disk; sveld does not do this for you. A thrown error (sync or
|
|
1335
|
+
* async) is re-thrown by the caller as `sveld: writer "<name>" failed: ...`
|
|
1336
|
+
* with the original error as `cause`.
|
|
1337
|
+
*/
|
|
1338
|
+
write(components: ComponentDocs, options: TOptions): Promise<unknown> | unknown;
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1341
|
+
export interface RegisterWriterOptions {
|
|
1342
|
+
/** Overwrite an existing writer registered under the same `name` instead of throwing. @default false */
|
|
1343
|
+
replace?: boolean;
|
|
1344
|
+
}
|
|
1345
|
+
|
|
1346
|
+
export declare function registerWriter<TOptions = unknown>(writer: OutputWriter<TOptions>, options?: RegisterWriterOptions): void;
|
|
1347
|
+
|
|
1348
|
+
export declare function getWriter(name: string): OutputWriter<unknown> | undefined;
|
|
1349
|
+
|
|
1350
|
+
export declare function listWriters(): OutputWriter<unknown>[];
|