sveld 0.32.2 → 0.32.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.
@@ -135,26 +135,6 @@ interface ComponentSlot {
135
135
  /** Source range for the slot/snippet declaration or documentation tag, when available */
136
136
  source?: SourceRange;
137
137
  }
138
- /**
139
- * Event that is forwarded from a child component or element.
140
- *
141
- * Forwarded events are those that use `on:eventname` syntax without
142
- * a handler, passing the event through to the parent.
143
- */
144
- interface ForwardedEvent {
145
- /** Always "forwarded" for forwarded events */
146
- type: "forwarded";
147
- /** The event name (e.g., "click", "change") */
148
- name: string;
149
- /** The element or component that forwards this event */
150
- element: ComponentInlineElement | ComponentElement;
151
- /** Description extracted from JSDoc `@event` tags */
152
- description?: string;
153
- /** The detail type if explicitly specified in `@event` tag */
154
- detail?: string;
155
- /** Source range for the forwarded event declaration or documentation tag, when available */
156
- source?: SourceRange;
157
- }
158
138
  /**
159
139
  * Event that is dispatched by the component.
160
140
  *
@@ -173,7 +153,40 @@ interface DispatchedEvent {
173
153
  /** Source range for the dispatched event call or documentation tag, when available */
174
154
  source?: SourceRange;
175
155
  }
176
- type ComponentEvent = ForwardedEvent | DispatchedEvent;
156
+ /**
157
+ * Serialized version of {@link ForwardedEvent} for JSON output.
158
+ *
159
+ * This interface maintains backward compatibility by serializing the `element`
160
+ * property as a string instead of an object. The element name is extracted
161
+ * from the {@link ComponentInlineElement} or {@link ComponentElement} object.
162
+ *
163
+ * @example
164
+ * ```ts
165
+ * // ForwardedEvent with element object:
166
+ * { type: "forwarded", name: "click", element: { type: "Element", name: "button" } }
167
+ *
168
+ * // SerializedForwardedEvent for JSON:
169
+ * { type: "forwarded", name: "click", element: "button" }
170
+ * ```
171
+ */
172
+ export interface SerializedForwardedEvent {
173
+ /** Always "forwarded" for forwarded events */
174
+ type: "forwarded";
175
+ /** The event name (e.g., "click", "change") */
176
+ name: string;
177
+ /**
178
+ * Serialized as string for JSON backward compatibility.
179
+ * In the internal API, this is an object, but for JSON output it's a string.
180
+ */
181
+ element: string;
182
+ /** Description extracted from JSDoc `@event` tags */
183
+ description?: string;
184
+ /** The detail type if explicitly specified in `@event` tag */
185
+ detail?: string;
186
+ /** Source range for the forwarded event declaration or documentation tag, when available */
187
+ source?: SourceRange;
188
+ }
189
+ export type SerializedComponentEvent = SerializedForwardedEvent | DispatchedEvent;
177
190
  /**
178
191
  * Type definition extracted from JSDoc `@typedef` tags.
179
192
  *
@@ -306,8 +319,8 @@ export interface ParsedComponent {
306
319
  moduleExports: ComponentProp[];
307
320
  /** Slots available in the component template */
308
321
  slots: ComponentSlot[];
309
- /** Events that the component can dispatch or forward */
310
- events: ComponentEvent[];
322
+ /** Events that the component can dispatch or forward (serialized for JSON/API output) */
323
+ events: SerializedComponentEvent[];
311
324
  /** Custom type definitions from JSDoc `@typedef` tags */
312
325
  typedefs: TypeDef[];
313
326
  /** Generic type parameters (e.g., `[name: "T", type: "string"]`) or null */
