Skip to content

Commit

Permalink
fix #1368
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Apr 29, 2018
1 parent 890da3b commit d036931
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
13 changes: 9 additions & 4 deletions src/Stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions test/stats/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
5 changes: 4 additions & 1 deletion test/stats/samples/hooks/_config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
export default {
test(assert, stats) {
assert.deepEqual(stats.hooks, {
oncreate: true
oncreate: true,
ondestroy: false,
onstate: false,
onupdate: false
});
}
};

0 comments on commit d036931

Please sign in to comment.