forked from sveltejs/language-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
100 lines (94 loc) · 3.72 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
export interface SvelteCompiledToTsx {
code: string;
map: import("magic-string").SourceMap;
exportedNames: IExportedNames;
events: ComponentEvents;
}
export interface IExportedNames {
has(name: string): boolean;
}
export interface ComponentEvents {
getAll(): { name: string; type: string; doc?: string }[];
}
export function svelte2tsx(
svelte: string,
options?: {
/**
* Path of the file
*/
filename?: string;
/**
* If the given file uses TypeScript inside script.
* This cannot be inferred from `svelte2tsx` by looking
* at the attributes of the script tag because the
* user may have set a default-language through
* `svelte-preprocess`.
*/
isTsFile?: boolean;
/**
* Whether to try emitting result when there's a syntax error in the template
*/
emitOnTemplateError?: boolean;
/**
* The namespace option from svelte config
* see https://svelte.dev/docs#svelte_compile for more info
*/
namespace?: string;
/**
* When setting this to 'dts', all tsx/jsx code and the template code will be thrown out.
* Only the `code` property will be set on the returned element.
* Use this as an intermediate step to generate type definitions from a component.
* It is expected to pass the result to TypeScript which should handle emitting the d.ts files.
* The shims need to be provided by the user ambient-style,
* for example through `filenames.push(require.resolve('svelte2tsx/svelte-shims.d.ts'))`.
* If you pass 'ts', it uses the new transformation which will replace the now deprecated 'tsx'
* transformation soon.
*/
mode?: 'ts' | 'tsx' | 'dts',
/**
* 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.
* Would be overridden by the same config in the svelte:option element if exist
* see https://svelte.dev/docs#svelte_compile for more info
*/
accessors?: boolean
}
): SvelteCompiledToTsx
export interface EmitDtsConfig {
/**
* Where to output the declaration files
*/
declarationDir: string;
/**
* Path to `svelte-shims.d.ts` of `svelte2tsx`.
* Example: `require.resolve('svelte2tsx/svelte-shims.d.ts')`
*/
svelteShimsPath: string;
/**
* If you want to emit types only for part of your project,
* then set this to the folder for which the types should be emitted.
* Most of the time you don't need this. For SvelteKit, this is for example
* set to `src/lib` by default.
*/
libRoot?: string;
}
// to make typo fix non-breaking, continue to export the old name but mark it as deprecated
/**@deprecated*/
export interface EmitDtsConig extends EmitDtsConfig {} /* eslint-disable-line @typescript-eslint/no-empty-interface */
/**
* Searches for a jsconfig or tsconfig starting at `root` and emits d.ts files
* into `declarationDir` using the ambient file from `svelteShimsPath`.
* Note: Handwritten `d.ts` files are not copied over; TypeScript does not
* touch these files.
*/
export function emitDts(config: EmitDtsConfig): Promise<void>;