sveld 0.37.2 → 0.37.4

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/lib/browser.d.ts CHANGED
@@ -110,11 +110,22 @@ interface ComponentPropParam {
110
110
  optional?: boolean;
111
111
  }
112
112
 
113
+ interface ComponentPropReExport {
114
+ /** Module specifier as written in the source (e.g. `"./utils.js"`). */
115
+ from: string;
116
+ /** Name `from` exports: `"default"` for a default import, `"*"` for `export *` or a namespace import. */
117
+ imported: string;
118
+ }
119
+
113
120
  interface ComponentProp {
114
- /** Public prop name. */
121
+ /** Public prop name; `"*"` for a bare `export * from "..."`. */
115
122
  name: string;
116
- /** `"let"` (required), `"const"` (default), or `"function"`. */
117
- kind: "let" | "const" | "function";
123
+ /**
124
+ * `"let"` (required), `"const"` (default), or `"function"`. `"re-export"`
125
+ * is module-export only: `export { x } from "..."`, `export * from "..."`,
126
+ * or `export { x }` of an imported binding, written to the `.d.ts` as-is.
127
+ */
128
+ kind: "let" | "const" | "function" | "re-export";
118
129
  /** True when declared with `const`. */
119
130
  constant: boolean;
120
131
  /** TypeScript type text. */
@@ -133,6 +144,12 @@ interface ComponentProp {
133
144
  params?: ComponentPropParam[];
134
145
  /** From JSDoc `@returns` on function props. */
135
146
  returnType?: string;
147
+ /**
148
+ * A function's own type parameter list from its `@template` tags (e.g.
149
+ * `T extends { id: string }`), without the angle brackets. Also prefixed
150
+ * onto `type` when that signature is built from `@param`/`@returns`.
151
+ */
152
+ typeParameters?: string;
136
153
  /**
137
154
  * True for arrow/function-expression initializers and bare `function`
138
155
  * declarations in every mode; additionally true for a function-shaped
@@ -158,6 +175,8 @@ interface ComponentProp {
158
175
  tags?: JsDocPassthroughTag[];
159
176
  /** True from `@ignore`/`@internal` JSDoc; excluded from every output by `buildComponentApiDocument`. */
160
177
  internal?: boolean;
178
+ /** Set when `kind` is `"re-export"`. */
179
+ reExport?: ComponentPropReExport;
161
180
  /** Source range when available. */
162
181
  source?: SourceRange;
163
182
  }
@@ -420,8 +439,17 @@ export class ComponentParser {
420
439
  tags?: JsDocPassthroughTag[];
421
440
  sveldIgnore?: string[];
422
441
  internal: boolean;
442
+ typeParameters?: string;
423
443
  } | undefined;
424
444
  private addModuleExport;
445
+ /**
446
+ * Resolves one `export { local as exported }` specifier to the variable
447
+ * declarator it names. Each specifier resolves on its own, so
448
+ * `export { a, b }` exports both, and `const a = 1, b = ""; export { b }`
449
+ * exports `b`'s declarator rather than the first one in the declaration.
450
+ */
451
+ private resolveExportSpecifier;
452
+ private recordUnresolvedExportSpecifier;
425
453
  /**
426
454
  * @example
427
455
  * ```ts
@@ -478,7 +506,7 @@ export class ComponentParser {
478
506
  parseSvelteComponent(source: string, diagnostics: ComponentParserDiagnostics): ParsedComponent;
479
507
  }
480
508
 
481
- export type SveldDiagnosticKind = "prop-unknown-type" | "context-any-type" | "slot-missing-type" | "event-no-source" | "example-compile-error" | "example-syntax-error" | "syntax-skipped" | "rest-props-unresolved" | "context-duplicate-key" | "spread-unresolved" | "export-unresolved" | "extend-props-target-missing" | "extend-props-duplicate" | "extend-props-override" | "jsdoc-unknown-tag" | "typedef-duplicate" | "property-duplicate" | "generics-conflict" | "jsdoc-tag-dropped" | "internal-typedef-referenced";
509
+ export type SveldDiagnosticKind = "prop-unknown-type" | "context-any-type" | "slot-missing-type" | "event-no-source" | "example-compile-error" | "example-syntax-error" | "syntax-skipped" | "rest-props-unresolved" | "context-duplicate-key" | "spread-unresolved" | "export-unresolved" | "module-export-conflict" | "extend-props-target-missing" | "extend-props-duplicate" | "extend-props-override" | "jsdoc-unknown-tag" | "typedef-duplicate" | "property-duplicate" | "generics-conflict" | "event-description-ambiguous" | "jsdoc-tag-dropped" | "internal-typedef-referenced" | "types-inline-unresolved";
482
510
 
483
511
  type SveldDiagnosticSeverity = "error" | "warning";
484
512
 
@@ -512,6 +540,95 @@ export interface ComponentDocApi extends ParsedComponent {
512
540
 
513
541
  export type ComponentDocs = Map<string, ComponentDocApi>;
514
542
 
543
+ interface InlinedTypes {
544
+ /** Exact `typeImportStatements` entries the writer must drop. */
545
+ droppedImportStatements: string[];
546
+ /** Declarations to emit (already stripped of `export`), in dependency order. */
547
+ declarations: string[];
548
+ /** Absolute paths of every file read, for watch-mode invalidation. */
549
+ dependencies: string[];
550
+ }
551
+
552
+ type CommentLevel = "all" | "descriptions" | "none";
553
+
554
+ export declare function formatTsProps(props?: string): string;
555
+
556
+ export declare function getTypeDefs(def: Pick<ComponentDocApi, "typedefs">, emit?: {
557
+ export: boolean;
558
+ }, commentLevel?: CommentLevel): string;
559
+
560
+ export declare function getContextDefs(def: Pick<ComponentDocApi, "contexts" | "generics">, emit?: {
561
+ export: boolean;
562
+ }, commentLevel?: CommentLevel): string;
563
+
564
+ export interface WriteTsDefinitionOptions {
565
+ /**
566
+ * `"class"` (default) extends the deprecated `SvelteComponentTyped`.
567
+ * `"component"` emits `declare const X: Component<Props, Exports, Bindings>`
568
+ * instead, for Svelte 5+ consumers. Generic components get a per-component
569
+ * interface with a generic call signature instead of `Component<...>`
570
+ * directly, since a `declare const` can't itself carry a generic type
571
+ * parameter (see `genGenericComponentDeclaration`).
572
+ */
573
+ format?: "class" | "component";
574
+ /**
575
+ * Which generated type declarations get an `export` keyword. `true`
576
+ * (default) exports all; `false` exports none; an object picks per kind.
577
+ * Module-script exports (`export declare const/function`) are runtime
578
+ * exports and are always emitted as exports.
579
+ */
580
+ exportTypes?: boolean | {
581
+ props?: boolean;
582
+ exports?: boolean;
583
+ typedefs?: boolean;
584
+ contexts?: boolean;
585
+ };
586
+ /** @internal Set by `writeTsDefinitions` for `@extends` targets; overrides `exportTypes.props`. */
587
+ forceExportProps?: boolean;
588
+ /**
589
+ * Templates for generated type names. `{name}` is replaced with the
590
+ * component's module name. Defaults: `"{name}Props"`, `"{name}Exports"`.
591
+ */
592
+ typeNames?: {
593
+ props?: string;
594
+ exports?: string;
595
+ };
596
+ /**
597
+ * How much JSDoc to emit. `"all"` (default) keeps descriptions,
598
+ * `@deprecated`, `@default`, and passthrough tags (`@since`, `@see`,
599
+ * `@example`, `@link`). `"descriptions"` keeps descriptions and
600
+ * `@deprecated` only. `"none"` emits no comments at all.
601
+ */
602
+ comments?: "all" | "descriptions" | "none";
603
+ /**
604
+ * `"type"` (default) emits the props type as a type alias.
605
+ * `"interface"` emits `interface <Name>Props { ... }` when the props are a
606
+ * plain object (no `@restProps`, no `@extendProps`, no whole-object
607
+ * `$props()` type); other shapes are intersections and stay aliases.
608
+ */
609
+ propsDeclaration?: "type" | "interface";
610
+ /**
611
+ * Copies `type`/`interface` declarations imported from a relative source (or a
612
+ * tsconfig/jsconfig path alias) directly into the `.d.ts`, dropping the import. `"local"`
613
+ * follows relative sources, path aliases, re-exports, and same-file dependencies; bare package
614
+ * imports, `.svelte` sources, and unsupported exports (enums, classes, functions, consts,
615
+ * namespaces) stay imports and get a `types-inline-unresolved` warning. `"all"` additionally
616
+ * inlines bare/package imports (e.g. `import type { Foo } from "some-lib"`) using the real
617
+ * TypeScript checker - same unsupported-export/collision rules, same warning on failure - with
618
+ * two exceptions kept as plain imports regardless: `svelte`/`svelte/elements` (a hard-coded
619
+ * allow-list; copying framework types would freeze a Svelte version into consumer output) and
620
+ * `@extendProps`/`@extends` targets (deferred; unrelated mechanism). `"all"` needs `typescript`
621
+ * 7+ and a `tsconfig.json`, same hard requirement as `resolveTypes`. `false` (default)
622
+ * preserves every import as-is.
623
+ * @default false
624
+ */
625
+ inline?: false | "local" | "all";
626
+ /** @internal Set by `writeTsDefinitions` from `GenerateBundleResult.inlinedTypesByFilePath` when `inline` resolved something for this component. */
627
+ inlined?: InlinedTypes;
628
+ }
629
+
630
+ export declare function writeTsDefinition(component: ComponentDocApi, options?: WriteTsDefinitionOptions): string;
631
+
515
632
  interface EntryExport {
516
633
  name: string;
517
634
  kind: "const" | "let" | "var" | "function" | "class" | "type" | "interface" | "enum";
@@ -735,26 +852,6 @@ declare class Writer {
735
852
  write(filePath: string, raw: string): Promise<boolean>;
736
853
  }
737
854
 
738
- export declare function formatTsProps(props?: string): string;
739
-
740
- export declare function getTypeDefs(def: Pick<ComponentDocApi, "typedefs">): string;
741
-
742
- export declare function getContextDefs(def: Pick<ComponentDocApi, "contexts" | "generics">): string;
743
-
744
- export interface WriteTsDefinitionOptions {
745
- /**
746
- * `"class"` (default) extends the deprecated `SvelteComponentTyped`.
747
- * `"component"` emits `declare const X: Component<Props, Exports, Bindings>`
748
- * instead, for Svelte 5+ consumers. Generic components get a per-component
749
- * interface with a generic call signature instead of `Component<...>`
750
- * directly, since a `declare const` can't itself carry a generic type
751
- * parameter (see `genGenericComponentDeclaration`).
752
- */
753
- format?: "class" | "component";
754
- }
755
-
756
- export declare function writeTsDefinition(component: ComponentDocApi, options?: WriteTsDefinitionOptions): string;
757
-
758
855
  export declare const COMPONENT_API_SCHEMA_VERSION = 1;
759
856
 
760
857
  export interface ComponentApiDocument {