UNPKG

@ethan-jones-vizio/sveld

Version:

Generate TypeScript definitions for your Svelte components.

98 lines (97 loc) 2.43 kB
interface ComponentParserDiagnostics { moduleName: string; filePath: string; } interface ComponentParserOptions { verbose?: boolean; } interface ComponentProp { name: string; kind: "let" | "const" | "function"; constant: boolean; type?: string; value?: any; description?: string; isFunction: boolean; isFunctionDeclaration: boolean; isRequired: boolean; reactive: boolean; } interface ComponentSlot { name?: string; default: boolean; fallback?: string; slot_props?: string; } interface ForwardedEvent { type: "forwarded"; name: string; element: ComponentInlineElement | ComponentElement; } interface DispatchedEvent { type: "dispatched"; name: string; detail?: any; } declare type ComponentEvent = ForwardedEvent | DispatchedEvent; interface TypeDef { type: string; name: string; description?: string; ts: string; } interface ComponentInlineElement { type: "InlineComponent"; name: string; } interface ComponentElement { type: "Element"; name: string; } declare type RestProps = undefined | ComponentInlineElement | ComponentElement; interface Extends { interface: string; import: string; } export interface ParsedComponent { props: ComponentProp[]; moduleExports: ComponentProp[]; slots: ComponentSlot[]; events: ComponentEvent[]; typedefs: TypeDef[]; rest_props: RestProps; extends?: Extends; componentComment?: string; } export default class ComponentParser { private options?; private source?; private compiled?; private parsed?; private rest_props?; private extends?; private componentComment?; private readonly reactive_vars; private readonly vars; private readonly props; private readonly moduleExports; private readonly slots; private readonly events; private readonly typedefs; private readonly bindings; constructor(options?: ComponentParserOptions); private static mapToArray; private static assignValue; private static formatComment; private sourceAtPos; private collectReactiveVars; private addProp; private addModuleExport; private aliasType; private addSlot; private addDispatchedEvent; private parseCustomTypes; cleanup(): void; parseSvelteComponent(source: string, diagnostics: ComponentParserDiagnostics): ParsedComponent; } export {};