UNPKG

@stacksjs/dtsx

Version:

A modern, fast .d.ts generation tool, powered by Bun.

65 lines (64 loc) 2.92 kB
/** Check whether a file path points at a Vue SFC. */ export declare function isVueFile(filePath: string): boolean; /** * Parse the script blocks of a Vue SFC. Template/style content is ignored — * declarations only depend on the component's script. */ export declare function parseVueSfc(source: string): VueSfc; /** * Find the index of the closer matching the opener at `start` * (`text[start]` must be the opener). Returns -1 when unbalanced. */ export declare function findMatching(text: string, start: number, open: string, close: string): number; /** Map a runtime props option (`{...}` or `[...]`) to a type literal. */ export declare function mapRuntimeProps(propsText: string): string | null; /** * Remove `defineProps` / `defineEmits` / `defineExpose` / `defineOptions` * statements (including `withDefaults(defineProps(), ...)` wrappers) from * `<script setup>` content. Their type information has already been captured * in the synthesized component type; keeping the calls would only add noise * the declaration scanner does not need. Macros are only valid as top-level * statements, so a statement always starts at the beginning of a line. */ export declare function stripMacroStatements(content: string): string; /** Extract the options object from `export default {...}` / `export default defineComponent({...})`. */ export declare function extractDefaultExportOptions(script: string): OptionsExtraction; /** * Transform a Vue SFC into a virtual TypeScript module whose declarations the * regular pipeline can emit. Always returns a module — a template-only SFC * still gets a bare `DefineComponent` default export. */ export declare function transformVueSfcToTs(source: string): string; /** * Vue Single-File Component (SFC) support. * * Parses the `<script>` / `<script setup>` blocks of a `.vue` file and * transforms them into a virtual TypeScript module whose default export is a * `DefineComponent` typed from: * - `defineProps<T>()` generics, runtime `defineProps({...})` objects, or * Options-API `props` (including `PropType<T>` casts) * - `defineEmits` generics / arrays and Options-API `emits` * - `defineExpose({...})` exposed keys * * The virtual module is fed through the regular declaration pipeline, so every * plugin surface (bun, vite, esbuild, tsup, webpack) emits component * declarations without knowing anything about Vue. */ export declare interface VueSfcBlock { content: string attrs: string setup: boolean lang: string } export declare interface VueSfc { script: VueSfcBlock | null scriptSetup: VueSfcBlock | null } // --------------------------------------------------------------------------- // Options API default-export extraction // --------------------------------------------------------------------------- declare interface OptionsExtraction { options: string | null script: string passthrough: boolean }