sveld 0.35.1 → 0.35.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.
Files changed (51) hide show
  1. package/README.md +0 -4
  2. package/cli.js +1 -1
  3. package/lib/ComponentParser.d.ts +139 -401
  4. package/lib/ast-guards.d.ts +0 -2
  5. package/lib/browser.js +203 -225
  6. package/lib/bundle.d.ts +1 -3
  7. package/lib/chunk-1p4ka68s.js +2 -0
  8. package/lib/chunk-72hx9e9w.js +20 -0
  9. package/lib/chunk-7qz0hzgw.js +217 -0
  10. package/lib/chunk-8xw75w8t.js +10 -0
  11. package/lib/chunk-cxrw7gzr.js +2 -0
  12. package/lib/chunk-jdnsv86e.js +1 -0
  13. package/lib/chunk-pmj8c3yv.js +6 -0
  14. package/lib/chunk-s9mzxa4y.js +1 -0
  15. package/lib/chunk-v4q9vw0y.js +62 -0
  16. package/lib/chunk-xkrgedm4.js +4 -0
  17. package/lib/chunk-zva3xjwa.js +13 -0
  18. package/lib/cli-entry.d.ts +12 -0
  19. package/lib/cli-entry.js +1 -0
  20. package/lib/get-svelte-entry.d.ts +0 -1
  21. package/lib/index.js +1 -343
  22. package/lib/parse-cache.d.ts +1 -1
  23. package/lib/parse-entry-exports.d.ts +2 -2
  24. package/lib/parsed-component-metadata.d.ts +13 -0
  25. package/lib/parser/bindings.d.ts +0 -2
  26. package/lib/parser/context.d.ts +7 -49
  27. package/lib/parser/events.d.ts +0 -2
  28. package/lib/parser/jsdoc.d.ts +0 -4
  29. package/lib/parser/prop-shared.d.ts +84 -0
  30. package/lib/parser/props.d.ts +0 -2
  31. package/lib/parser/rest-props.d.ts +0 -2
  32. package/lib/parser/runes-detection.d.ts +1 -4
  33. package/lib/parser/scopes.d.ts +0 -2
  34. package/lib/parser/slots.d.ts +0 -5
  35. package/lib/parser/source-position.d.ts +0 -4
  36. package/lib/parser/type-resolution.d.ts +0 -15
  37. package/lib/parser/typescript-casts.d.ts +0 -1
  38. package/lib/parser/utils.d.ts +1 -0
  39. package/lib/parser/variable-jsdoc.d.ts +12 -0
  40. package/lib/parser-stack.d.ts +20 -0
  41. package/lib/path.d.ts +0 -1
  42. package/lib/svelte-parse.d.ts +4 -0
  43. package/lib/svelte-version.d.ts +1 -0
  44. package/lib/writer/Writer.d.ts +7 -29
  45. package/lib/writer/WriterMarkdown.d.ts +0 -2
  46. package/lib/writer/markdown-format-utils.d.ts +0 -84
  47. package/lib/writer/writer-json.d.ts +2 -12
  48. package/lib/writer/writer-markdown.d.ts +0 -2
  49. package/lib/writer/writer-ts-definitions-core.d.ts +1 -9
  50. package/lib/writer/writer-ts-definitions.d.ts +1 -28
  51. package/package.json +1 -1
@@ -1,8 +1,9 @@
1
1
  import type { Property } from "estree";
2
2
  import type { Node } from "estree-walker";
3
3
  import type { SveldDiagnostic } from "./diagnostics";
4
- /** Returns `value`, or `undefined` when it's `undefined` or the empty string. */
5
- export declare function assignValue(value?: "" | string): string | undefined;
4
+ import { PARSED_COMPONENT_TYPE_SCRIPT_METADATA } from "./parsed-component-metadata";
5
+ import { assignValueOrUndefined } from "./parser/utils";
6
+ export { assignValueOrUndefined as assignValue };
6
7
  /** Structured JSDoc tag (e.g. `{ name: "since", body: "1.2.0" }`). */
