Skip to content

Commit 4ad7631

Browse files
committed
expose svelte2tsx component documentation
1 parent 1948af4 commit 4ad7631

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

packages/svelte2tsx/index.d.ts

+19-6
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,24 @@ export interface SvelteCompiledToTsx {
33
map: import("magic-string").SourceMap;
44
exportedNames: IExportedNames;
55
events: ComponentEvents;
6+
componentDocumentation: string;
7+
slots: Map<string, Map<string, string>>;
8+
generics: {
9+
definitions: string;
10+
references: string;
11+
};
612
}
713

8-
export interface IExportedNames {
9-
has(name: string): boolean;
10-
}
14+
export type IExportedNames = Map<
15+
string,
16+
{
17+
isLet: boolean;
18+
type?: string;
19+
identifierText?: string;
20+
required?: boolean;
21+
doc?: string;
22+
}
23+
>;
1124

1225
export interface ComponentEvents {
1326
getAll(): { name: string; type: string; doc?: string }[];
@@ -51,16 +64,16 @@ export function svelte2tsx(
5164
/**
5265
* Takes effect when using the new 'ts' mode. Default 'svelteHTML'.
5366
* Tells svelte2tsx from which namespace some specific functions to use.
54-
*
67+
*
5568
* Example: 'svelteHTML' -> svelteHTML.createElement<..>(..)
56-
*
69+
*
5770
* A namespace needs to implement the following functions:
5871
* - `createElement(str: string, validAttributes: ..): Element`
5972
* - `mapElementTag<Key extends keyof YourElements>(str: Key): YourElements[Key]`
6073
*/
6174
typingsNamespace?: string;
6275
/**
63-
* The accessor option from svelte config.
76+
* The accessor option from svelte config.
6477
* Would be overridden by the same config in the svelte:option element if exist
6578
* see https://svelte.dev/docs#svelte_compile for more info
6679
*/

packages/svelte2tsx/src/svelte2tsx/index.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,13 @@ declare function __sveltets_1_createSvelteComponentTyped<Props, Events, Slots>(
451451
code: str.toString(),
452452
map: str.generateMap({ hires: true, source: options?.filename }),
453453
exportedNames: exportedNames.getExportsMap(),
454-
events: events.createAPI()
454+
events: events.createAPI(),
455+
componentDocumentation: componentDocumentation.getFormatted(),
456+
slots,
457+
generics: {
458+
definition: generics.toDefinitionString(),
459+
references: generics.toReferencesString()
460+
}
455461
};
456462
}
457463
}

0 commit comments

Comments
 (0)