Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose svelte2tsx component documentation #1346

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions packages/svelte2tsx/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,24 @@ export interface SvelteCompiledToTsx {
map: import("magic-string").SourceMap;
exportedNames: IExportedNames;
events: ComponentEvents;
componentDocumentation: string;
slots: Map<string, Map<string, string>>;
generics: {
definitions: string;
references: string;
};
}

export interface IExportedNames {
has(name: string): boolean;
}
export type IExportedNames = Map<
string,
{
isLet: boolean;
type?: string;
identifierText?: string;
required?: boolean;
doc?: string;
}
>;

export interface ComponentEvents {
getAll(): { name: string; type: string; doc?: string }[];
Expand Down Expand Up @@ -51,16 +64,16 @@ export function svelte2tsx(
/**
* Takes effect when using the new 'ts' mode. Default 'svelteHTML'.
* Tells svelte2tsx from which namespace some specific functions to use.
*
*
* Example: 'svelteHTML' -> svelteHTML.createElement<..>(..)
*
*
* A namespace needs to implement the following functions:
* - `createElement(str: string, validAttributes: ..): Element`
* - `mapElementTag<Key extends keyof YourElements>(str: Key): YourElements[Key]`
*/
typingsNamespace?: string;
/**
* The accessor option from svelte config.
* The accessor option from svelte config.
* Would be overridden by the same config in the svelte:option element if exist
* see https://svelte.dev/docs#svelte_compile for more info
*/
Expand Down
8 changes: 7 additions & 1 deletion packages/svelte2tsx/src/svelte2tsx/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,13 @@ declare function __sveltets_1_createSvelteComponentTyped<Props, Events, Slots>(
code: str.toString(),
map: str.generateMap({ hires: true, source: options?.filename }),
exportedNames: exportedNames.getExportsMap(),
events: events.createAPI()
events: events.createAPI(),
componentDocumentation: componentDocumentation.getFormatted(),
slots,
generics: {
definition: generics.toDefinitionString(),
references: generics.toReferencesString()
}
};
}
}