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

@ -78,7 +78,9 @@ export default class Stats {
total: now() - this.startTime
}, 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 {
source: node.source.value,
specifiers: node.specifiers.map(specifier => {
@ -94,9 +96,12 @@ export default class Stats {
}
});
const hooks: Record<string, boolean> = {};
if (compiler.templateProperties.oncreate) hooks.oncreate = true;
if (compiler.templateProperties.ondestroy) hooks.ondestroy = true;
const hooks: Record<string, boolean> = compiler && {
oncreate: !!compiler.templateProperties.oncreate,
ondestroy: !!compiler.templateProperties.ondestroy,
onstate: !!compiler.templateProperties.onstate,
onupdate: !!compiler.templateProperties.onupdate
};
return {
timings,

@ -132,7 +132,7 @@ function compile(source: string, _options: CompileOptions) {
stats.stop('validate');
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;

@ -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 {
test(assert, stats) {
assert.deepEqual(stats.hooks, {
oncreate: true
oncreate: true,
ondestroy: false,
onstate: false,
onupdate: false
});
}
};
Loading…
Cancel
Save