sveld 0.37.3 → 0.37.5

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
@@ -435,7 +435,8 @@ Every diagnostic carries a stable, namespaced `code` (`"sveld/<kind>"`) alongsid
435
435
  | `sveld/rest-props-unresolved` | `warning` | Spread `$$restProps` onto a plain element (or `svelte:element`) instead of a component, or add an `@restProps` tag to type it manually. |
436
436
  | `sveld/context-duplicate-key` | `warning` | Remove the duplicate `setContext` call, or give it a distinct key; only the first call's shape is used. |
437
437
  | `sveld/spread-unresolved` | `warning` | Spread a local object literal or a variable with a resolvable type instead; otherwise the spread widens the generated type to `Record<string, any>`. |
438
- | `sveld/export-unresolved` | `warning` | Export a local declaration directly instead of re-exporting an import or a binding from another file; sveld only resolves exports of a local declaration. |
438
+ | `sveld/export-unresolved` | `warning` | Export a local declaration directly. Instance-script exports are props, so move a re-export (`export { x } from "..."`, or `export { x }` of an import) into `<script context="module">`, where sveld writes it to the `.d.ts` as-is. |
439
+ | `sveld/module-export-conflict` | `warning` | Rename the module-script export. `default` is always skipped (it collides with the component itself); a name matching the generated `<Name>Props`/`<Name>Exports` type breaks the `.d.ts` if the export carries a type. |
439
440
  | `sveld/extend-props-target-missing` | `error` | Point `@extends`/`@extendProps` at a file that exists, and (for a bundled `.svelte` target) name its generated `<Name>Props` interface exactly. |
440
441
  | `sveld/extend-props-duplicate` | `warning` | Remove the extra `@extends`/`@extendProps` tag; only the last one is used. |
441
442
  | `sveld/extend-props-override` | `warning` | Rename the own prop, or accept that it intentionally overrides the `@extends` target's prop of the same name. |
@@ -443,13 +444,14 @@ Every diagnostic carries a stable, namespaced `code` (`"sveld/<kind>"`) alongsid
443
444
  | `sveld/typedef-duplicate` | `warning` | Rename one of the `@typedef`/`@callback` declarations; only the later one is kept. |
444
445
  | `sveld/property-duplicate` | `warning` | Remove the duplicate `@property`; only the later one is kept. |
445
446
  | `sveld/generics-conflict` | `warning` | Rename one of the `@generics`/`@template` declarations to a distinct generic name. |
447
+ | `sveld/event-description-ambiguous` | `warning` | Put an event's description above its `@event` tag (or indent it as a continuation of the tag's line), or give each event its own comment block. Unindented text after an `@event` is read as the description of the tag below it. |
446
448
  | `sveld/jsdoc-tag-dropped` | `warning` | Move the tag next to a `@slot`/`@snippet`/`@event`/`@typedef`/`@callback` tag in the same comment block so it has something to attach to. |
447
449
  | `sveld/internal-typedef-referenced` | `error` | Remove `@internal`/`@ignore` from the referenced typedef, or stop referencing it from public type text (inline the shape, or make the referencing item `@internal` too). |
448
450
  | `sveld/types-inline-unresolved` | `warning` | The import is kept as-is. Point it at a relative `.ts` file that exports a `type`/`interface`, or rename the colliding type. |
449
451
 
450
452
  #### Severity and `--strict=errors`
451
453
 
452
- Each diagnostic's `severity` is `"error"` (`example-compile-error`, `example-syntax-error`, `syntax-skipped`, `extend-props-target-missing`, `internal-typedef-referenced` — sveld emitted broken or unmodeled output) or `"warning"` (`prop-unknown-type`, `context-any-type`, `slot-missing-type`, `event-no-source`, `rest-props-unresolved`, `context-duplicate-key`, `spread-unresolved`, `export-unresolved`, `extend-props-duplicate`, `extend-props-override`, `jsdoc-unknown-tag`, `typedef-duplicate`, `property-duplicate`, `generics-conflict`, `jsdoc-tag-dropped`, `types-inline-unresolved` — a type fell back to `any`). Plain `strict: true` / `--strict` fails on both, unchanged from before. Pass `strict: "errors"` (or `--strict=errors`) to fail CI only on `error`-severity diagnostics, letting `any`-fallback warnings through:
454
+ Each diagnostic's `severity` is `"error"` (`example-compile-error`, `example-syntax-error`, `syntax-skipped`, `extend-props-target-missing`, `internal-typedef-referenced` — sveld emitted broken or unmodeled output) or `"warning"` (`prop-unknown-type`, `context-any-type`, `slot-missing-type`, `event-no-source`, `rest-props-unresolved`, `context-duplicate-key`, `spread-unresolved`, `export-unresolved`, `module-export-conflict`, `extend-props-duplicate`, `extend-props-override`, `jsdoc-unknown-tag`, `typedef-duplicate`, `property-duplicate`, `generics-conflict`, `event-description-ambiguous`, `jsdoc-tag-dropped`, `types-inline-unresolved` — a type fell back to `any`). Plain `strict: true` / `--strict` fails on both, unchanged from before. Pass `strict: "errors"` (or `--strict=errors`) to fail CI only on `error`-severity diagnostics, letting `any`-fallback warnings through:
453
455
 
