forked from sveltejs/svelte
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
34 lines (27 loc) · 866 Bytes
/
index.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
import compile from './compile/index';
import { CompileOptions } from './interfaces';
import deprecate from './utils/deprecate';
export function create(source: string, options: CompileOptions = {}) {
const onerror = options.onerror || (err => {
throw err;
});
if (options.onerror) {
// TODO remove in v3
deprecate(`Instead of using options.onerror, wrap svelte.create in a try-catch block`);
delete options.onerror;
}
options.format = 'eval';
try {
const compiled = compile(source, options);
if (!compiled || !compiled.js.code) {
return;
}
return (new Function(`return ${compiled.js.code}`))();
} catch (err) {
onerror(err);
}
}
export { default as compile } from './compile/index';
export { default as parse } from './parse/index';
export { default as preprocess } from './preprocess/index';
export const VERSION = '__VERSION__';