sveld 0.38.0 → 0.38.2

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 CHANGED
@@ -279,7 +279,7 @@ Try sveld in the browser at [sveld.onrender.com](https://sveld.onrender.com) (so
279
279
  - Node 22 or later, or Bun. sveld is ESM-only.
280
280
  - A `sveld.config.ts` needs a runtime that strips TypeScript: Bun, or Node 22.18+ / 23.6+.
281
281
  - The optional [`checkExamples`](docs/ci.md#checking-example-blocks) check for TS/JS examples needs `typescript` 7+ and a `tsconfig.json`. Nothing else loads TypeScript.
282
- - Your installed Svelte version doesn't affect parsing. sveld uses its own template parser, kept in parity with `svelte/compiler`.
282
+ - Your installed Svelte version doesn't affect parsing. sveld parses with [sveast](https://github.com/metonym/sveast), kept in parity with `svelte/compiler`.
283
283
 
284
284
  ## Contributing
285
285
 
@@ -1,9 +1,3 @@
1
- import type { Property } from "estree";
2
-
3
- import type { Dirent } from "node:fs";
4
-
5
- import { type Program } from "acorn";
6
-
7
1
  declare const brand: unique symbol;
8
2
 
9
3
  type Brand<TBase extends string, TBrand extends string> = TBase & {
@@ -20,11 +14,6 @@ interface ComponentParserDiagnostics {
20
14
  }
21
15
 
22
16
  export class ComponentParser {
23
- /**
24
- * All per-parse mutable state (props, slots, events, scopes, source, etc.).
25
- * See {@link ParserContext} for field-by-field documentation. Replaced
26
- * wholesale by `cleanup()` between parses.
27
- */
28
17
  private ctx;
29
18
  /**
30
19
  * Resets parser state for reuse between parses.
@@ -65,9 +54,9 @@ interface JsDocPassthroughTag {
65
54
  type DeprecatedValue = string | true;
66
55
 
67
56
  interface SourcePosition {
68
- /** 1-based source line number */
57
+ /** 1-based. */
69
58
  line: number;
70
- /** 0-based source column number */
59
+ /** 0-based. */
71
60
  column: number;
72
61
  }
73
62
 
@@ -130,13 +119,9 @@ interface PendingDispatchEscapeCandidate {
130
119
  }
131
120
 
132
121
  interface PendingCrossFileCandidates {
133
- /** Unresolved CallExpression defaults. */
134
122
  pendingCallDefaultCandidates?: PendingCallDefaultCandidate[];
135
- /** Imported-identifier defaults. */
136
123
  pendingConstDefaultCandidates?: PendingConstDefaultCandidate[];
137
- /** Unresolved `setContext` import keys. */
138
124
  pendingContextKeyCandidates?: PendingContextKeyCandidate[];
139
- /** Dispatchers passed to imported functions. */
140
125
  pendingDispatchEscapeCandidates?: PendingDispatchEscapeCandidate[];
141
126
  /**
142
127
  * `event-no-source` diagnostics held back while the dispatcher escapes to
@@ -182,13 +167,9 @@ interface ComponentPropDefaultValue {
182
167
  type ComponentPropBinding = "readonly" | "writable";
183
168
 
184
169
  interface ComponentPropParam {
185
- /** Parameter name. */
186
170
  name: string;
187
- /** Parameter type (e.g. `"string"`, `"CustomType"`). */
188
171
  type: string;
189
- /** From JSDoc `@param`. */
190
172
  description?: string;
191
- /** True when optional. */
192
173
  optional?: boolean;
193
174
  }
194
175
 
@@ -235,7 +216,6 @@ interface ComponentProp {
235
216
  kind: "let" | "const" | "function" | "re-export" | "class";
236
217
  /** True when declared with `const`. */
237
218
  constant: boolean;
238
- /** TypeScript type text. */
239
219
  type?: string;
240
220
  /** Conservative provenance for the prop type. See the precedence rule on {@link ComponentProp}. */
241
221
  typeSource?: ComponentPropTypeSource;
@@ -272,7 +252,6 @@ interface ComponentProp {
272
252
  * type/JSDoc signature in runes only (see {@link ComponentProp}).
273
253
  */
274
254
  isFunction: boolean;
275
- /** True for `function` declarations. */
276
255
  isFunctionDeclaration: boolean;
277
256
  /** True when declared with `let` and no default. */
278
257
  isRequired: boolean;
@@ -293,14 +272,12 @@ interface ComponentProp {
293
272
  internal?: boolean;
294
273
  /** Set when `kind` is `"re-export"`. */
295
274
  reExport?: ComponentPropReExport;
296
- /** Source range when available. */
297
275
  source?: SourceRange;
298
276
  }
299
277
 
300
278
  interface ComponentSlot {
301
- /** Slot name (`null` for the default slot). */
279
+ /** `null` for the default slot. */
302
280
  name?: string | null;
303
- /** True for the default slot. */
304
281
  default: boolean;
305
282
  /** Fallback content when the slot is empty. */
306
283
  fallback?: string;
@@ -314,16 +291,12 @@ interface ComponentSlot {
314
291
  tags?: JsDocPassthroughTag[];
315
292
  /** True from `@ignore`/`@internal` JSDoc; excluded from every output by `buildComponentApiDocument`. */
316
293
  internal?: boolean;
317
- /** Source range when available. */
318
294
  source?: SourceRange;
319
295
  }
320
296
 
321
297
  interface DispatchedEvent {
322
- /** Discriminator: `"dispatched"`. */
323
298
  type: "dispatched";
324
- /** Event name. */
325
299
  name: string;
326
- /** Detail type text. */
327
300
  detail?: string;
328
301
  /** From JSDoc `@event`. */
329
302
  description?: string;
@@ -333,14 +306,11 @@ interface DispatchedEvent {
333
306
  tags?: JsDocPassthroughTag[];
334
307
  /** True from `@ignore`/`@internal` JSDoc; excluded from every output by `buildComponentApiDocument`. */
335
308
  internal?: boolean;
336
- /** Source range when available. */
337
309
  source?: SourceRange;
338
310
  }
339
311
 
340
312
  interface SerializedForwardedEvent {
341
- /** Discriminator: `"forwarded"`. */
342
313
  type: "forwarded";
343
- /** Event name. */
344
314
  name: string;
345
315
  /** Element name as a string for JSON output. */
346
316
  element: string;
@@ -354,7 +324,6 @@ interface SerializedForwardedEvent {
354
324
  tags?: JsDocPassthroughTag[];
355
325
  /** True from `@ignore`/`@internal` JSDoc; excluded from every output by `buildComponentApiDocument`. */
356
326
  internal?: boolean;
357
- /** Source range when available. */
358
327
  source?: SourceRange;
359
328
  }
360
329
 
@@ -363,9 +332,7 @@ export type SerializedComponentEvent = SerializedForwardedEvent | DispatchedEven
363
332
  interface TypeDef {
364
333
  /** Type text (e.g. `"{ x: number; y: number }"`). */
365
334
  type: string;
366
- /** Type name. */
367
335
  name: string;
368
- /** From JSDoc. */
369
336
  description?: string;
370
337
  /** Full `type` alias declaration text. */
371
338
  ts: string;
@@ -380,9 +347,7 @@ interface TypeDef {
380
347
  type ComponentGenerics = [name: string, type: string] | null;
381
348
 
382
349
  interface ComponentInlineElement {
383
- /** Discriminator: `"InlineComponent"`. */
384
350
  type: "InlineComponent";
385
- /** Component name. */
386
351
  name: string;
387
352
  }
388
353
 
@@ -447,20 +412,15 @@ interface ComponentCssProperty {
447
412
  }
448
413
 
449
414
  interface ComponentContextProp {
450
- /** Property name. */
451
415
  name: string;
452
- /** Property type text. */
453
416
  type: string;
454
- /** From JSDoc. */
455
417
  description?: string;
456
- /** True when optional. */
457
418
  optional: boolean;
458
419
  /** True from `@ignore`/`@internal` JSDoc; excluded from every output by `buildComponentApiDocument`. */
459
420
  internal?: boolean;
460
421
  }
461
422
 
462
423
  interface ComponentContext {
463
- /** Context key from `setContext`. */
464
424
  key: string;
465
425
  /** Generated type name (e.g. `"ModalContext"`). */
466
426
  typeName: string;
@@ -470,9 +430,8 @@ interface ComponentContext {
470
430
  * when untyped). `properties` is empty then.
471
431
  */
472
432
  type?: string;
473
- /** From JSDoc. */
474
433
  description?: string;
475
- /** Context object properties. Empty when {@link ComponentContext.type} is set. */
434
+ /** Empty when {@link ComponentContext.type} is set. */
476
435
  properties: ComponentContextProp[];
477
436
  /** True when a `{...spread}` in the context's object literal couldn't be resolved; the generated type intersects with `Record<string, any>`. */
478
437
  hasUnresolvedSpread?: boolean;
@@ -483,7 +442,6 @@ interface ComponentContext {
483
442
  }
484
443
 
485
444
  interface ParsedComponent {
486
- /** Source range of the parsed file. */
487
445
  source?: SourceRange;
488
446
  syntaxMode: SyntaxMode;
489
447
  scriptLanguage?: ScriptLanguage;
@@ -509,15 +467,13 @@ interface ParsedComponent {
509
467
  cssParts?: ComponentCssPart[];
510
468
  /** From component-level `@cssprop`/`@cssproperty` JSDoc tags. */
511
469
  cssProperties?: ComponentCssProperty[];
512
- /**
513
- * Type guesses from this parse (unknown props, `any` contexts, orphan `@event` tags).
514
- */
470
+ /** Type guesses from this parse (unknown props, `any` contexts, orphan `@event` tags). */
515
471
  diagnostics?: SveldDiagnostic[];
516
472
  /** Writer-only TypeScript metadata. Not serialized to JSON. */
517
473
  [PARSED_COMPONENT_TYPE_SCRIPT_METADATA]?: ParsedComponentTypeScriptMetadata;
518
474
  }
519
475
 
520
- export type SveldDiagnosticKind = "prop-unknown-type" | "context-any-type" | "slot-missing-type" | "event-no-source" | "dispatch-escapes" | "example-compile-error" | "example-syntax-error" | "syntax-skipped" | "type-syntax-error" | "rest-props-unresolved" | "context-duplicate-key" | "context-key-unresolved" | "context-value-unresolved" | "spread-unresolved" | "export-unresolved" | "module-export-conflict" | "extend-props-target-missing" | "extend-props-duplicate" | "extend-props-override" | "jsdoc-unknown-tag" | "typedef-duplicate" | "property-duplicate" | "generics-conflict" | "event-description-ambiguous" | "jsdoc-tag-dropped" | "internal-typedef-referenced" | "cross-file-unresolved" | "export-ambiguous";
476
+ 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";
521
477
 
522
478
  type SveldDiagnosticSeverity = "error" | "warning";
523
479
 
@@ -651,10 +607,9 @@ export interface WriteTsDefinitionOptions {
651
607
  /**
652
608
  * `"class"` (default) extends the deprecated `SvelteComponentTyped`.
653
609
  * `"component"` emits `declare const X: Component<Props, Exports, Bindings>`
654
- * instead, for Svelte 5+ consumers. Generic components get a per-component
655
- * interface with a generic call signature instead of `Component<...>`
656
- * directly, since a `declare const` can't itself carry a generic type
657
- * parameter (see `genGenericComponentDeclaration`).
610
+ * instead, for Svelte 5+ consumers. Generic components and components with
611
+ * events get a per-component interface instead, since a `declare const`
612
+ * can't carry a generic type parameter and `Component` has no events slot.
658
613
  */
659
614
  format?: "class" | "component";
660
615
  }