454
456
  ```sh
455
457
  npx sveld --json --strict=errors
@@ -2185,7 +2187,27 @@ Chained references are also resolved:
2185
2187
  count?: number;
2186
2188
  ```
2187
2189
 
2188
- Resolution follows up to 5 levels of indirection. Beyond that, the last resolved identifier name is used as the default value. If the identifier cannot be resolved (e.g., it is imported from another module), the variable name is used as-is.
2190
+ Resolution follows up to 5 levels of indirection. Beyond that, the last resolved identifier name is used as the default value.
2191
+
2192
+ A named import resolves when the imported module (followed through re-exports) declares it as an `export const` with a string, number, boolean, or static template literal:
2193
+
2194
+ ```svelte
2195
+ <script>
2196
+ // timing.js: export const TOOLTIP_LEAVE_DELAY_MS = 300;
2197
+ import { TOOLTIP_LEAVE_DELAY_MS } from "./timing.js";
2198
+
2199
+ export let leaveDelayMs = TOOLTIP_LEAVE_DELAY_MS;
2200
+ </script>
2201
+ ```
2202
+
2203
+ ```ts
2204
+ /**
2205
+ * @default 300
2206
+ */
2207
+ leaveDelayMs?: number;
2208
+ ```
2209
+
2210
+ Any other identifier that cannot be resolved (an `export let`, a computed value, a package import) is used as-is, and its type falls back to `any`.
2189
2211
 
2190
2212
  When an explicit `@default` annotation is provided, it always takes precedence over the resolved value.
2191
2213
 