@@ -440,7 +453,6 @@ export default class ComponentParser {
440
453
  private buildScopeDeclarations;
441
454
  private createRestPropsFromParent;
442
455
  private maybeSetRestProps;
443
- private isCallExpressionNamed;
444
456
  private getPropertyName;
445
457
  private logUnsupportedRunesPattern;
446
458
  private logParserWarning;
@@ -506,23 +518,14 @@ export default class ComponentParser {
506
518
  * ```ts
507
519
  * // Input JSDoc:
508
520
  * /**
509
- * * @type {string}
510
- * * @param {number} x - The x coordinate
511
- * * @param {number} y - The y coordinate
512
- * * @returns {void}
513
- * * Description text
514
- * *\/
515
- *
521
+ * * @type {string}
522
+ * * @param {number} x - The x coordinate
523
+ * * @param {number} y - The y coordinate
524
+ * * @returns {void}
525
+ * * Description text
526
+ * *\/
516
527
  * // Output:
517
- * {
518
- * type: "string",
519
- * params: [
520
- * { name: "x", type: "number", description: "The x coordinate", optional: false },
521
- * { name: "y", type: "number", description: "The y coordinate", optional: false }
522
- * ],
523
- * returnType: "void",
524
- * description: "Description text"
525
- * }
528
+ * { type: "string", params: [ { name: "x", type: "number", description: "The x coordinate", optional: false }, { name: "y", type: "number", description: "The y coordinate", optional: false } ], returnType: "void", description: "Description text" }
526
529
  * ```
527
530
  */
528
531
  private processJSDocComment;
@@ -597,6 +600,10 @@ export default class ComponentParser {
597
600
  * Returns the init node if found, or undefined.
598
601
  */
599
602
  private resolveLocalVarInitializer;
603
+ /**
604
+ * Look up JSDoc on a local variable declaration by name.
605
+ */
606
+ private resolveLocalVarJSDoc;
600
607
  /**
601
608
  * Unwraps `$bindable(...)` calls so defaults are documented as their underlying values.
602
609
  */
@@ -794,11 +801,7 @@ export default class ComponentParser {
794
801
  * @example
795
802
  * ```ts
796
803
  * // Input:
797
- * [
798
- * { name: "value", type: "string", description: "The new value" },
799
- * { name: "count", type: "number", optional: true, default: "0" }
800
- * ]
801
- *
804
+ * [ { name: "value", type: "string", description: "The new value" }, { name: "count", type: "number", optional: true, default: "0" } ]
802
805
  * // Output:
803
806
  * "{ /** The new value *\/ value: string; /** @default 0 *\/ count?: number; }"
804
807
  * ```
@@ -0,0 +1,12 @@
1
+ import type { ArrowFunctionExpression, CallExpression, FunctionDeclaration, FunctionExpression, Identifier, Literal, MemberExpression, ObjectExpression, VariableDeclaration } from "estree";
2
+ export declare function isObject(value: unknown): value is Record<string, unknown>;
3
+ export declare function isVariableDeclaration(node: unknown): node is VariableDeclaration;
4
+ export declare function isLiteral(node: unknown): node is Literal;
5
+ export declare function isIdentifier(node: unknown): node is Identifier;
6
+ export declare function isMemberExpression(node: unknown): node is MemberExpression;
7
+ export declare function isObjectExpression(node: unknown): node is ObjectExpression;
8
+ export declare function isCallExpression(node: unknown): node is CallExpression;
9
+ export declare function isCallExpressionNamed(node: unknown, calleeName: string): node is CallExpression;
10
+ export declare function isFunctionDeclaration(node: unknown): node is FunctionDeclaration;
11
+ export declare function isFunctionExpression(node: unknown): node is FunctionExpression;
12
+ export declare function isArrowFunctionExpression(node: unknown): node is ArrowFunctionExpression;
@@ -0,0 +1,11 @@
1
+ declare const brand: unique symbol;
2
+ export type Brand<TBase extends string, TBrand extends string> = TBase & {
3
+ readonly [brand]: TBrand;
4
+ };
5
+ export type SvelteEntryPoint = Brand<string, "SvelteEntryPoint">;
6
+ export declare function asSvelteEntryPoint(path: string): SvelteEntryPoint;
7
+ export type NormalizedPath = Brand<string, "NormalizedPath">;
8
+ export declare function asNormalizedPath(path: string): NormalizedPath;
9
+ export type RelativeSourcePath = Brand<string, "RelativeSourcePath">;
10
+ export declare function asRelativeSourcePath(path: string): RelativeSourcePath;
11
+ export {};
package/lib/cli.d.ts CHANGED
@@ -1,10 +1,5 @@
1
1
  /**
2
- * Command-line interface for sveld.
3
- *
4
- * Parses command-line arguments, runs Rollup to process the entry point,
5
- * generates component documentation, and writes output files.
6
- *
7
- * @param process - Node.js process object containing command-line arguments
2
+ * CLI entry point: parse flags, run Rollup, generate docs, write outputs.
8
3
  *
9
4
  * @example
10
5
  * ```ts
@@ -1,13 +1,6 @@
1
1
  import type { ParsedExports } from "./parse-exports";
2
2
  /**
3
- * Creates export statements from parsed export information.
4
- *
5
- * Groups exports by source file and generates optimized export statements.
6
- * Handles special cases like Svelte component exports, default exports,
7
- * and mixed exports from module context.
8
- *
9
- * @param parsed_exports - Map of export names to their source and metadata
10
- * @returns A string containing all export statements
3
+ * Builds export statements from parsed export metadata.
11
4
  *
12
5
  * @example
13
6
  * ```ts
@@ -20,10 +13,7 @@ import type { ParsedExports } from "./parse-exports";
20
13
  */
21
14
  export declare function createExports(parsed_exports: ParsedExports): string;
22
15
  /**
23
- * Removes the `.svelte` extension from a file path.
24
- *
25
- * @param filePath - The file path to process
26
- * @returns The path without the .svelte extension
16
+ * Strips the `.svelte` extension from a path.
27
17
  *
28
18
  * @example
29
19
  * ```ts
@@ -32,10 +22,7 @@ export declare function createExports(parsed_exports: ParsedExports): string;
32
22
  */
33
23
  export declare function removeSvelteExt(filePath: string): string;
34
24
  /**
35
- * Converts a `.svelte` file path to a `.svelte.d.ts` TypeScript definition path.
36
- *
37
- * @param filePath - The Svelte file path to convert
38
- * @returns The path with .svelte.d.ts extension
25
+ * Maps a `.svelte` path to its `.svelte.d.ts` definition path.
39
26
  *
40
27
  * @example
41
28
  * ```ts
@@ -1,9 +1,5 @@
1
1
  /**
2
- * Element tag map adapted from TypeScript's `lib.dom.d.ts`.
3
- *
4
- * Maps HTML element tag names to their corresponding TypeScript element types.
5
- * Used for generating proper TypeScript types for element bindings and rest props.
6
- * See the TypeScript lib.dom.d.ts for the original source.
2
+ * Tag-to-DOM-type map from TypeScript `lib.dom.d.ts`. Unknown tags fall back to `HTMLElement`.
7
3
  *
8
4
  * @example
9
5
  * ```ts
@@ -135,14 +131,9 @@ declare const tag_map: {
135
131
  wbr: string;
136
132
  };
137
133
  type ElementTag = keyof typeof tag_map;
134
+ export declare function isElementTag(element: string): element is ElementTag;
138
135
  /**
139
- * Gets the TypeScript element type for a given HTML tag name.
140
- *
141
- * Returns the specific element type (e.g., `HTMLButtonElement`) if the tag
142
- * is in the map, otherwise returns the generic `HTMLElement` type.
143
- *
144
- * @param element - The HTML tag name (e.g., "button", "div", "input")
145
- * @returns The corresponding TypeScript element type name
136
+ * Returns the DOM interface for a tag, or `HTMLElement` when unknown.
146
137
  *
147
138
  * @example
148
139
  * ```ts
@@ -151,5 +142,5 @@ type ElementTag = keyof typeof tag_map;
151
142
  * getElementByTag("custom") // Returns: "HTMLElement" (fallback)
152
143
  * ```
153
144
  */
154
- export declare function getElementByTag(element: ElementTag | string): string;
145
+ export declare function getElementByTag(element: string): string;
155
146
  export {};
@@ -1,6 +1,4 @@
1
- export type SvelteEntryPoint = string;
2
- /**
3
- * Get the file path entry point for uncompiled Svelte source code
4
- * Expects a "svelte" field in the consumer's `package.json`
5
- */
6
- export declare function getSvelteEntry(entryPoint?: SvelteEntryPoint): SvelteEntryPoint | null;
1
+ import { type SvelteEntryPoint } from "./brands";
2
+ export type { SvelteEntryPoint };
3
+ /** Resolve the Svelte entry from `entryPoint` or `package.json#svelte`. */
4
+ export declare function getSvelteEntry(entryPoint?: string): SvelteEntryPoint | null;
package/lib/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- export { default as ComponentParser } from "./ComponentParser";
1
+ export { default as ComponentParser, type SerializedComponentEvent } from "./ComponentParser";
2
2
  export { cli } from "./cli";
3
+ export type { SvelteEntryPoint } from "./get-svelte-entry";
3
4
  export { default } from "./plugin";
4
5
  export { sveld } from "./sveld";