7
8
  export interface JsDocPassthroughTag {
8
9
  name: string;
@@ -100,10 +101,7 @@ export interface ParsedComponentTypeScriptMetadata {
100
101
  */
101
102
  referencesComponentGenerics?: boolean;
102
103
  }
103
- export declare const PARSED_COMPONENT_TYPE_SCRIPT_METADATA: unique symbol;
104
- export declare function getParsedComponentTypeScriptMetadata(component: {
105
- [PARSED_COMPONENT_TYPE_SCRIPT_METADATA]?: ParsedComponentTypeScriptMetadata;
106
- }): ParsedComponentTypeScriptMetadata | undefined;
104
+ export { applyResolvedProps, getParsedComponentTypeScriptMetadata, PARSED_COMPONENT_TYPE_SCRIPT_METADATA, } from "./parsed-component-metadata";
107
105
  /** One prop returned by the TypeScript checker during `resolveTypes`. */
108
106
  export interface ResolvedComponentProp {
109
107
  name: string;
@@ -111,8 +109,6 @@ export interface ResolvedComponentProp {
111
109
  isRequired: boolean;
112
110
  description?: string;
113
111
  }
114
- /** Append checker-resolved props. Names the AST walker already found are left alone. */
115
- export declare function applyResolvedProps(component: ParsedComponent, resolved: ResolvedComponentProp[]): void;
116
112
  export type SyntaxMode = "legacy" | "runes";
117
113
  export type ScriptLanguage = "js" | "ts";
118
114
  export type ScopeBindingKind = "prop" | "local";
@@ -151,120 +147,119 @@ type ModernScriptAttribute = {
151
147
  export type ModernScriptNode = {
152
148
  attributes?: ModernScriptAttribute[];
153
149
  };
154
- /**
155
- * Diagnostic information for component parsing.
156
- *
157
- * Used to provide context about the component being parsed for error
158
- * messages and logging.
159
- */
160
150
  interface ComponentParserDiagnostics {
161
- /** The module/component name (e.g., "Button", "App") */
162
151
  moduleName: string;
163
- /** The file path to the component (e.g., "./Button.svelte") */
164
152
  filePath: string;
165
153
  }
166
154
  export type ComponentPropBinding = "readonly" | "writable";
167
- /**
168
- * Parameter information for function props.
169
- *
170
- * Extracted from JSDoc `@param` tags to provide detailed function signatures.
171
- */
155
+ /** Function prop parameter from JSDoc `@param` tags. */
172
156
  export interface ComponentPropParam {
173
- /** The parameter name */
157
+ /** Parameter name. */
174
158
  name: string;
175
- /** The parameter type (e.g., "string", "number", "CustomType") */
159
+ /** Parameter type (e.g. `"string"`, `"CustomType"`). */
176
160
  type: string;
177
- /** Optional description from JSDoc */
161
+ /** From JSDoc `@param`. */
178
162
  description?: string;
179
- /** Whether the parameter is optional */
163
+ /** True when optional. */
180
164
  optional?: boolean;
181
165
  }
182
166
  /**
183
- * Component prop definition extracted from Svelte component.
167
+ * A parsed component prop: the shared internal IR that every prop front-end
168
+ * (legacy `<script context="module">` exports, legacy instance
169
+ * `export let`/`export function`, and runes `$props()` destructuring)
170
+ * produces via {@link resolvePropTypeAndDocs}, then hands to `addProp`. The
171
+ * three front-ends differ only in how they extract the raw signals (type
172
+ * text, JSDoc, initializer shape) from their respective AST shapes; the
173
+ * decisions below are shared and, outside the two documented mode
174
+ * differences, identical across modes.
184
175
  *
185
- * Represents a single prop that can be passed to the component, including
186
- * its type, default value, description, and metadata about whether it's
187
- * required, reactive, or a function.
176
+ * - `typeSource` precedence: an explicit TypeScript annotation always wins,
177
+ * then JSDoc (`@type`/`@param`/`@returns`), then a type resolved from an
178
+ * identifier default's own JSDoc, and only then a bare inferred/initializer
179
+ * type. See {@link resolveTypeSource}.
180
+ * - JSDoc-vs-TS merge: `type`/`params`/`returnType`/`description` each
181
+ * independently prefer their JSDoc-sourced value over the identifier
182
+ * default's resolved value; an explicit TypeScript type additionally beats
183
+ * JSDoc for `type` only.
184
+ * - Mode difference (preserved, not converged): legacy `export let`/
185
+ * `export function` never infers `isFunction` from a function-shaped type
186
+ * text; runes `$props()` does (`inferIsFunctionFromTypeSignature`).
187
+ * - Mode difference (preserved, not converged): legacy falls back to a
188
+ * matching `@typedef`'s own description when the prop has none; runes does
189
+ * not pass `typedefs` to {@link resolvePropTypeAndDocs} today.
188
190
  */
189
191
  export interface ComponentProp {
190
- /** The prop name as declared in the component */
192
+ /** Public prop name. */
191
193
  name: string;
192
- /** The declaration kind: "let" (required), "const" (optional with default), or "function" */
194
+ /** `"let"` (required), `"const"` (default), or `"function"`. */
193
195
  kind: "let" | "const" | "function";
194
- /** Whether this prop is declared as `const` (has a default value) */
196
+ /** True when declared with `const`. */
195
197
  constant: boolean;
196
- /** The TypeScript type of the prop (e.g., "string", "number | string") */
198
+ /** TypeScript type text. */
197
199
  type?: string;
198
- /** Conservative provenance for the prop type */
200
+ /** Conservative provenance for the prop type. See the precedence rule on {@link ComponentProp}. */
199
201
  typeSource?: ComponentPropTypeSource;
200
- /** Local variable name, emitted when it differs from the public prop name */
202
+ /** Local binding when it differs from the public name. */
201
203
  localName?: string;
202
- /** The default value as a string representation of the source code */
204
+ /** Default value as source text; unset when the prop has no initializer/default. */
203
205
  value?: string;
204
- /** Structured default value metadata for docs UIs */
206
+ /** Structured default value metadata for docs UIs; set alongside `value` from the same initializer. */
205
207
  defaultValue?: ComponentPropDefaultValue;
206
- /** Description extracted from JSDoc comments */
208
+ /** From JSDoc, or a matching `@typedef`'s own description (legacy only; see {@link ComponentProp}). */
207
209
  description?: string;
208
- /** Function parameters (for function props) extracted from `@param` tags */
210
+ /** From JSDoc `@param` on function props. */
209
211
  params?: ComponentPropParam[];
210
- /** Return type (for function props) extracted from `@returns` tag */
212
+ /** From JSDoc `@returns` on function props. */
211
213
  returnType?: string;
212
- /** Whether this prop is a function (arrow function or function expression) */
214
+ /**
215
+ * True for arrow/function-expression initializers and bare `function`
216
+ * declarations in every mode; additionally true for a function-shaped
217
+ * type/JSDoc signature in runes only (see {@link ComponentProp}).
218
+ */
213
219
  isFunction: boolean;
214
- /** Whether this prop is a function declaration (not an expression) */
220
+ /** True for `function` declarations. */
215
221
  isFunctionDeclaration: boolean;
216
- /** Whether this prop is required (no default value, declared with `let`) */
222
+ /** True when declared with `let` and no default. */
217
223
  isRequired: boolean;
218
- /** Whether this prop is reactive (can change and trigger reactivity) */
224
+ /**
225
+ * True when the prop is mutated locally (legacy, inferred from assignment/
226
+ * binding targets) or declared with `$bindable()` (runes).
227
+ */
219
228
  reactive: boolean;
220
- /** Explicit author-documented binding direction from `@bindable` JSDoc */
229
+ /** Binding direction from `@bindable` JSDoc. */
221
230
  binding?: ComponentPropBinding;
222
- /** True when the prop is explicitly declared with Svelte 5 `$bindable()` */
231
+ /** True when declared with Svelte 5 `$bindable()` (runes only). */
223
232
  bindable?: true;
224
233
  /** From `@deprecated` JSDoc. */
225
234
  deprecated?: DeprecatedValue;
226
- /** Structured `@since` / `@example` tags, in source order. */
235
+ /** `@since` / `@example` tags in source order. */
227
236
  tags?: JsDocPassthroughTag[];
228
- /** Source range for the prop declaration, when available */
237
+ /** Source range when available. */
229
238
  source?: SourceRange;
230
239
  }
231
- /**
232
- * Component slot definition.
233
- *
234
- * Represents a slot that can be used to pass content into the component.
235
- * Includes information about slot props, fallback content, and descriptions.
236
- */
237
240
  export interface ComponentSlot {
238
- /** The slot name (null or undefined for default slot) */
241
+ /** Slot name (`null` for the default slot). */
239
242
  name?: string | null;
240
- /** Whether this is the default slot */
243
+ /** True for the default slot. */
241
244
  default: boolean;
242
- /** Fallback content to display when slot is not provided */
245
+ /** Fallback content when the slot is empty. */
243
246
  fallback?: string;
244
- /** TypeScript type definition for slot props (e.g., "{ title: string }") */
247
+ /** Slot props as TypeScript type text. */
245
248
  slot_props?: string;
246
- /** Description extracted from JSDoc `@slot` or `@snippet` tags */
249
+ /** From JSDoc `@slot` or `@snippet`. */
247
250
  description?: string;
248
251
  /** From `@deprecated` JSDoc. */
249
252
  deprecated?: DeprecatedValue;
250
- /**
251
- * JSDoc tags that appeared after the prose description and before `@slot` / `@snippet`
252
- * (e.g. `@example`), in source order.
253
- */
253
+ /** Tags between the description and `@slot`/`@snippet` (e.g. `@example`), in source order. */
254
254
  tags?: JsDocPassthroughTag[];
255
- /** Source range for the slot/snippet declaration or documentation tag, when available */
255
+ /** Source range when available. */
256
256
  source?: SourceRange;
257
257
  }
258
- /**
259
- * Slot prop value definition.
260
- *
261
- * Used internally to track slot prop types and whether they should be
262
- * replaced with prop type references.
263
- */
258
+ /** Slot prop type text or a reference to resolve at finalize time. */
264
259
  export interface SlotPropValue {
265
- /** The prop type value or reference */
260
+ /** Type text or reference. */
266
261
  value?: string;
267
- /** Whether this value should be replaced with a prop type reference */
262
+ /** True to replace with a prop type reference. */
268
263
  replace: boolean;
269
264
  }
270
265
  export type SlotProps = Record<string, SlotPropValue>;
@@ -279,60 +274,45 @@ export type SlotProps = Record<string, SlotPropValue>;
279
274
  export type InternalComponentSlot = Omit<ComponentSlot, "slot_props"> & {
280
275
  slot_props?: string | SlotProps;
281
276
  };
282
- /**
283
- * Event that is forwarded from a child component or element.
284
- *
285
- * Forwarded events are those that use `on:eventname` syntax without
286
- * a handler, passing the event through to the parent.
287
- */
277
+ /** Event forwarded with `on:eventname` and no handler. */
288
278
  export interface ForwardedEvent {
289
- /** Always "forwarded" for forwarded events */
279
+ /** Discriminator: `"forwarded"`. */
290
280
  type: "forwarded";
291
- /** The event name (e.g., "click", "change") */
281
+ /** Event name. */
292
282
  name: string;
293
- /** The element or component that forwards this event */
283
+ /** Element or component that forwards the event. */
294
284
  element: ComponentInlineElement | ComponentElement;
295
- /** Description extracted from JSDoc `@event` tags */
285
+ /** From JSDoc `@event`. */
296
286
  description?: string;
297
287
  /** From `@deprecated` JSDoc. */
298
288
  deprecated?: DeprecatedValue;
299
- /** The detail type if explicitly specified in `@event` tag */
289
+ /** Detail type from `@event`. */
300
290
  detail?: string;
301
- /** Structured `@since` / `@example` tags, in source order. */
291
+ /** `@since` / `@example` tags in source order. */
302
292
  tags?: JsDocPassthroughTag[];
303
- /** Source range for the forwarded event declaration or documentation tag, when available */
293
+ /** Source range when available. */
304
294
  source?: SourceRange;
305
295
  }
306
- /**
307
- * Event that is dispatched by the component.
308
- *
309
- * Dispatched events are those created with `createEventDispatcher()` and
310
- * dispatched via `dispatch("eventname", detail)`, or dispatched from a custom
311
- * element via `$host().dispatchEvent(new CustomEvent("eventname", { detail }))`.
312
- */
296
+ /** Event from `createEventDispatcher()`, `dispatch()`, or `$host().dispatchEvent()`. */
313
297
  export interface DispatchedEvent {
314
- /** Always "dispatched" for dispatched events */
298
+ /** Discriminator: `"dispatched"`. */
315
299
  type: "dispatched";
316
- /** The event name (e.g., "click", "change") */
300
+ /** Event name. */
317
301
  name: string;
318
- /** The detail type (e.g., "{ value: string }", "null", "CustomEvent<...>") */
302
+ /** Detail type text. */
319
303
  detail?: string;
320
- /** Description extracted from JSDoc `@event` tags */
304
+ /** From JSDoc `@event`. */
321
305
  description?: string;
322
306
  /** From `@deprecated` JSDoc. */
323
307
  deprecated?: DeprecatedValue;
324
- /** Structured `@since` / `@example` tags, in source order. */
308
+ /** `@since` / `@example` tags in source order. */
325
309
  tags?: JsDocPassthroughTag[];
326
- /** Source range for the dispatched event call or documentation tag, when available */
310
+ /** Source range when available. */
327
311
  source?: SourceRange;
328
312
  }
329
313
  export type ComponentEvent = ForwardedEvent | DispatchedEvent;
330
314
  /**
331
- * Serialized version of {@link ForwardedEvent} for JSON output.
332
- *
333
- * This interface maintains backward compatibility by serializing the `element`
334
- * property as a string instead of an object. The element name is extracted
335
- * from the {@link ComponentInlineElement} or {@link ComponentElement} object.
315
+ * Serialized {@link ForwardedEvent} for JSON output. `element` is a string, not an object.
336
316
  *
337
317
  * @example
338
318
  * ```ts
@@ -344,63 +324,47 @@ export type ComponentEvent = ForwardedEvent | DispatchedEvent;
344
324
  * ```
345
325
  */
346
326
  export interface SerializedForwardedEvent {
347
- /** Always "forwarded" for forwarded events */
327
+ /** Discriminator: `"forwarded"`. */
348
328
  type: "forwarded";
349
- /** The event name (e.g., "click", "change") */
329
+ /** Event name. */
350
330
  name: string;
351
- /**
352
- * Serialized as string for JSON backward compatibility.
353
- * In the internal API, this is an object, but for JSON output it's a string.
354
- */
331
+ /** Element name as a string for JSON output. */
355
332
  element: string;
356
- /** Description extracted from JSDoc `@event` tags */
333
+ /** From JSDoc `@event`. */
357
334
  description?: string;
358
335
  /** From `@deprecated` JSDoc. */
359
336
  deprecated?: DeprecatedValue;
360
- /** The detail type if explicitly specified in `@event` tag */
337
+ /** Detail type from `@event`. */
361
338
  detail?: string;
362
- /** Structured `@since` / `@example` tags, in source order. */
339
+ /** `@since` / `@example` tags in source order. */
363
340
  tags?: JsDocPassthroughTag[];
364
- /** Source range for the forwarded event declaration or documentation tag, when available */
341
+ /** Source range when available. */
365
342
  source?: SourceRange;
366
343
  }
367
344
  export type SerializedComponentEvent = SerializedForwardedEvent | DispatchedEvent;
368
- /**
369
- * Type definition extracted from JSDoc `@typedef` tags.
370
- *
371
- * Represents custom types defined in component comments that can be
372
- * referenced by props, events, and other type annotations.
373
- */
345
+ /** JSDoc `@typedef` extracted as a named type. */
374
346
  export interface TypeDef {
375
- /** The type string representation (e.g., "{ x: number; y: number }") */
347
+ /** Type text (e.g. `"{ x: number; y: number }"`). */
376
348
  type: string;
377
- /** The type name (e.g., "Point", "User") */
349
+ /** Type name. */
378
350
  name: string;
379
- /** Description extracted from JSDoc comments */
351
+ /** From JSDoc. */
380
352
  description?: string;
381
- /** The full TypeScript type definition string (e.g., "type Point = { x: number; y: number }") */
353
+ /** Full `type` alias declaration text. */
382
354
  ts: string;
383
355
  }
384
356
  export type ComponentGenerics = [name: string, type: string] | null;
385
- /**
386
- * Represents an inline Svelte component element.
387
- *
388
- * Used to identify which component forwards an event or accepts rest props.
389
- */
390
357
  export interface ComponentInlineElement {
391
- /** Always "InlineComponent" for component elements */
358
+ /** Discriminator: `"InlineComponent"`. */
392
359
  type: "InlineComponent";
393
- /** The component name (e.g., "Button", "Modal") */
360
+ /** Component name. */
394
361
  name: string;
395
362
  }
396
363
  export interface ComponentElement {
397
364
  type: "Element";
398
365
  name: string;
399
366
  /**
400
- * For `svelte:element`, stores the hardcoded element tag if `this` is a literal string.
401
- *
402
- * When `svelte:element` is used with a static tag (e.g., `svelte:element this="div"`),
403
- * this property contains the tag name. If the tag is dynamic, this property is undefined.
367
+ * Static tag for `svelte:element this="div"`. Undefined when `this` is dynamic.
404
368
  *
405
369
  * @example
406
370
  * ```svelte
@@ -414,62 +378,43 @@ export interface ComponentElement {
414
378
  * ```
415
379
  */
416
380
  thisValue?: string;
417
- /** Inline or block description from the `@restProps` JSDoc tag */
381
+ /** From `@restProps` JSDoc. */
418
382
  description?: string;
419
383
  }
420
384
  export type RestProps = undefined | ComponentInlineElement | ComponentElement;
421
- /**
422
- * Interface extension information from JSDoc `@extends` tag.
423
- *
424
- * Allows components to extend external TypeScript interfaces for
425
- * better type safety and code reuse.
426
- */
385
+ /** JSDoc `@extends` target. */
427
386
  export interface Extends {
428
- /** The interface name to extend (e.g., "ButtonProps") */
387
+ /** Interface name (e.g. `"ButtonProps"`). */
429
388
  interface: string;
430
- /** The import path for the interface (e.g., "./types" or "carbon-components-svelte") */
389
+ /** Import path (e.g. `"./types"`). */
431
390
  import: string;
432
391
  }
433
392
  export interface ComponentPropBindings {
434
393
  elements: string[];
435
394
  }
436
- /**
437
- * Property definition for a component context.
438
- *
439
- * Represents a single property in a context object created with `setContext`.
440
- */
441
395
  export interface ComponentContextProp {
442
- /** The property name */
396
+ /** Property name. */
443
397
  name: string;
444
- /** The property type (inferred from JSDoc or variable types) */
398
+ /** Property type text. */
445
399
  type: string;
446
- /** Description extracted from JSDoc comments on the variable */
400
+ /** From JSDoc. */
447
401
  description?: string;
448
- /** Whether the property is optional */
402
+ /** True when optional. */
449
403
  optional: boolean;
450
404
  }
451
- /**
452
- * Component context definition.
453
- *
454
- * Represents a context created with `setContext(key, value)` that can be
455
- * accessed by child components via `getContext(key)`.
456
- */
405
+ /** Context from `setContext(key, value)`. */
457
406
  export interface ComponentContext {
458
- /** The context key (e.g., "modal", "tabs") */
407
+ /** Context key from `setContext`. */
459
408
  key: string;
460
- /** The generated TypeScript type name (e.g., "ModalContext", "TabsContext") */
409
+ /** Generated type name (e.g. `"ModalContext"`). */
461
410
  typeName: string;
462
- /** Description extracted from JSDoc comments */
411
+ /** From JSDoc. */
463
412
  description?: string;
464
- /** Properties available in this context */
413
+ /** Context object properties. */
465
414
  properties: ComponentContextProp[];
466
415
  }
467
416
  /**
468
- * Complete parsed component metadata.
469
- *
470
- * This is the main return type from {@link ComponentParser.parseSvelteComponent}.
471
- * Contains all extracted information about a Svelte component including props,
472
- * slots, events, types, and more.
417
+ * Complete parsed component metadata from {@link ComponentParser.parseSvelteComponent}.
473
418
  *
474
419
  * @example
475
420
  * ```ts
@@ -479,51 +424,39 @@ export interface ComponentContext {
479
424
  * filePath: "./Button.svelte"
480
425
  * });
481
426
  *
482
- * // Access component metadata:
483
- * parsed.props // Array of component props
484
- * parsed.slots // Array of component slots
485
- * parsed.events // Array of component events
486
- * parsed.typedefs // Array of custom type definitions
487
- * parsed.contexts // Array of context definitions
427
+ * parsed.props;
428
+ * parsed.slots;
429
+ * parsed.events;
430
+ * parsed.typedefs;
431
+ * parsed.contexts;
488
432
  * ```
489
433
  */
490
434
  export interface ParsedComponent {
491
- /** Source range for the component source that was parsed */
435
+ /** Source range of the parsed file. */
492
436
  source?: SourceRange;
493
- /** Whether the component uses legacy or runes syntax according to compiler metadata */
494
437
  syntaxMode: SyntaxMode;
495
- /** Language used by the instance or module script when it can be determined */
496
438
  scriptLanguage?: ScriptLanguage;
497
- /** Component props that can be passed to the component */
439
+ /** Instance-level props (`export let`/`export function`, or runes `$props()`). See {@link ComponentProp} for the shared IR these are built from. */
498
440
  props: ComponentProp[];
499
- /** Exports from `<script context="module">` block */
441
+ /** Exports from `<script context="module">`. Same {@link ComponentProp} shape as `props`, resolved through the same shared decisions. */
500
442
  moduleExports: ComponentProp[];
501
- /** Slots available in the component template */
502
443
  slots: ComponentSlot[];
503
- /** Events that the component can dispatch or forward (serialized for JSON/API output) */
444
+ /** Serialized events for JSON/API output. */
504
445
  events: SerializedComponentEvent[];
505
- /** Custom type definitions from JSDoc `@typedef` tags */
506
446
  typedefs: TypeDef[];
507
- /** Generic type parameters (e.g., `[name: "T", type: "string"]`) or null */
508
447
  generics: null | ComponentGenerics;
509
- /** Rest props configuration (which elements/components accept rest props) */
510
448
  rest_props: RestProps;
511
- /** Interface extension from JSDoc `@extends` tag */
512
449
  extends?: Extends;
513
- /** Component-level description from `@component` HTML comment */
450
+ /** From `@component` HTML comment. */
514
451
  componentComment?: string;
515
- /** Source range for the `@component` HTML comment, when available */
516
452
  componentCommentSource?: SourceRange;
517
- /** Contexts created with `setContext` in the component */
518
453
  contexts?: ComponentContext[];
519
- /** Custom-element tag name from `<svelte:options customElement="x-foo" />` (or the object form's `tag`), when present */
520
454
  customElementTag?: string;
521
455
  /**
522
456
  * Type guesses from this parse (unknown props, `any` contexts, orphan `@event` tags).
523
- * Set on every {@link ComponentParser.parseSvelteComponent} call.
524
457
  */
525
458
  diagnostics?: SveldDiagnostic[];
526
- /** Internal writer-only TypeScript metadata. Not serialized to JSON. */
459
+ /** Writer-only TypeScript metadata. Not serialized to JSON. */
527
460
  [PARSED_COMPONENT_TYPE_SCRIPT_METADATA]?: ParsedComponentTypeScriptMetadata;
528
461
  }
529
462
  export default class ComponentParser {
@@ -560,38 +493,7 @@ export default class ComponentParser {
560
493
  getPropTypeByLocalOrPublic(name: string): string | undefined;
561
494
  getExplicitPropType(name: string): string | undefined;
562
495
  getPropertyName(node: Property["key"]): string | undefined;
563
- /**
564
- * Checks if a MemberExpression represents a well-known numeric constant.
565
- *
566
- * Identifies constants from the Number and Math objects that should be
567
- * typed as `number` rather than their literal values.
568
- *
569
- * @param memberExpr - The AST node to check
570
- * @returns True if the expression is a recognized numeric constant
571
- *
572
- * @example
573
- * ```ts
574
- * // Recognized constants:
575
- * Number.POSITIVE_INFINITY // true
576
- * Number.MAX_VALUE // true
577
- * Math.PI // true
578
- * Math.E // true
579
- *
580
- * // Not recognized:
581
- * Custom.CONSTANT // false
582
- * Number.UNKNOWN // false
583
- * ```
584
- */
585
496
  isNumericConstant(memberExpr: unknown): boolean;
586
- resolveTypeSource({ hasTypeScriptType, hasJSDocType, inferredType, finalType, }: {
587
- hasTypeScriptType?: boolean;
588
- hasJSDocType?: boolean;
589
- inferredType?: string;
590
- finalType?: string;
591
- }): ComponentPropTypeSource;
592
- /**
593
- * Look up JSDoc on a local variable declaration by name.
594
- */
595
497
  resolveLocalVarJSDoc(name: string): {
596
498
  type?: string;
597
499
  params?: ComponentPropParam[];
@@ -601,212 +503,49 @@ export default class ComponentParser {
601
503
  deprecated?: DeprecatedValue;
602
504
  tags?: JsDocPassthroughTag[];
603
505
  } | undefined;
604
- /**
605
- * Adds or merges a module export to the moduleExports map.
606
- *
607
- * Similar to {@link addProp}, but for exported values from the module script.
608
- * If an export with the same name already exists, the new data is merged
609
- * with the existing export.
610
- *
611
- * @param prop_name - The name of the exported value
612
- * @param data - The export data to add or merge
613
- *
614
- * @example
615
- * ```ts
616
- * // For: export const API_URL = "https://api.example.com"
617
- * addModuleExport("API_URL", {
618
- * name: "API_URL",
619
- * kind: "const",
620
- * type: "string",
621
- * value: '"https://api.example.com"'
622
- * })
623
- * ```
624
- */
625
506
  private addModuleExport;
626
507
  /**
627
- * Normalizes type strings by aliasing common patterns.
628
- *
629
- * Converts `*` to `any` (common JSDoc wildcard) and trims whitespace
630
- * from type annotations.
631
- *
632
- * @param type - The type string to normalize
633
- * @returns The normalized type string
634
- *
635
508
  * @example
636
509
  * ```ts
637
- * aliasType("*") // Returns: "any"
638
- * aliasType(" string ") // Returns: "string"
639
- * aliasType("number") // Returns: "number"
510
+ * aliasType("*"); // "any"
511
+ * aliasType(" string "); // "string"
640
512
  * ```
641
513
  */
642
514
  aliasType(type: string): string;
643
515
  /**
644
- * Builds a cache of variable type information from JSDoc comments.
645
- *
646
- * Scans the source code for variable declarations and extracts type information
647
- * from preceding JSDoc comments. This cache is used to infer types for context
648
- * properties and other variable references.
649
- *
650
- * @example
651
- * ```ts
652
- * // Source code:
653
- * /**
654
- * * @type {string}
655
- * * The user's name
656
- * *\/
657
- * const userName = "John";
658
- *
659
- * // Cache entry:
660
- * // { "userName": { type: "string", description: "The user's name" } }
661
- * ```
662
- */
663
- private buildVariableInfoCache;
664
- /**
665
- * Cache for compiled regex patterns for variable name matching.
666
- *
667
- * Stores three regex patterns (const, let, function) per variable name
668
- * to avoid recreating them on each lookup. Improves performance when
669
- * searching for the same variable multiple times.
670
- */
671
- private static readonly VAR_NAME_REGEX_CACHE;
672
- /**
673
- * Gets or creates cached regex patterns for matching variable declarations.
674
- *
675
- * Creates three regex patterns for matching const, let, and function declarations
676
- * of a specific variable name. The patterns are cached to avoid recreating them
677
- * for the same variable name.
678
- *
679
- * @param varName - The variable name to create regex patterns for
680
- * @returns A tuple of three RegExp objects for const, let, and function patterns
681
- *
682
516
  * @example
683
517
  * ```ts
684
- * getVarNameRegexes("count")
685
- * // Returns:
686
- * // [
687
- * // /\bconst\s+count\s*=/,
688
- * // /\blet\s+count\s*=/,
689
- * // /\bfunction\s+count\s*\(/
690
- * // ]
691
- * ```
692
- */
693
- private static getVarNameRegexes;
694
- /**
695
- * Finds the type and description for a variable by searching for its JSDoc comment.
696
- *
697
- * First checks the cache built by {@link buildVariableInfoCache}. If not found,
698
- * searches the source code directly for the variable declaration and its
699
- * preceding JSDoc comment.
700
- *
701
- * @param varName - The variable name to look up
702
- * @returns The type and description if found, null otherwise
703
- *
704
- * @example
705
- * ```ts
706
- * // Source:
707
- * /**
708
- * * @type {number}
709
- * * The count value
710
- * *\/
711
- * const count = 0;
712
- *
713
- * findVariableTypeAndDescription("count")
714
- * // Returns: { type: "number", description: "The count value" }
518
+ * // Given:
519
+ * // /**
520
+ * // * @type {number}
521
+ * // * The count value
522
+ * // *\/
523
+ * // const count = 0;
524
+ *
525
+ * findVariableTypeAndDescription("count");
526
+ * // { type: "number", description: "The count value" }
715
527
  * ```
716
528
  */
717
529
  findVariableTypeAndDescription(varName: string): {
718
530
  type: string;
719
531
  description?: string;
720
532
  } | null;
533
+ accumulateGeneric(name: string, constraint: string): void;
721
534
  /**
722
- * Cleans up all parser state, resetting the instance for reuse.
723
- *
724
- * Clears all maps, caches, and resets all state variables to their initial
725
- * values. Should be called before parsing a new component or when the
726
- * parser instance needs to be reset.
535
+ * Resets parser state for reuse between parses.
727
536
  *
728
537
  * @example
729
538
  * ```ts
730
539
  * parser.parseSvelteComponent(source1, diagnostics1);
731
- * parser.cleanup(); // Reset state
732
- * parser.parseSvelteComponent(source2, diagnostics2); // Fresh parse
540
+ * parser.cleanup();
541
+ * parser.parseSvelteComponent(source2, diagnostics2);
733
542
  * ```
734
543
  */
735
- accumulateGeneric(name: string, constraint: string): void;
736
544
  cleanup(): void;
737
- /**
738
- * Pre-compiled regex for matching script blocks in Svelte components.
739
- *
740
- * Matches `<script>` tags and their content, capturing the opening tag,
741
- * script content, and closing tag. Global and case-insensitive flags
742
- * allow matching multiple script blocks.
743
- *
744
- * @example
745
- * ```ts
746
- * // Matches:
747
- * // "<script>const x = 1;</script>"
748
- * // "<script lang='ts'>...</script>"
749
- * ```
750
- */
751
545
  private static readonly SCRIPT_BLOCK_REGEX;
752
- /**
753
- * Pre-compiled regex for matching TypeScript directive comments.
754
- *
755
- * Matches TypeScript directive comments like ts-ignore, ts-expect-error,
756
- * etc. Used to remove these directives from script blocks before JSDoc parsing.
757
- *
758
- * @example
759
- * ```ts
760
- * // Matches:
761
- * // "// ts-ignore"
762
- * // "// ts-expect-error: reason"
763
- * // "// ts-nocheck"
764
- * ```
765
- */
766
546
  private static readonly TS_DIRECTIVE_REGEX;
767
- /**
768
- * Strips TypeScript directive comments from script blocks only.
769
- *
770
- * Removes TypeScript directive comments (e.g., ts-ignore, ts-expect-error directives)
771
- * from within `<script>` blocks to prevent them from interfering with JSDoc parsing.
772
- * Directives outside script blocks are left untouched.
773
- *
774
- * @param source - The Svelte component source code
775
- * @returns The source code with TypeScript directives removed from script blocks
776
- *
777
- * @example
778
- * ```ts
779
- * // Input (with TypeScript directive):
780
- * <script>
781
- * const x: string = 123; // directive removed
782
- * </script>
783
- *
784
- * // Output (directive stripped):
785
- * <script>
786
- * const x: string = 123;
787
- * </script>
788
- * ```
789
- */
790
547
  private static stripTypeScriptDirectivesFromScripts;
791
548
  /**
792
- * Parses a Svelte component and extracts all component metadata.
793
- *
794
- * This is the main entry point that orchestrates the entire parsing process:
795
- * 1. Cleans up previous state
796
- * 2. Strips TypeScript directives that might interfere with JSDoc
797
- * 3. Compiles the component to get the AST
798
- * 4. Collects reactive variables
799
- * 5. Builds variable type cache
800
- * 6. Parses custom types from JSDoc comments
801
- * 7. Walks the AST to extract props, slots, events, bindings, and contexts
802
- * 8. Post-processes events to distinguish dispatched vs forwarded
803
- * 9. Processes props with bindings and slots with prop references
804
- * 10. Returns the complete parsed component structure
805
- *
806
- * @param source - The Svelte component source code
807
- * @param diagnostics - Diagnostic information (module name and file path)
808
- * @returns A ParsedComponent object containing all extracted metadata
809
- *
810
549
  * @example
811
550
  * ```ts
812
551
  * const parser = new ComponentParser();
@@ -814,9 +553,8 @@ export default class ComponentParser {
814
553
  * moduleName: "Button",
815
554
  * filePath: "./Button.svelte"
816
555
  * });
817
- * // Returns: { props: [...], slots: [...], events: [...], ... }
556
+ * // { props, slots, events, typedefs, ... }
818
557
  * ```
819
558
  */
820
559
  parseSvelteComponent(source: string, diagnostics: ComponentParserDiagnostics): ParsedComponent;
821
560
  }
822
- export {};