|
|
|
@ -46,16 +46,6 @@ function validate_options(options: CompileOptions, stats: Stats) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default function compile(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.compile in a try-catch block`);
|
|
|
|
|
delete options.onerror;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
options = normalize_options(options);
|
|
|
|
|
|
|
|
|
|
const stats = new Stats({
|
|
|
|
@ -64,33 +54,29 @@ export default function compile(source: string, options: CompileOptions = {}) {
|
|
|
|
|
|
|
|
|
|
let ast: Ast;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
validate_options(options, stats);
|
|
|
|
|
|
|
|
|
|
stats.start('parse');
|
|
|
|
|
ast = parse(source, options);
|
|
|
|
|
stats.stop('parse');
|
|
|
|
|
|
|
|
|
|
stats.start('create component');
|
|
|
|
|
const component = new Component(
|
|
|
|
|
ast,
|
|
|
|
|
source,
|
|
|
|
|
options.name || 'SvelteComponent',
|
|
|
|
|
options,
|
|
|
|
|
stats
|
|
|
|
|
);
|
|
|
|
|
stats.stop('create component');
|
|
|
|
|
|
|
|
|
|
if (options.generate === false) {
|
|
|
|
|
return { ast, stats: stats.render(null), js: null, css: null };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (options.generate === 'ssr') {
|
|
|
|
|
return renderSSR(component, options);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return renderDOM(component, options);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
onerror(err);
|
|
|
|
|
validate_options(options, stats);
|
|
|
|
|
|
|
|
|
|
stats.start('parse');
|
|
|
|
|
ast = parse(source, options);
|
|
|
|
|
stats.stop('parse');
|
|
|
|
|
|
|
|
|
|
stats.start('create component');
|
|
|
|
|
const component = new Component(
|
|
|
|
|
ast,
|
|
|
|
|
source,
|
|
|
|
|
options.name || 'SvelteComponent',
|
|
|
|
|
options,
|
|
|
|
|
stats
|
|
|
|
|
);
|
|
|
|
|
stats.stop('create component');
|
|
|
|
|
|
|
|
|
|
if (options.generate === false) {
|
|
|
|
|
return { ast, stats: stats.render(null), js: null, css: null };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (options.generate === 'ssr') {
|
|
|
|
|
return renderSSR(component, options);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return renderDOM(component, options);
|
|
|
|
|
}
|