sveld 0.38.1 → 0.38.3
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/browser.d.ts +9 -48
- package/browser.js +174 -194
- package/chunk-1azsj0zd.js +13 -0
- package/chunk-asxze8b8.js +1 -0
- package/chunk-nv6dzbmp.js +29 -0
- package/chunk-q19n9qm3.js +5 -0
- package/chunk-ssa3mr5n.js +234 -0
- package/cli-entry.js +2 -2
- package/index.d.ts +12 -53
- package/index.js +1 -1
- package/package.json +1 -1
- package/chunk-wpqsw5ca.js +0 -13
- package/chunk-x0hkebcs.js +0 -29
- package/chunk-y5gqpp8d.js +0 -5
- package/chunk-ymq8jc0f.js +0 -254
- package/chunk-ynrmtc58.js +0 -1
package/cli-entry.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{se,oe,ae,N,n,$t,Te,Ee,J,Se,ke,Z,q,I,F,K,V,U,D,R,Be,L,qt,je}from"./chunk-ssa3mr5n.js";import{existsSync as v}from"node:fs";import{join as x,resolve as E}from"node:path";var g="src/index.js",h={SUCCESS:0,USAGE_ERROR:1,GENERATION_FAILURE:2,BREAKING_CHANGE:3,DIAGNOSTICS:4},w=`Usage: sveld [options]
|
|
2
2
|
|
|
3
3
|
Generate TypeScript definitions and component documentation for a Svelte
|
|
4
4
|
library. With no flags, only TypeScript definitions are generated for the
|
|
@@ -35,4 +35,4 @@ Exit codes:
|
|
|
35
35
|
2 generation failure
|
|
36
36
|
3 breaking API change detected by --check
|
|
37
37
|
4 diagnostics present under --strict
|
|
38
|
-
`,
|
|
38
|
+
`,C=["help","version","glob","types","json","markdown","quiet","stdout","strict","report-diagnostics","check-examples","fail-fast","entry","config","cache","check","check-level","types-format","types-index-types","format"],S=new Map([["-h","--help"],["-v","--version"],["-q","--quiet"]]),b=/[A-Z]/g,O=new Set(["glob","types","json","markdown","quiet","stdout","strict","report-diagnostics","check-examples","fail-fast","types-index-types"]),j=new Set(["entry","config","cache","check","types-format"]),A=new Set(["entry","config","types-format"]);function T(o){let t=o.replace(b,(r)=>`-${r.toLowerCase()}`);return N(t,C)}function P(o,t){let r=o.indexOf("="),s=r===-1?o.slice(2):o.slice(2,r),i=r===-1?!0:o.slice(r+1),e=!1;if(r===-1&&j.has(s)){if(t!==void 0&&!t.startsWith("--")&&!S.has(t))i=t,e=!0;else if(A.has(s))return{result:{kind:"usage-error",message:`sveld: --${s} requires a value (pass --${s}=<value> or --${s} <value>).`},consumedNext:!1,flag:s}}return{result:_(s,i,o),consumedNext:e,flag:s}}function _(o,t,r){let s=(u)=>({kind:"option",option:u}),i=t===!0||t==="true",e=typeof t==="string"?t:void 0;switch(o){case"help":return{kind:"help"};case"version":return{kind:"version"};case"glob":case"types":case"json":case"markdown":case"quiet":return s({[o]:i});case"stdout":if(i)return s({stdout:!0});if(t==="false")return s({stdout:!1});return{kind:"usage-error",message:`sveld: --stdout does not take a value; got "${t}".`};case"strict":if(i)return s({strict:!0});if(t==="false")return s({strict:!1});return s({strict:t});case"report-diagnostics":return s({reportDiagnostics:i});case"check-examples":if(i)return s({checkExamples:!0});if(t==="false")return s({checkExamples:!1});return s({checkExamples:t});case"fail-fast":return s({failFast:i});case"entry":return s(e===void 0?{}:{entry:e});case"config":return s(e===void 0?{}:{config:e});case"cache":if(t==="false")return s({cache:!1});return s({cache:e??!0});case"check":if(t==="false")return s({check:!1});return s({check:e??!0});case"types-format":return s(e===void 0?{}:{typesOptions:{format:e}});case"types-index-types":return s({typesOptions:{indexTypes:i}});case"format":return s(e===void 0?{}:{format:e});case"check-level":return s(e===void 0?{}:{checkLevel:e});default:return{kind:"unknown",arg:r,suggestion:T(o)}}}function G(o){let t={},r=!1;for(let s=0;s<o.length;s++){let i=S.get(o[s])??o[s];if(!i.startsWith("--"))return{kind:"unknown",arg:i,positionalHint:r?!0:void 0};let{result:e,consumedNext:u,flag:d}=P(i,o[s+1]);if(e.kind!=="option")return e;if(t=I(t,e.option),r=O.has(d),u)s++}return{kind:"options",options:t}}async function B(o){if(typeof o!=="string")return q();let t=E(o);if(!v(t))throw Error(`sveld: config file "${o}" does not exist.`);return Z(t)}function p(o,t){return o!==void 0&&!t.includes(o)}async function H(o){let t=(a)=>{console.error(a),o.exitCode=h.USAGE_ERROR},r=G(o.argv.slice(2));if(r.kind==="help"){console.log(w);return}if(r.kind==="version"){console.log($t.version);return}if(r.kind==="usage-error")return t(r.message);if(r.kind==="unknown"){let a=`sveld: unknown flag "${r.arg}".`;if(r.suggestion)a+=` Did you mean "--${r.suggestion}"?`;if(r.positionalHint)a+=" Values are passed as --flag=value or --flag value.";return console.error(a),t("Run sveld --help for a list of available flags.")}let s=r.options,i;try{i=await B(s.config)}catch(a){return t(a instanceof Error?a.message:String(a))}let e=I(i,s);if(F(e),e.stdout){if([e.json,e.markdown].filter(Boolean).length!==1)return t("sveld: --stdout requires exactly one of --json or --markdown.");if(e.types===!0)return t("sveld: --stdout cannot be combined with --types; type definitions span multiple files.");if(e.check)return t("sveld: --stdout cannot be combined with --check; both write their document to stdout.")}if(p(e.format,["text","json"]))return t(`sveld: --format must be "text" or "json"; got "${e.format}".`);if(p(e.strict,[!0,!1,"errors"]))return t(`sveld: --strict must be "errors" when given a value; got "${e.strict}".`);if(p(e.checkLevel,["major","minor","patch"]))return t(`sveld: --check-level must be "major", "minor", or "patch"; got "${e.checkLevel}".`);if(p(e.checkExamples,[!0,!1,"syntax"]))return t(`sveld: --check-examples must be "syntax" when given a value; got "${e.checkExamples}".`);let u=e.typesOptions?.format;if(p(u,["class","component"]))return t(`sveld: --types-format must be "class" or "component"; got "${u}".`);V(e.quiet===!0);let d=Be(e.entry),f;if(d.entry!==null)f=d.entry;else if(!d.configured&&v(x(o.cwd(),g)))console.error(`sveld: no entry point configured; using "${g}". Set package.json#svelte (or pass --entry) to silence this.`),f=K(n(g));else return t(`sveld: ${d.message}`);let c,l;try{if(c=await R(f,e.glob===!0,D(e)),e.check)l=await J(c.components,Te(e),{entryExports:c.entryExports});if(e.stdout)await qt(c,e,f);else await L(c,e,f),c.cache?.save()}catch(a){if(a instanceof U)return t(`sveld: ${a.message}`);console.error(a instanceof Error?a.message:String(a)),o.exitCode=h.GENERATION_FAILURE;return}let k=e.reportDiagnostics||e.strict,m=se(c.diagnostics,k);if(k&&m.length>0)if(e.format==="json")o.stderr.write(ae(m));else console.error(oe(m));if(l)if(e.format==="json")o.stdout.write(ke(l));else console.log(Se(l));let y=je({errors:c.errors,check:l,writesSnapshot:l?Ee(e,l.snapshotFile):!1,checkLevel:e.checkLevel,diagnostics:m,strict:e.strict});if(y!==h.SUCCESS)o.exitCode=y}export{H as cli};
|
package/index.d.ts
CHANGED
|
@@ -4,11 +4,6 @@ interface ComponentParserDiagnostics {
|
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
export class ComponentParser {
|
|
7
|
-
/**
|
|
8
|
-
* All per-parse mutable state (props, slots, events, scopes, source, etc.).
|
|
9
|
-
* See {@link ParserContext} for field-by-field documentation. Replaced
|
|
10
|
-
* wholesale by `cleanup()` between parses.
|
|
11
|
-
*/
|
|
12
7
|
private ctx;
|
|
13
8
|
/**
|
|
14
9
|
* Resets parser state for reuse between parses.
|
|
@@ -49,9 +44,9 @@ interface JsDocPassthroughTag {
|
|
|
49
44
|
type DeprecatedValue = string | true;
|
|
50
45
|
|
|
51
46
|
interface SourcePosition {
|
|
52
|
-
/** 1-based
|
|
47
|
+
/** 1-based. */
|
|
53
48
|
line: number;
|
|
54
|
-
/** 0-based
|
|
49
|
+
/** 0-based. */
|
|
55
50
|
column: number;
|
|
56
51
|
}
|
|
57
52
|
|
|
@@ -114,13 +109,9 @@ interface PendingDispatchEscapeCandidate {
|
|
|
114
109
|
}
|
|
115
110
|
|
|
116
111
|
interface PendingCrossFileCandidates {
|
|
117
|
-
/** Unresolved CallExpression defaults. */
|
|
118
112
|
pendingCallDefaultCandidates?: PendingCallDefaultCandidate[];
|
|
119
|
-
/** Imported-identifier defaults. */
|
|
120
113
|
pendingConstDefaultCandidates?: PendingConstDefaultCandidate[];
|
|
121
|
-
/** Unresolved `setContext` import keys. */
|
|
122
114
|
pendingContextKeyCandidates?: PendingContextKeyCandidate[];
|
|
123
|
-
/** Dispatchers passed to imported functions. */
|
|
124
115
|
pendingDispatchEscapeCandidates?: PendingDispatchEscapeCandidate[];
|
|
125
116
|
/**
|
|
126
117
|
* `event-no-source` diagnostics held back while the dispatcher escapes to
|
|
@@ -166,13 +157,9 @@ interface ComponentPropDefaultValue {
|
|
|
166
157
|
type ComponentPropBinding = "readonly" | "writable";
|
|
167
158
|
|
|
168
159
|
interface ComponentPropParam {
|
|
169
|
-
/** Parameter name. */
|
|
170
160
|
name: string;
|
|
171
|
-
/** Parameter type (e.g. `"string"`, `"CustomType"`). */
|
|
172
161
|
type: string;
|
|
173
|
-
/** From JSDoc `@param`. */
|
|
174
162
|
description?: string;
|
|
175
|
-
/** True when optional. */
|
|
176
163
|
optional?: boolean;
|
|
177
164
|
}
|
|
178
165
|
|
|
@@ -219,7 +206,6 @@ interface ComponentProp {
|
|
|
219
206
|
kind: "let" | "const" | "function" | "re-export" | "class";
|
|
220
207
|
/** True when declared with `const`. */
|
|
221
208
|
constant: boolean;
|
|
222
|
-
/** TypeScript type text. */
|
|
223
209
|
type?: string;
|
|
224
210
|
/** Conservative provenance for the prop type. See the precedence rule on {@link ComponentProp}. */
|
|
225
211
|
typeSource?: ComponentPropTypeSource;
|
|
@@ -256,7 +242,6 @@ interface ComponentProp {
|
|
|
256
242
|
* type/JSDoc signature in runes only (see {@link ComponentProp}).
|
|
257
243
|
*/
|
|
258
244
|
isFunction: boolean;
|
|
259
|
-
/** True for `function` declarations. */
|
|
260
245
|
isFunctionDeclaration: boolean;
|
|
261
246
|
/** True when declared with `let` and no default. */
|
|
262
247
|
isRequired: boolean;
|
|
@@ -277,14 +262,12 @@ interface ComponentProp {
|
|
|
277
262
|
internal?: boolean;
|
|
278
263
|
/** Set when `kind` is `"re-export"`. */
|
|
279
264
|
reExport?: ComponentPropReExport;
|
|
280
|
-
/** Source range when available. */
|
|
281
265
|
source?: SourceRange;
|
|
282
266
|
}
|
|
283
267
|
|
|
284
268
|
interface ComponentSlot {
|
|
285
|
-
/**
|
|
269
|
+
/** `null` for the default slot. */
|
|
286
270
|
name?: string | null;
|
|
287
|
-
/** True for the default slot. */
|
|
288
271
|
default: boolean;
|
|
289
272
|
/** Fallback content when the slot is empty. */
|
|
290
273
|
fallback?: string;
|
|
@@ -298,16 +281,12 @@ interface ComponentSlot {
|
|
|
298
281
|
tags?: JsDocPassthroughTag[];
|
|
299
282
|
/** True from `@ignore`/`@internal` JSDoc; excluded from every output by `buildComponentApiDocument`. */
|
|
300
283
|
internal?: boolean;
|
|
301
|
-
/** Source range when available. */
|
|
302
284
|
source?: SourceRange;
|
|
303
285
|
}
|
|
304
286
|
|
|
305
287
|
interface DispatchedEvent {
|
|
306
|
-
/** Discriminator: `"dispatched"`. */
|
|
307
288
|
type: "dispatched";
|
|
308
|
-
/** Event name. */
|
|
309
289
|
name: string;
|
|
310
|
-
/** Detail type text. */
|
|
311
290
|
detail?: string;
|
|
312
291
|
/** From JSDoc `@event`. */
|
|
313
292
|
description?: string;
|
|
@@ -317,14 +296,11 @@ interface DispatchedEvent {
|
|
|
317
296
|
tags?: JsDocPassthroughTag[];
|
|
318
297
|
/** True from `@ignore`/`@internal` JSDoc; excluded from every output by `buildComponentApiDocument`. */
|
|
319
298
|
internal?: boolean;
|
|
320
|
-
/** Source range when available. */
|
|
321
299
|
source?: SourceRange;
|
|
322
300
|
}
|
|
323
301
|
|
|
324
302
|
interface SerializedForwardedEvent {
|
|
325
|
-
/** Discriminator: `"forwarded"`. */
|
|
326
303
|
type: "forwarded";
|
|
327
|
-
/** Event name. */
|
|
328
304
|
name: string;
|
|
329
305
|
/** Element name as a string for JSON output. */
|
|
330
306
|
element: string;
|
|
@@ -338,7 +314,6 @@ interface SerializedForwardedEvent {
|
|
|
338
314
|
tags?: JsDocPassthroughTag[];
|
|
339
315
|
/** True from `@ignore`/`@internal` JSDoc; excluded from every output by `buildComponentApiDocument`. */
|
|
340
316
|
internal?: boolean;
|
|
341
|
-
/** Source range when available. */
|
|
342
317
|
source?: SourceRange;
|
|
343
318
|
}
|
|
344
319
|
|
|
@@ -347,9 +322,7 @@ export type SerializedComponentEvent = SerializedForwardedEvent | DispatchedEven
|
|
|
347
322
|
interface TypeDef {
|
|
348
323
|
/** Type text (e.g. `"{ x: number; y: number }"`). */
|
|
349
324
|
type: string;
|
|
350
|
-
/** Type name. */
|
|
351
325
|
name: string;
|
|
352
|
-
/** From JSDoc. */
|
|
353
326
|
description?: string;
|
|
354
327
|
/** Full `type` alias declaration text. */
|
|
355
328
|
ts: string;
|
|
@@ -364,9 +337,7 @@ interface TypeDef {
|
|
|
364
337
|
type ComponentGenerics = [name: string, type: string] | null;
|
|
365
338
|
|
|
366
339
|
interface ComponentInlineElement {
|
|
367
|
-
/** Discriminator: `"InlineComponent"`. */
|
|
368
340
|
type: "InlineComponent";
|
|
369
|
-
/** Component name. */
|
|
370
341
|
name: string;
|
|
371
342
|
}
|
|
372
343
|
|
|
@@ -431,20 +402,15 @@ interface ComponentCssProperty {
|
|
|
431
402
|
}
|
|
432
403
|
|
|
433
404
|
interface ComponentContextProp {
|
|
434
|
-
/** Property name. */
|
|
435
405
|
name: string;
|
|
436
|
-
/** Property type text. */
|
|
437
406
|
type: string;
|
|
438
|
-
/** From JSDoc. */
|
|
439
407
|
description?: string;
|
|
440
|
-
/** True when optional. */
|
|
441
408
|
optional: boolean;
|
|
442
409
|
/** True from `@ignore`/`@internal` JSDoc; excluded from every output by `buildComponentApiDocument`. */
|
|
443
410
|
internal?: boolean;
|
|
444
411
|
}
|
|
445
412
|
|
|
446
413
|
interface ComponentContext {
|
|
447
|
-
/** Context key from `setContext`. */
|
|
448
414
|
key: string;
|
|
449
415
|
/** Generated type name (e.g. `"ModalContext"`). */
|
|
450
416
|
typeName: string;
|
|
@@ -454,9 +420,8 @@ interface ComponentContext {
|
|
|
454
420
|
* when untyped). `properties` is empty then.
|
|
455
421
|
*/
|
|
456
422
|
type?: string;
|
|
457
|
-
/** From JSDoc. */
|
|
458
423
|
description?: string;
|
|
459
|
-
/**
|
|
424
|
+
/** Empty when {@link ComponentContext.type} is set. */
|
|
460
425
|
properties: ComponentContextProp[];
|
|
461
426
|
/** True when a `{...spread}` in the context's object literal couldn't be resolved; the generated type intersects with `Record<string, any>`. */
|
|
462
427
|
hasUnresolvedSpread?: boolean;
|
|
@@ -467,7 +432,6 @@ interface ComponentContext {
|
|
|
467
432
|
}
|
|
468
433
|
|
|
469
434
|
interface ParsedComponent {
|
|
470
|
-
/** Source range of the parsed file. */
|
|
471
435
|
source?: SourceRange;
|
|
472
436
|
syntaxMode: SyntaxMode;
|
|
473
437
|
scriptLanguage?: ScriptLanguage;
|
|
@@ -493,20 +457,16 @@ interface ParsedComponent {
|
|
|
493
457
|
cssParts?: ComponentCssPart[];
|
|
494
458
|
/** From component-level `@cssprop`/`@cssproperty` JSDoc tags. */
|
|
495
459
|
cssProperties?: ComponentCssProperty[];
|
|
496
|
-
/**
|
|
497
|
-
* Type guesses from this parse (unknown props, `any` contexts, orphan `@event` tags).
|
|
498
|
-
*/
|
|
460
|
+
/** Type guesses from this parse (unknown props, `any` contexts, orphan `@event` tags). */
|
|
499
461
|
diagnostics?: SveldDiagnostic[];
|
|
500
462
|
/** Writer-only TypeScript metadata. Not serialized to JSON. */
|
|
501
463
|
[PARSED_COMPONENT_TYPE_SCRIPT_METADATA]?: ParsedComponentTypeScriptMetadata;
|
|
502
464
|
}
|
|
503
465
|
|
|
504
|
-
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";
|
|
466
|
+
export type SveldDiagnosticKind = "prop-unknown-type" | "context-any-type" | "slot-missing-type" | "slot-not-rendered" | "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";
|
|
505
467
|
|
|
506
468
|
export type SveldDiagnosticSeverity = "error" | "warning";
|
|
507
469
|
|
|
508
|
-
export declare const DIAGNOSTIC_CODES: Record<SveldDiagnosticKind, string>;
|
|
509
|
-
|
|
510
470
|
export interface SveldDiagnostic {
|
|
511
471
|
/**
|
|
512
472
|
* File this came from, e.g. `"./Button.svelte"`, or the entry barrel
|
|
@@ -537,6 +497,8 @@ export interface DiagnosticIgnoreMatcher {
|
|
|
537
497
|
name?: string;
|
|
538
498
|
}
|
|
539
499
|
|
|
500
|
+
export declare const DIAGNOSTIC_CODES: Record<SveldDiagnosticKind, string>;
|
|
501
|
+
|
|
540
502
|
export declare const DIAGNOSTICS_SCHEMA_VERSION = 1;
|
|
541
503
|
|
|
542
504
|
export interface DiagnosticsJson {
|
|
@@ -920,16 +882,13 @@ interface WriteTsDefinitionOptions {
|
|
|
920
882
|
/**
|
|
921
883
|
* `"class"` (default) extends the deprecated `SvelteComponentTyped`.
|
|
922
884
|
* `"component"` emits `declare const X: Component<Props, Exports, Bindings>`
|
|
923
|
-
* instead, for Svelte 5+ consumers. Generic components
|
|
924
|
-
*
|
|
925
|
-
*
|
|
926
|
-
* parameter (see `genGenericComponentDeclaration`).
|
|
885
|
+
* instead, for Svelte 5+ consumers. Generic components and components with
|
|
886
|
+
* events get a per-component interface instead, since a `declare const`
|
|
887
|
+
* can't carry a generic type parameter and `Component` has no events slot.
|
|
927
888
|
*/
|
|
928
889
|
format?: "class" | "component";
|
|
929
890
|
}
|
|
930
891
|
|
|
931
|
-
type SveldOptions = SveldRuntimeOptions;
|
|
932
|
-
|
|
933
892
|
export interface SveldResult {
|
|
934
893
|
/** Diagnostics from this run. */
|
|
935
894
|
diagnostics: SveldDiagnostic[];
|
|
@@ -953,4 +912,4 @@ export interface SveldResult {
|
|
|
953
912
|
|
|
954
913
|
type ExitCode = 0 | 1 | 2 | 3 | 4;
|
|
955
914
|
|
|
956
|
-
export declare function sveld(opts?:
|
|
915
|
+
export declare function sveld(opts?: SveldRuntimeOptions): Promise<SveldResult>;
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{H,Ve,m,Bt,J,Se,jt,ke,Vt,Jt,Ut}from"./chunk-ssa3mr5n.js";import{ee}from"./chunk-nv6dzbmp.js";export{jt as CHECK_REPORT_SCHEMA_VERSION,ee as ComponentParser,Ve as DIAGNOSTICS_SCHEMA_VERSION,H as DIAGNOSTIC_CODES,m as buildComponentApiDocument,Jt as default,Vt as defineConfig,Bt as diffApiDocuments,Se as formatCheckReport,ke as formatCheckReportJson,J as runCheck,Ut as sveld};
|