@@ -2667,6 +2689,16 @@ function render(value: unknown, props: ComponentProps) {
2667
2689
 
2668
2690
  Both forms support the same modifiers as typedef properties elsewhere in this doc: optional properties (`[name]`), default values (`[name=value]`), and nested/discriminated-union shapes. See the linked sections above for full signatures and worked examples with generated output.
2669
2691
 
2692
+ A description can wrap onto continuation lines, which run until the next tag. Indent them past the `*` gutter to keep them attached to the tag unambiguously; an unindented line right above an `@event`/`@typedef`/`@slot` with no description of its own is read as that tag's description instead, and an unindented line after an event's last `@property` describes the event.
2693
+
2694
+ ```js
2695
+ /**
2696
+ * @typedef {object} Config
2697
+ * @property {number} itemHeight Height of each item in pixels, used for
2698
+ * virtualization math.
2699
+ */
2700
+ ```
2701
+
2670
2702
  ### `@callback`
2671
2703
 
2672
2704
  The `@callback` tag defines a function type with `@param` and `@returns`, following the [TypeScript JSDoc `@callback` spec](https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html#callback). Like `@typedef`, callbacks are exported from the generated `.d.ts`.
package/lib/browser.d.ts CHANGED
@@ -37,6 +37,13 @@ interface PendingCallDefaultCandidate {
37
37
  importedName?: string;
38
38
  }
39
39
 
40
+ interface PendingConstDefaultCandidate {
41
+ propName: string;
42
+ location: "props" | "moduleExports";
43
+ importSource: string;
44
+ importedName: string;
45
+ }
46
+
40
47
  interface PendingContextKeyCandidate {
41
48
  importSource: string;
42
49
  importedName: string;
@@ -60,6 +67,8 @@ interface ParsedComponentTypeScriptMetadata {
60
67
  referencesComponentGenerics?: boolean;
61
68
  /** Unresolved CallExpression defaults for the cross-file pass in `generateBundle`. */
62
69
  pendingCallDefaultCandidates?: PendingCallDefaultCandidate[];
70
+ /** Imported-identifier defaults for the cross-file pass in `generateBundle`. */
71
+ pendingConstDefaultCandidates?: PendingConstDefaultCandidate[];
63
72
  /** Unresolved `setContext` import keys for the cross-file pass in `generateBundle`. */
64
73
  pendingContextKeyCandidates?: PendingContextKeyCandidate[];
65
74
  }
@@ -110,11 +119,22 @@ interface ComponentPropParam {
110
119
  optional?: boolean;
111
120
  }
112
121
 
122
+ interface ComponentPropReExport {
123
+ /** Module specifier as written in the source (e.g. `"./utils.js"`). */
124
+ from: string;
125
+ /** Name `from` exports: `"default"` for a default import, `"*"` for `export *` or a namespace import. */
126
+ imported: string;
127
+ }
128
+
113
129
  interface ComponentProp {
114
- /** Public prop name. */
130
+ /** Public prop name; `"*"` for a bare `export * from "..."`. */
115
131
  name: string;
116
- /** `"let"` (required), `"const"` (default), or `"function"`. */
117
- kind: "let" | "const" | "function";
132
+ /**
133
+ * `"let"` (required), `"const"` (default), or `"function"`. `"re-export"`
134
+ * is module-export only: `export { x } from "..."`, `export * from "..."`,
135
+ * or `export { x }` of an imported binding, written to the `.d.ts` as-is.
136
+ */
137
+ kind: "let" | "const" | "function" | "re-export";
118
138
  /** True when declared with `const`. */
119
139
  constant: boolean;
120
140
  /** TypeScript type text. */
@@ -133,6 +153,12 @@ interface ComponentProp {
133
153
  params?: ComponentPropParam[];
134
154
  /** From JSDoc `@returns` on function props. */
135
155
  returnType?: string;
156
+ /**
157
+ * A function's own type parameter list from its `@template` tags (e.g.
158
+ * `T extends { id: string }`), without the angle brackets. Also prefixed
159
+ * onto `type` when that signature is built from `@param`/`@returns`.
160
+ */
161
+ typeParameters?: string;
136
162
  /**
137
163
  * True for arrow/function-expression initializers and bare `function`
138
164
  * declarations in every mode; additionally true for a function-shaped
@@ -158,6 +184,8 @@ interface ComponentProp {
158
184
  tags?: JsDocPassthroughTag[];
159
185
  /** True from `@ignore`/`@internal` JSDoc; excluded from every output by `buildComponentApiDocument`. */
160
186
  internal?: boolean;
187
+ /** Set when `kind` is `"re-export"`. */
188
+ reExport?: ComponentPropReExport;
161
189
  /** Source range when available. */
162
190
  source?: SourceRange;
163
191
  }
@@ -420,8 +448,17 @@ export class ComponentParser {
420
448
  tags?: JsDocPassthroughTag[];
421
449
  sveldIgnore?: string[];
422
450
  internal: boolean;
451
+ typeParameters?: string;
423
452
  } | undefined;
424
453
  private addModuleExport;
454
+ /**
455
+ * Resolves one `export { local as exported }` specifier to the variable
456
+ * declarator it names. Each specifier resolves on its own, so
457
+ * `export { a, b }` exports both, and `const a = 1, b = ""; export { b }`
458
+ * exports `b`'s declarator rather than the first one in the declaration.
459
+ */
460
+ private resolveExportSpecifier;
461
+ private recordUnresolvedExportSpecifier;
425
462
  /**
426
463
  * @example
427
464
  * ```ts
@@ -478,7 +515,7 @@ export class ComponentParser {
478
515
  parseSvelteComponent(source: string, diagnostics: ComponentParserDiagnostics): ParsedComponent;
479
516
  }
480
517
 
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" | "types-inline-unresolved";
518
+ export type SveldDiagnosticKind = "prop-unknown-type" | "context-any-type" | "slot-missing-type" | "event-no-source" | "example-compile-error" | "example-syntax-error" | "syntax-skipped" | "rest-props-unresolved" | "context-duplicate-key" | "spread-unresolved" | "export-unresolved" | "module-export-conflict" | "extend-props-target-missing" | "extend-props-duplicate" | "extend-props-override" | "jsdoc-unknown-tag" | "typedef-duplicate" | "property-duplicate" | "generics-conflict" | "event-description-ambiguous" | "jsdoc-tag-dropped" | "internal-typedef-referenced" | "types-inline-unresolved";
482
519
 
483
520
  type SveldDiagnosticSeverity = "error" | "warning";
484
521