-
-
Notifications
You must be signed in to change notification settings - Fork 207
/
Copy pathindex.d.ts
198 lines (187 loc) · 6.73 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import ts from 'typescript';
export interface SvelteCompiledToTsx {
code: string;
map: import("magic-string").SourceMap;
exportedNames: IExportedNames;
/**
* @deprecated Use TypeScript's `TypeChecker` to get the type information instead. This only covers literal typings.
*/
events: ComponentEvents;
}
export interface IExportedNames {
has(name: string): boolean;
}
/**
* @deprecated Use TypeScript's `TypeChecker` to get the type information instead. This only covers literal typings.
*/
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 ts/js 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 regular Svelte->TS/JS transformation.
*
* @default 'ts'
*/
mode?: 'ts' | 'dts',
/**
* 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]`
*
* @default 'svelteHTML'
*/
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
/**
* The Svelte parser to use. Defaults to the one bundled with `svelte2tsx`.
*/
parse?: typeof import('svelte/compiler').parse;
/**
* The VERSION from 'svelte/compiler'. Defaults to the one bundled with `svelte2tsx`.
* Transpiled output may vary between versions.
*/
version?: string;
}
): 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')`
*
* If a path is given that points to `svelte-shims-v4.d.ts`,
* the `SvelteComponent` import is used instead of
* `SvelteComponentTyped` which is deprecated in Svelte v4.
*/
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;
/**
* Name of your tsconfig file, if it's not the standard `tsconfig.json` or `jsconfig.json`
*/
tsconfig?: string;
}
// to make typo fix non-breaking, continue to export the old name but mark it as deprecated
/**@deprecated*/
export interface EmitDtsConig extends EmitDtsConfig {}
/**
* 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>;
/**
* ## Internal, do not use! This is subject to change at any time.
*
* Implementation notice: If one of the methods use a TypeScript function which is not from the
* static top level `ts` namespace, it must be passed as a parameter.
*/
export const internalHelpers: {
get_global_types: (
tsSystem: ts.System,
isSvelte3: boolean,
sveltePath: string,
typesPath: string,
hiddenFolderPath?: string,
) => string[],
isKitFile: (
fileName: string,
options: InternalHelpers.KitFilesSettings
) => boolean;
isKitRouteFile: (basename: string) => boolean,
isHooksFile: (
fileName: string,
basename: string,
hooksPath: string
) => boolean,
isParamsFile: (fileName: string, basename: string, paramsPath: string) =>boolean,
upsertKitFile: (
_ts: typeof ts,
fileName: string,
kitFilesSettings: InternalHelpers.KitFilesSettings,
getSource: () => ts.SourceFile | undefined,
surround?: (code: string) => string
) => { text: string; addedCode: InternalHelpers.AddedCode[] } | undefined,
toVirtualPos: (pos: number, addedCode: InternalHelpers.AddedCode[]) => number,
toOriginalPos: (pos: number, addedCode: InternalHelpers.AddedCode[]) => {pos: number; inGenerated: boolean},
findExports: (_ts: typeof ts, source: ts.SourceFile, isTsFile: boolean) => Map<
string,
| {
type: 'function';
node: ts.FunctionDeclaration | ts.ArrowFunction | ts.FunctionExpression;
hasTypeDefinition: boolean;
}
| {
type: 'var';
node: ts.VariableDeclaration;
hasTypeDefinition: boolean;
}
>,
renderName: string
};
/**
* ## Internal, do not use! This is subject to change at any time.
*/
export namespace InternalHelpers {
export interface AddedCode {
generatedPos: number;
originalPos: number;
length: number;
total: number;
inserted: string;
}
export interface KitFilesSettings {
serverHooksPath: string;
clientHooksPath: string;
universalHooksPath: string;
paramsPath: string;
}
}