From d03693114df5898740cd4a44f42531b02f2239fb Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 28 Apr 2018 21:00:07 -0400 Subject: [PATCH] fix #1368 --- src/Stats.ts | 13 +++++++++---- src/index.ts | 2 +- test/stats/index.js | 8 ++++++++ test/stats/samples/hooks/_config.js | 5 ++++- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/Stats.ts b/src/Stats.ts index c9e62aef21..6faca18e75 100644 --- a/src/Stats.ts +++ b/src/Stats.ts @@ -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 = {}; - if (compiler.templateProperties.oncreate) hooks.oncreate = true; - if (compiler.templateProperties.ondestroy) hooks.ondestroy = true; + const hooks: Record = compiler && { + oncreate: !!compiler.templateProperties.oncreate, + ondestroy: !!compiler.templateProperties.ondestroy, + onstate: !!compiler.templateProperties.onstate, + onupdate: !!compiler.templateProperties.onupdate + }; return { timings, diff --git a/src/index.ts b/src/index.ts index 6bef0581bd..2895dd2977 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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; diff --git a/test/stats/index.js b/test/stats/index.js index fba9926061..550c887a6a 100644 --- a/test/stats/index.js +++ b/test/stats/index.js @@ -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'); + }); }); diff --git a/test/stats/samples/hooks/_config.js b/test/stats/samples/hooks/_config.js index 78fc771a06..5778d44102 100644 --- a/test/stats/samples/hooks/_config.js +++ b/test/stats/samples/hooks/_config.js @@ -1,7 +1,10 @@ export default { test(assert, stats) { assert.deepEqual(stats.hooks, { - oncreate: true + oncreate: true, + ondestroy: false, + onstate: false, + onupdate: false }); } }; \ No newline at end of file