pull/1374/head
Rich Harris 7 years ago
parent 890da3b02a
commit d03693114d

@ -78,7 +78,9 @@ export default class Stats {
total: now() - this.startTime total: now() - this.startTime
}, collapseTimings(this.timings)); }, collapseTimings(this.timings));
const imports = compiler.imports.map(node => { // TODO would be good to have this info even
// if options.generate is false
const imports = compiler && compiler.imports.map(node => {
return { return {
source: node.source.value, source: node.source.value,
specifiers: node.specifiers.map(specifier => { specifiers: node.specifiers.map(specifier => {
@ -94,9 +96,12 @@ export default class Stats {
} }
}); });
const hooks: Record<string, boolean> = {}; const hooks: Record<string, boolean> = compiler && {
if (compiler.templateProperties.oncreate) hooks.oncreate = true; oncreate: !!compiler.templateProperties.oncreate,
if (compiler.templateProperties.ondestroy) hooks.ondestroy = true; ondestroy: !!compiler.templateProperties.ondestroy,
onstate: !!compiler.templateProperties.onstate,
onupdate: !!compiler.templateProperties.onupdate
};
return { return {
timings, timings,

@ -132,7 +132,7 @@ function compile(source: string, _options: CompileOptions) {
stats.stop('validate'); stats.stop('validate');
if (options.generate === false) { if (options.generate === false) {
return { ast: ast, stats, js: null, css: null }; return { ast, stats: stats.render(null), js: null, css: null };
} }
const compiler = options.generate === 'ssr' ? generateSSR : generate; const compiler = options.generate === 'ssr' ? generateSSR : generate;

@ -56,4 +56,12 @@ describe('stats', () => {
} }
}); });
}); });
it('returns a stats object when options.generate is false', () => {
const { stats } = svelte.compile('', {
generate: false
});
assert.equal(typeof stats.timings.total, 'number');
});
}); });

@ -1,7 +1,10 @@
export default { export default {
test(assert, stats) { test(assert, stats) {
assert.deepEqual(stats.hooks, { assert.deepEqual(stats.hooks, {
oncreate: true oncreate: true,
ondestroy: false,
onstate: false,
onupdate: false
}); });
} }
}; };
Loading…
Cancel
Save